blob: 2c0c5deb64e97270fd14846a85c2baf26211ebf5 [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;
Pengquan Meng85728fb2018-03-12 16:31:21 -070055import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
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
Pengquan Meng85728fb2018-03-12 16:31:21 -0700275 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
276 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
277 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
278
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700279 /** The singleton instance. */
280 private static PhoneInterfaceManager sInstance;
281
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800283 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700284 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private AppOpsManager mAppOps;
286 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800287 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800288 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700289 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
Derek Tan97ebb422014-09-05 16:55:38 -0700291 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
292 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800293 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800294 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700295
Michelecea4cf22018-12-21 15:00:11 -0800296 // String to store multi SIM allowed
297 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
298
Derek Tan740e1672017-06-27 14:56:27 -0700299 // The AID of ISD-R.
300 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
301
yinxub1bed742017-04-17 11:45:04 -0700302 private NetworkScanRequestTracker mNetworkScanRequestTracker;
303
David Kelly5e06a7f2018-03-12 14:10:59 +0000304 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
305 private static final int MANUFACTURER_CODE_LENGTH = 8;
306
Derek Tan89e89d42014-07-08 17:00:10 -0700307 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700308 * Experiment flag to enable erase modem config on reset network, default value is false
309 */
310 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
311 "reset_network_erase_modem_config_enabled";
312
313 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700314 * A request object to use for transmitting data to an ICC.
315 */
316 private static final class IccAPDUArgument {
317 public int channel, cla, command, p1, p2, p3;
318 public String data;
319
320 public IccAPDUArgument(int channel, int cla, int command,
321 int p1, int p2, int p3, String data) {
322 this.channel = channel;
323 this.cla = cla;
324 this.command = command;
325 this.p1 = p1;
326 this.p2 = p2;
327 this.p3 = p3;
328 this.data = data;
329 }
330 }
331
332 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700333 * A request object to use for transmitting data to an ICC.
334 */
335 private static final class ManualNetworkSelectionArgument {
336 public OperatorInfo operatorInfo;
337 public boolean persistSelection;
338
339 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
340 this.operatorInfo = operatorInfo;
341 this.persistSelection = persistSelection;
342 }
343 }
344
345 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
347 * request after sending. The main thread will notify the request when it is complete.
348 */
349 private static final class MainThreadRequest {
350 /** The argument to use for the request */
351 public Object argument;
352 /** The result of the request that is run on the main thread */
353 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800354 // The subscriber id that this request applies to. Defaults to
355 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
356 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
Nathan Harold92bed182018-10-12 18:16:49 -0700358 // In cases where subId is unavailable, the caller needs to specify the phone.
359 public Phone phone;
360
vagdeviaf9a5b92018-08-15 16:01:53 -0700361 public WorkSource workSource;
362
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 public MainThreadRequest(Object argument) {
364 this.argument = argument;
365 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800366
Nathan Harold92bed182018-10-12 18:16:49 -0700367 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
368 this.argument = argument;
369 if (phone != null) {
370 this.phone = phone;
371 }
372 this.workSource = workSource;
373 }
374
vagdeviaf9a5b92018-08-15 16:01:53 -0700375 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800376 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800377 if (subId != null) {
378 this.subId = subId;
379 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700380 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 }
383
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800384 private static final class IncomingThirdPartyCallArgs {
385 public final ComponentName component;
386 public final String callId;
387 public final String callerDisplayName;
388
389 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
390 String callerDisplayName) {
391 this.component = component;
392 this.callId = callId;
393 this.callerDisplayName = callerDisplayName;
394 }
395 }
396
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 /**
398 * A handler that processes messages on the main thread in the phone process. Since many
399 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
400 * inbound binder threads to the main thread in the phone process. The Binder thread
401 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
402 * on, which will be notified when the operation completes and will contain the result of the
403 * request.
404 *
405 * <p>If a MainThreadRequest object is provided in the msg.obj field,
406 * note that request.result must be set to something non-null for the calling thread to
407 * unblock.
408 */
409 private final class MainThreadHandler extends Handler {
410 @Override
411 public void handleMessage(Message msg) {
412 MainThreadRequest request;
413 Message onCompleted;
414 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800415 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800417 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418
419 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700420 case CMD_HANDLE_USSD_REQUEST: {
421 request = (MainThreadRequest) msg.obj;
422 final Phone phone = getPhoneFromRequest(request);
423 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
424 String ussdRequest = ussdObject.first;
425 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700426
Pengquan Menga1bb6272018-09-06 09:59:22 -0700427 if (!isUssdApiAllowed(request.subId)) {
428 // Carrier does not support use of this API, return failure.
429 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
430 UssdResponse response = new UssdResponse(ussdRequest, null);
431 Bundle returnData = new Bundle();
432 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
433 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700434
Pengquan Menga1bb6272018-09-06 09:59:22 -0700435 request.result = true;
436 notifyRequester(request);
437 return;
438 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700439
Pengquan Menga1bb6272018-09-06 09:59:22 -0700440 try {
441 request.result = phone != null
442 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
443 } catch (CallStateException cse) {
444 request.result = false;
445 }
446 // Wake up the requesting thread
447 notifyRequester(request);
448 break;
pkanwar32d516d2016-10-14 19:37:38 -0700449 }
450
Yorke Lee716f67e2015-06-17 15:39:16 -0700451 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700453 final Phone phone = getPhoneFromRequest(request);
454 request.result = phone != null ?
455 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
456 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700458 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700461
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800465 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 if (uiccCard == null) {
467 loge("iccTransmitApduLogicalChannel: No UICC");
468 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700469 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700470 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
472 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700473 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700474 iccArgument.channel, iccArgument.cla, iccArgument.command,
475 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700477 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 break;
479
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 ar = (AsyncResult) msg.obj;
482 request = (MainThreadRequest) ar.userObj;
483 if (ar.exception == null && ar.result != null) {
484 request.result = ar.result;
485 } else {
486 request.result = new IccIoResult(0x6F, 0, (byte[])null);
487 if (ar.result == null) {
488 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800489 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800491 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700492 } else {
493 loge("iccTransmitApduLogicalChannel: Unknown exception");
494 }
495 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 break;
498
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
500 request = (MainThreadRequest) msg.obj;
501 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800502 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 if (uiccCard == null) {
504 loge("iccTransmitApduBasicChannel: No UICC");
505 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700506 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 } else {
508 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
509 request);
510 uiccCard.iccTransmitApduBasicChannel(
511 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
512 iccArgument.p3, iccArgument.data, onCompleted);
513 }
514 break;
515
516 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
517 ar = (AsyncResult) msg.obj;
518 request = (MainThreadRequest) ar.userObj;
519 if (ar.exception == null && ar.result != null) {
520 request.result = ar.result;
521 } else {
522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
523 if (ar.result == null) {
524 loge("iccTransmitApduBasicChannel: Empty response");
525 } else if (ar.exception instanceof CommandException) {
526 loge("iccTransmitApduBasicChannel: CommandException: " +
527 ar.exception);
528 } else {
529 loge("iccTransmitApduBasicChannel: Unknown exception");
530 }
531 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 break;
534
535 case CMD_EXCHANGE_SIM_IO:
536 request = (MainThreadRequest) msg.obj;
537 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800538 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 if (uiccCard == null) {
540 loge("iccExchangeSimIO: No UICC");
541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 } else {
544 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
545 request);
546 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
547 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
548 iccArgument.data, onCompleted);
549 }
550 break;
551
552 case EVENT_EXCHANGE_SIM_IO_DONE:
553 ar = (AsyncResult) msg.obj;
554 request = (MainThreadRequest) ar.userObj;
555 if (ar.exception == null && ar.result != null) {
556 request.result = ar.result;
557 } else {
558 request.result = new IccIoResult(0x6f, 0, (byte[])null);
559 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 break;
562
Derek Tan4d5e5c12014-02-04 11:54:58 -0800563 case CMD_SEND_ENVELOPE:
564 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 if (uiccCard == null) {
567 loge("sendEnvelopeWithStatus: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
572 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
573 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800574 break;
575
576 case EVENT_SEND_ENVELOPE_DONE:
577 ar = (AsyncResult) msg.obj;
578 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700579 if (ar.exception == null && ar.result != null) {
580 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800581 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700582 request.result = new IccIoResult(0x6F, 0, (byte[])null);
583 if (ar.result == null) {
584 loge("sendEnvelopeWithStatus: Empty response");
585 } else if (ar.exception instanceof CommandException) {
586 loge("sendEnvelopeWithStatus: CommandException: " +
587 ar.exception);
588 } else {
589 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
590 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800591 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800593 break;
594
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 case CMD_OPEN_CHANNEL:
596 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800597 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800598 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 if (uiccCard == null) {
600 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800601 request.result = new IccOpenLogicalChannelResponse(-1,
602 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700603 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 } else {
605 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800606 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
607 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700608 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 break;
610
611 case EVENT_OPEN_CHANNEL_DONE:
612 ar = (AsyncResult) msg.obj;
613 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 int[] result = (int[]) ar.result;
617 int channelId = result[0];
618 byte[] selectResponse = null;
619 if (result.length > 1) {
620 selectResponse = new byte[result.length - 1];
621 for (int i = 1; i < result.length; ++i) {
622 selectResponse[i - 1] = (byte) result[i];
623 }
624 }
625 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 if (ar.result == null) {
629 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 if (ar.exception != null) {
632 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
633 }
634
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700635 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700636 if (ar.exception instanceof CommandException) {
637 CommandException.Error error =
638 ((CommandException) (ar.exception)).getCommandError();
639 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700640 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700641 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700642 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 }
644 }
645 openChannelResp = new IccOpenLogicalChannelResponse(
646 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700648 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700649 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
652 case CMD_CLOSE_CHANNEL:
653 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800654 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 if (uiccCard == null) {
656 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900657 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 } else {
660 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
661 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
662 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 break;
664
665 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800666 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
667 break;
668
669 case CMD_NV_READ_ITEM:
670 request = (MainThreadRequest) msg.obj;
671 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800672 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
673 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800674 break;
675
676 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800682 request.result = "";
683 if (ar.result == null) {
684 loge("nvReadItem: Empty response");
685 } else if (ar.exception instanceof CommandException) {
686 loge("nvReadItem: CommandException: " +
687 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800689 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 }
691 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700692 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 break;
694
Jake Hambye994d462014-02-03 13:10:13 -0800695 case CMD_NV_WRITE_ITEM:
696 request = (MainThreadRequest) msg.obj;
697 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
698 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800699 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700700 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
703 case EVENT_NV_WRITE_ITEM_DONE:
704 handleNullReturnEvent(msg, "nvWriteItem");
705 break;
706
707 case CMD_NV_WRITE_CDMA_PRL:
708 request = (MainThreadRequest) msg.obj;
709 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800710 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800711 break;
712
713 case EVENT_NV_WRITE_CDMA_PRL_DONE:
714 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
715 break;
716
chen xu6dac5ab2018-10-26 17:39:23 -0700717 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800718 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700719 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800720 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800721 break;
722
chen xu6dac5ab2018-10-26 17:39:23 -0700723 case EVENT_RESET_MODEM_CONFIG_DONE:
724 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800725 break;
726
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 case CMD_GET_PREFERRED_NETWORK_TYPE:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700730 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 break;
732
733 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
734 ar = (AsyncResult) msg.obj;
735 request = (MainThreadRequest) ar.userObj;
736 if (ar.exception == null && ar.result != null) {
737 request.result = ar.result; // Integer
738 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800739 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800740 if (ar.result == null) {
741 loge("getPreferredNetworkType: Empty response");
742 } else if (ar.exception instanceof CommandException) {
743 loge("getPreferredNetworkType: CommandException: " +
744 ar.exception);
745 } else {
746 loge("getPreferredNetworkType: Unknown exception");
747 }
748 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800750 break;
751
752 case CMD_SET_PREFERRED_NETWORK_TYPE:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
755 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700756 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800757 break;
758
759 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
760 handleNullReturnEvent(msg, "setPreferredNetworkType");
761 break;
762
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000763 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
764 request = (MainThreadRequest)msg.obj;
765 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800766 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000767 break;
768
769 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
770 ar = (AsyncResult)msg.obj;
771 request = (MainThreadRequest)ar.userObj;
772 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000774 break;
775
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800776 case CMD_SET_VOICEMAIL_NUMBER:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
779 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800780 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
781 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800782 break;
783
784 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
785 handleNullReturnEvent(msg, "setVoicemailNumber");
786 break;
787
Stuart Scott54788802015-03-30 13:18:01 -0700788 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
789 request = (MainThreadRequest) msg.obj;
790 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
791 request);
792 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
793 break;
794
795 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
796 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
797 break;
798
Shishir Agrawal302c8692015-06-19 13:49:39 -0700799 case CMD_PERFORM_NETWORK_SCAN:
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
802 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
803 break;
804
805 case EVENT_PERFORM_NETWORK_SCAN_DONE:
806 ar = (AsyncResult) msg.obj;
807 request = (MainThreadRequest) ar.userObj;
808 CellNetworkScanResult cellScanResult;
809 if (ar.exception == null && ar.result != null) {
810 cellScanResult = new CellNetworkScanResult(
811 CellNetworkScanResult.STATUS_SUCCESS,
812 (List<OperatorInfo>) ar.result);
813 } else {
814 if (ar.result == null) {
815 loge("getCellNetworkScanResults: Empty response");
816 }
817 if (ar.exception != null) {
818 loge("getCellNetworkScanResults: Exception: " + ar.exception);
819 }
820 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
821 if (ar.exception instanceof CommandException) {
822 CommandException.Error error =
823 ((CommandException) (ar.exception)).getCommandError();
824 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
825 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
826 } else if (error == CommandException.Error.GENERIC_FAILURE) {
827 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
828 }
829 }
830 cellScanResult = new CellNetworkScanResult(errorCode, null);
831 }
832 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700833 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700834 break;
835
836 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
837 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700838 ManualNetworkSelectionArgument selArg =
839 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
841 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700842 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
843 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700844 break;
845
846 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
849 if (ar.exception == null) {
850 request.result = true;
851 } else {
852 request.result = false;
853 loge("setNetworkSelectionModeManual " + ar.exception);
854 }
855 notifyRequester(request);
856 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700857 break;
858
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700859 case CMD_GET_MODEM_ACTIVITY_INFO:
860 request = (MainThreadRequest) msg.obj;
861 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700862 if (defaultPhone != null) {
863 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
864 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700865 break;
866
867 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
868 ar = (AsyncResult) msg.obj;
869 request = (MainThreadRequest) ar.userObj;
870 if (ar.exception == null && ar.result != null) {
871 request.result = ar.result;
872 } else {
873 if (ar.result == null) {
874 loge("queryModemActivityInfo: Empty response");
875 } else if (ar.exception instanceof CommandException) {
876 loge("queryModemActivityInfo: CommandException: " +
877 ar.exception);
878 } else {
879 loge("queryModemActivityInfo: Unknown exception");
880 }
881 }
Amit Mahajand4766222016-01-28 15:28:28 -0800882 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
883 if (request.result == null) {
884 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
885 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700886 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700887 break;
888
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 case CMD_SET_ALLOWED_CARRIERS:
890 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800891 CarrierRestrictionRules argument =
892 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700893 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800894 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700895 break;
896
897 case EVENT_SET_ALLOWED_CARRIERS_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null && ar.result != null) {
901 request.result = ar.result;
902 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800903 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
904 if (ar.exception instanceof CommandException) {
905 loge("setAllowedCarriers: CommandException: " + ar.exception);
906 CommandException.Error error =
907 ((CommandException) (ar.exception)).getCommandError();
908 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
909 request.result =
910 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
911 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700912 } else {
913 loge("setAllowedCarriers: Unknown exception");
914 }
915 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700916 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700917 break;
918
919 case CMD_GET_ALLOWED_CARRIERS:
920 request = (MainThreadRequest) msg.obj;
921 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800922 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700923 break;
924
925 case EVENT_GET_ALLOWED_CARRIERS_DONE:
926 ar = (AsyncResult) msg.obj;
927 request = (MainThreadRequest) ar.userObj;
928 if (ar.exception == null && ar.result != null) {
929 request.result = ar.result;
930 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800931 request.result = new IllegalStateException(
932 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700933 if (ar.result == null) {
934 loge("getAllowedCarriers: Empty response");
935 } else if (ar.exception instanceof CommandException) {
936 loge("getAllowedCarriers: CommandException: " +
937 ar.exception);
938 } else {
939 loge("getAllowedCarriers: Unknown exception");
940 }
941 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700942 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700943 break;
944
Nathan Haroldb3014052017-01-25 15:57:32 -0800945 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
946 ar = (AsyncResult) msg.obj;
947 request = (MainThreadRequest) ar.userObj;
948 if (ar.exception == null && ar.result != null) {
949 request.result = ar.result;
950 } else {
951 request.result = new IllegalArgumentException(
952 "Failed to retrieve Forbidden Plmns");
953 if (ar.result == null) {
954 loge("getForbiddenPlmns: Empty response");
955 } else {
956 loge("getForbiddenPlmns: Unknown exception");
957 }
958 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700959 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800960 break;
961
962 case CMD_GET_FORBIDDEN_PLMNS:
963 request = (MainThreadRequest) msg.obj;
964 uiccCard = getUiccCardFromRequest(request);
965 if (uiccCard == null) {
966 loge("getForbiddenPlmns() UiccCard is null");
967 request.result = new IllegalArgumentException(
968 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700969 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800970 break;
971 }
972 Integer appType = (Integer) request.argument;
973 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
974 if (uiccApp == null) {
975 loge("getForbiddenPlmns() no app with specified type -- "
976 + appType);
977 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700978 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800979 break;
980 } else {
981 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
982 + " specified type -- " + appType);
983 }
984 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
985 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
986 onCompleted);
987 break;
988
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000989 case CMD_SWITCH_SLOTS:
990 request = (MainThreadRequest) msg.obj;
991 int[] physicalSlots = (int[]) request.argument;
992 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
993 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
994 break;
995
996 case EVENT_SWITCH_SLOTS_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001000 notifyRequester(request);
1001 break;
1002 case CMD_GET_NETWORK_SELECTION_MODE:
1003 request = (MainThreadRequest) msg.obj;
1004 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1005 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1006 break;
1007
1008 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
1011 if (ar.exception != null) {
1012 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1013 } else {
1014 int mode = ((int[]) ar.result)[0];
1015 if (mode == 0) {
1016 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1017 } else {
1018 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1019 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001020 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001021 notifyRequester(request);
1022 break;
1023 case CMD_GET_CDMA_ROAMING_MODE:
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1026 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1027 break;
1028 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 if (ar.exception != null) {
1032 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1033 } else {
1034 request.result = ((int[]) ar.result)[0];
1035 }
1036 notifyRequester(request);
1037 break;
1038 case CMD_SET_CDMA_ROAMING_MODE:
1039 request = (MainThreadRequest) msg.obj;
1040 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1041 int mode = (int) request.argument;
1042 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1043 break;
1044 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
1047 request.result = ar.exception == null;
1048 notifyRequester(request);
1049 break;
1050 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1053 int subscriptionMode = (int) request.argument;
1054 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1055 break;
1056 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1057 ar = (AsyncResult) msg.obj;
1058 request = (MainThreadRequest) ar.userObj;
1059 request.result = ar.exception == null;
1060 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001061 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 case CMD_GET_ALL_CELL_INFO:
1063 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001065 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001067 case EVENT_GET_ALL_CELL_INFO_DONE:
1068 ar = (AsyncResult) msg.obj;
1069 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001070 // If a timeout occurs, the response will be null
1071 request.result = (ar.exception == null && ar.result != null)
1072 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001073 synchronized (request) {
1074 request.notifyAll();
1075 }
1076 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001077 case CMD_REQUEST_CELL_INFO_UPDATE:
1078 request = (MainThreadRequest) msg.obj;
1079 request.phone.requestCellInfoUpdate(request.workSource,
1080 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1081 break;
1082 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1083 ar = (AsyncResult) msg.obj;
1084 request = (MainThreadRequest) ar.userObj;
1085 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1086 try {
1087 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001088 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001089 cb.onError(
1090 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1091 ar.exception.getClass().getName(),
1092 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001094 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001095 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001096 } else {
1097 // use the result as returned
1098 cb.onCellInfo((List<CellInfo>) ar.result);
1099 }
1100 } catch (RemoteException re) {
1101 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1102 }
1103 break;
1104 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001105 request = (MainThreadRequest) msg.obj;
1106 WorkSource ws = (WorkSource) request.argument;
1107 Phone phone = getPhoneFromRequest(request);
1108 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1109 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001110 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001111 ar = (AsyncResult) msg.obj;
1112 request = (MainThreadRequest) ar.userObj;
1113 if (ar.exception == null) {
1114 request.result = ar.result;
1115 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001116 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001117 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1118 ? new CdmaCellLocation() : new GsmCellLocation();
1119 }
1120
1121 synchronized (request) {
1122 request.notifyAll();
1123 }
1124 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001125 case CMD_MODEM_REBOOT:
1126 request = (MainThreadRequest) msg.obj;
1127 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001128 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001129 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001130 case EVENT_CMD_MODEM_REBOOT_DONE:
1131 handleNullReturnEvent(msg, "rebootModem");
1132 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001133 case CMD_REQUEST_ENABLE_MODEM:
1134 request = (MainThreadRequest) msg.obj;
1135 boolean enable = (boolean) request.argument;
1136 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001137 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001138 PhoneConfigurationManager.getInstance()
1139 .enablePhone(request.phone, enable, onCompleted);
1140 break;
1141 case EVENT_ENABLE_MODEM_DONE:
1142 ar = (AsyncResult) msg.obj;
1143 request = (MainThreadRequest) ar.userObj;
1144 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001145 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001146 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001147 if ((boolean) request.result) {
1148 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1149 updateModemStateMetrics();
1150 } else {
1151 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1152 + ar.exception);
1153 }
1154 notifyRequester(request);
1155 break;
1156 case CMD_GET_MODEM_STATUS:
1157 request = (MainThreadRequest) msg.obj;
1158 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1159 PhoneConfigurationManager.getInstance()
1160 .getPhoneStatusFromModem(request.phone, onCompleted);
1161 break;
1162 case EVENT_GET_MODEM_STATUS_DONE:
1163 ar = (AsyncResult) msg.obj;
1164 request = (MainThreadRequest) ar.userObj;
1165 int id = request.phone.getPhoneId();
1166 if (ar.exception == null && ar.result != null) {
1167 request.result = ar.result;
1168 //update the cache as modem status has changed
1169 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1170 (boolean) request.result);
1171 } else {
1172 // Return true if modem status cannot be retrieved. For most cases,
1173 // modem status is on. And for older version modems, GET_MODEM_STATUS
1174 // and disable modem are not supported. Modem is always on.
1175 // TODO: this should be fixed in R to support a third
1176 // status UNKNOWN b/131631629
1177 request.result = true;
1178 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1179 + ar.exception);
1180 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001181 notifyRequester(request);
1182 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001183 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1184 ar = (AsyncResult) msg.obj;
1185 request = (MainThreadRequest) ar.userObj;
1186 if (ar.exception == null && ar.result != null) {
1187 request.result = ar.result;
1188 } else {
1189 request.result = -1;
1190 loge("Failed to set Forbidden Plmns");
1191 if (ar.result == null) {
1192 loge("setForbidenPlmns: Empty response");
1193 } else if (ar.exception != null) {
1194 loge("setForbiddenPlmns: Exception: " + ar.exception);
1195 request.result = -1;
1196 } else {
1197 loge("setForbiddenPlmns: Unknown exception");
1198 }
1199 }
1200 notifyRequester(request);
1201 break;
1202 case CMD_SET_FORBIDDEN_PLMNS:
1203 request = (MainThreadRequest) msg.obj;
1204 uiccCard = getUiccCardFromRequest(request);
1205 if (uiccCard == null) {
1206 loge("setForbiddenPlmns: UiccCard is null");
1207 request.result = -1;
1208 notifyRequester(request);
1209 break;
1210 }
1211 Pair<Integer, List<String>> setFplmnsArgs =
1212 (Pair<Integer, List<String>>) request.argument;
1213 appType = setFplmnsArgs.first;
1214 List<String> fplmns = setFplmnsArgs.second;
1215 uiccApp = uiccCard.getApplicationByType(appType);
1216 if (uiccApp == null) {
1217 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1218 request.result = -1;
1219 loge("Failed to get UICC App");
1220 notifyRequester(request);
1221 } else {
1222 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1223 ((SIMRecords) uiccApp.getIccRecords())
1224 .setForbiddenPlmns(onCompleted, fplmns);
1225 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001226 case CMD_ERASE_MODEM_CONFIG:
1227 request = (MainThreadRequest) msg.obj;
1228 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1229 defaultPhone.eraseModemConfig(onCompleted);
1230 break;
1231 case EVENT_ERASE_MODEM_CONFIG_DONE:
1232 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001233 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 default:
1235 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1236 break;
1237 }
1238 }
Jake Hambye994d462014-02-03 13:10:13 -08001239
Pengquan Menga1bb6272018-09-06 09:59:22 -07001240 private void notifyRequester(MainThreadRequest request) {
1241 synchronized (request) {
1242 request.notifyAll();
1243 }
1244 }
1245
Jake Hambye994d462014-02-03 13:10:13 -08001246 private void handleNullReturnEvent(Message msg, String command) {
1247 AsyncResult ar = (AsyncResult) msg.obj;
1248 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1249 if (ar.exception == null) {
1250 request.result = true;
1251 } else {
1252 request.result = false;
1253 if (ar.exception instanceof CommandException) {
1254 loge(command + ": CommandException: " + ar.exception);
1255 } else {
1256 loge(command + ": Unknown exception");
1257 }
1258 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001259 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 }
1262
1263 /**
1264 * Posts the specified command to be executed on the main thread,
1265 * waits for the request to complete, and returns the result.
1266 * @see #sendRequestAsync
1267 */
1268 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001269 return sendRequest(
1270 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001271 }
1272
1273 /**
1274 * Posts the specified command to be executed on the main thread,
1275 * waits for the request to complete, and returns the result.
1276 * @see #sendRequestAsync
1277 */
1278 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1279 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001280 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001281 }
1282
1283 /**
1284 * Posts the specified command to be executed on the main thread,
1285 * waits for the request to complete, and returns the result.
1286 * @see #sendRequestAsync
1287 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001288 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001289 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001290 }
1291
1292 /**
1293 * Posts the specified command to be executed on the main thread,
1294 * waits for the request to complete, and returns the result.
1295 * @see #sendRequestAsync
1296 */
Nathan Harold92bed182018-10-12 18:16:49 -07001297 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1298 return sendRequest(command, argument, subId, null, workSource);
1299 }
1300
1301 /**
1302 * Posts the specified command to be executed on the main thread,
1303 * waits for the request to complete, and returns the result.
1304 * @see #sendRequestAsync
1305 */
1306 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1307 return sendRequest(
1308 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1309 }
1310
1311 /**
1312 * Posts the specified command to be executed on the main thread,
1313 * waits for the request to complete, and returns the result.
1314 * @see #sendRequestAsync
1315 */
1316 private Object sendRequest(
1317 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1319 throw new RuntimeException("This method will deadlock if called from the main thread.");
1320 }
1321
Nathan Harold92bed182018-10-12 18:16:49 -07001322 MainThreadRequest request = null;
1323 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1324 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1325 } else if (phone != null) {
1326 request = new MainThreadRequest(argument, phone, workSource);
1327 } else {
1328 request = new MainThreadRequest(argument, subId, workSource);
1329 }
1330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 Message msg = mMainThreadHandler.obtainMessage(command, request);
1332 msg.sendToTarget();
1333
1334 // Wait for the request to complete
1335 synchronized (request) {
1336 while (request.result == null) {
1337 try {
1338 request.wait();
1339 } catch (InterruptedException e) {
1340 // Do nothing, go back and wait until the request is complete
1341 }
1342 }
1343 }
1344 return request.result;
1345 }
1346
1347 /**
1348 * Asynchronous ("fire and forget") version of sendRequest():
1349 * Posts the specified command to be executed on the main thread, and
1350 * returns immediately.
1351 * @see #sendRequest
1352 */
1353 private void sendRequestAsync(int command) {
1354 mMainThreadHandler.sendEmptyMessage(command);
1355 }
1356
1357 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001358 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001360 */
1361 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001362 sendRequestAsync(command, argument, null, null);
1363 }
1364
1365 /**
1366 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1367 * @see {@link #sendRequest(int,Object)}
1368 */
1369 private void sendRequestAsync(
1370 int command, Object argument, Phone phone, WorkSource workSource) {
1371 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001372 Message msg = mMainThreadHandler.obtainMessage(command, request);
1373 msg.sendToTarget();
1374 }
1375
1376 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 * Initialize the singleton PhoneInterfaceManager instance.
1378 * This is only done once, at startup, from PhoneApp.onCreate().
1379 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001380 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 synchronized (PhoneInterfaceManager.class) {
1382 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001383 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 } else {
1385 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1386 }
1387 return sInstance;
1388 }
1389 }
1390
1391 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001392 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001395 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1397 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001398 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001399 mTelephonySharedPreferences =
1400 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001401 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001402 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001403
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 publish();
1405 }
1406
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001407 private Phone getDefaultPhone() {
1408 Phone thePhone = getPhone(getDefaultSubscription());
1409 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1410 }
1411
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 private void publish() {
1413 if (DBG) log("publish: " + this);
1414
1415 ServiceManager.addService("phone", this);
1416 }
1417
Stuart Scott584921c2015-01-15 17:10:34 -08001418 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001419 if (request.phone != null) {
1420 return request.phone;
1421 } else {
1422 return getPhoneFromSubId(request.subId);
1423 }
1424 }
1425
1426 private Phone getPhoneFromSubId(int subId) {
1427 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1428 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001429 }
1430
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001431 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1432 Phone phone = getPhoneFromRequest(request);
1433 return phone == null ? null :
1434 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1435 }
1436
Wink Saville36469e72014-06-11 15:17:00 -07001437 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001438 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001439 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001442 private void sendEraseModemConfig(Phone phone) {
1443 if (phone != null) {
1444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1445 mApp, phone.getSubId(), "eraseModemConfig");
1446 final long identity = Binder.clearCallingIdentity();
1447 try {
1448 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1449 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1450 } finally {
1451 Binder.restoreCallingIdentity(identity);
1452 }
1453 }
1454 }
1455
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001457 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001458 }
1459
Wink Savilleb564aae2014-10-23 10:18:09 -07001460 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 if (DBG) log("dial: " + number);
1462 // No permission check needed here: This is just a wrapper around the
1463 // ACTION_DIAL intent, which is available to any app since it puts up
1464 // the UI before it does anything.
1465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001466 final long identity = Binder.clearCallingIdentity();
1467 try {
1468 String url = createTelUrl(number);
1469 if (url == null) {
1470 return;
1471 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001473 // PENDING: should we just silently fail if phone is offhook or ringing?
1474 PhoneConstants.State state = mCM.getState(subId);
1475 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1476 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1477 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1478 mApp.startActivity(intent);
1479 }
1480 } finally {
1481 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 }
1483 }
1484
1485 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001486 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001487 }
1488
Wink Savilleb564aae2014-10-23 10:18:09 -07001489 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 if (DBG) log("call: " + number);
1491
1492 // This is just a wrapper around the ACTION_CALL intent, but we still
1493 // need to do a permission check since we're calling startActivity()
1494 // from the context of the phone app.
1495 enforceCallPermission();
1496
Jordan Liu1617b712019-07-10 15:06:26 -07001497 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 != AppOpsManager.MODE_ALLOWED) {
1499 return;
1500 }
1501
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001502 final long identity = Binder.clearCallingIdentity();
1503 try {
1504 String url = createTelUrl(number);
1505 if (url == null) {
1506 return;
1507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001509 boolean isValid = false;
1510 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1511 if (slist != null) {
1512 for (SubscriptionInfo subInfoRecord : slist) {
1513 if (subInfoRecord.getSubscriptionId() == subId) {
1514 isValid = true;
1515 break;
1516 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001517 }
Wink Saville08874612014-08-31 19:19:58 -07001518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001519 if (!isValid) {
1520 return;
1521 }
Wink Saville08874612014-08-31 19:19:58 -07001522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001523 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1524 intent.putExtra(SUBSCRIPTION_KEY, subId);
1525 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1526 mApp.startActivity(intent);
1527 } finally {
1528 Binder.restoreCallingIdentity(identity);
1529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 }
1531
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001533 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001534 }
1535
Wink Savilleb564aae2014-10-23 10:18:09 -07001536 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001537 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001538 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1539 }
1540
1541 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001542 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001543 }
1544
Wink Savilleb564aae2014-10-23 10:18:09 -07001545 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001546 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001547 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1548 }
1549
1550 /** {@hide} */
1551 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001552 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001553 }
1554
Wink Savilleb564aae2014-10-23 10:18:09 -07001555 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001557
1558 final long identity = Binder.clearCallingIdentity();
1559 try {
1560 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1561 checkSimPin.start();
1562 return checkSimPin.unlockSim(null, pin);
1563 } finally {
1564 Binder.restoreCallingIdentity(identity);
1565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 }
1567
Wink Saville9de0f752013-10-22 19:04:03 -07001568 /** {@hide} */
1569 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001570 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001571 }
1572
Wink Savilleb564aae2014-10-23 10:18:09 -07001573 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001575
1576 final long identity = Binder.clearCallingIdentity();
1577 try {
1578 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1579 checkSimPuk.start();
1580 return checkSimPuk.unlockSim(puk, pin);
1581 } finally {
1582 Binder.restoreCallingIdentity(identity);
1583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001584 }
1585
1586 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001587 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001588 * a synchronous one.
1589 */
1590 private static class UnlockSim extends Thread {
1591
1592 private final IccCard mSimCard;
1593
1594 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001595 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1596 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597
1598 // For replies from SimCard interface
1599 private Handler mHandler;
1600
1601 // For async handler to identify request type
1602 private static final int SUPPLY_PIN_COMPLETE = 100;
1603
1604 public UnlockSim(IccCard simCard) {
1605 mSimCard = simCard;
1606 }
1607
1608 @Override
1609 public void run() {
1610 Looper.prepare();
1611 synchronized (UnlockSim.this) {
1612 mHandler = new Handler() {
1613 @Override
1614 public void handleMessage(Message msg) {
1615 AsyncResult ar = (AsyncResult) msg.obj;
1616 switch (msg.what) {
1617 case SUPPLY_PIN_COMPLETE:
1618 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1619 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001620 mRetryCount = msg.arg1;
1621 if (ar.exception != null) {
1622 if (ar.exception instanceof CommandException &&
1623 ((CommandException)(ar.exception)).getCommandError()
1624 == CommandException.Error.PASSWORD_INCORRECT) {
1625 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1626 } else {
1627 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1628 }
1629 } else {
1630 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001632 mDone = true;
1633 UnlockSim.this.notifyAll();
1634 }
1635 break;
1636 }
1637 }
1638 };
1639 UnlockSim.this.notifyAll();
1640 }
1641 Looper.loop();
1642 }
1643
1644 /*
1645 * Use PIN or PUK to unlock SIM card
1646 *
1647 * If PUK is null, unlock SIM card with PIN
1648 *
1649 * If PUK is not null, unlock SIM card with PUK and set PIN code
1650 */
Wink Saville9de0f752013-10-22 19:04:03 -07001651 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652
1653 while (mHandler == null) {
1654 try {
1655 wait();
1656 } catch (InterruptedException e) {
1657 Thread.currentThread().interrupt();
1658 }
1659 }
1660 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1661
1662 if (puk == null) {
1663 mSimCard.supplyPin(pin, callback);
1664 } else {
1665 mSimCard.supplyPuk(puk, pin, callback);
1666 }
1667
1668 while (!mDone) {
1669 try {
1670 Log.d(LOG_TAG, "wait for done");
1671 wait();
1672 } catch (InterruptedException e) {
1673 // Restore the interrupted status
1674 Thread.currentThread().interrupt();
1675 }
1676 }
1677 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001678 int[] resultArray = new int[2];
1679 resultArray[0] = mResult;
1680 resultArray[1] = mRetryCount;
1681 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 }
1683 }
1684
1685 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001686 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001687
1688 }
1689
Wink Savilleb564aae2014-10-23 10:18:09 -07001690 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 // No permission check needed here: this call is harmless, and it's
1692 // needed for the ServiceState.requestStateUpdate() call (which is
1693 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001694 final long identity = Binder.clearCallingIdentity();
1695 try {
1696 final Phone phone = getPhone(subId);
1697 if (phone != null) {
1698 phone.updateServiceLocation();
1699 }
1700 } finally {
1701 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 }
1704
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001705 @Override
1706 public boolean isRadioOn(String callingPackage) {
1707 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001708 }
1709
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001710 @Override
1711 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001713 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001714 return false;
1715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001716
1717 final long identity = Binder.clearCallingIdentity();
1718 try {
1719 return isRadioOnForSubscriber(subId);
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
1722 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001723 }
1724
1725 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001726 final long identity = Binder.clearCallingIdentity();
1727 try {
1728 final Phone phone = getPhone(subId);
1729 if (phone != null) {
1730 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1731 } else {
1732 return false;
1733 }
1734 } finally {
1735 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 }
1738
1739 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001740 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 }
Wink Saville36469e72014-06-11 15:17:00 -07001742
Wink Savilleb564aae2014-10-23 10:18:09 -07001743 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001745
1746 final long identity = Binder.clearCallingIdentity();
1747 try {
1748 final Phone phone = getPhone(subId);
1749 if (phone != null) {
1750 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1751 }
1752 } finally {
1753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001754 }
Wink Saville36469e72014-06-11 15:17:00 -07001755 }
1756
1757 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001758 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001759 }
1760
Wink Savilleb564aae2014-10-23 10:18:09 -07001761 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001763
1764 final long identity = Binder.clearCallingIdentity();
1765 try {
1766 final Phone phone = getPhone(subId);
1767 if (phone == null) {
1768 return false;
1769 }
1770 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1771 toggleRadioOnOffForSubscriber(subId);
1772 }
1773 return true;
1774 } finally {
1775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 }
Wink Saville36469e72014-06-11 15:17:00 -07001778
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001779 public boolean needMobileRadioShutdown() {
1780 /*
1781 * If any of the Radios are available, it will need to be
1782 * shutdown. So return true if any Radio is available.
1783 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001784 final long identity = Binder.clearCallingIdentity();
1785 try {
1786 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1787 Phone phone = PhoneFactory.getPhone(i);
1788 if (phone != null && phone.isRadioAvailable()) return true;
1789 }
1790 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1791 return false;
1792 } finally {
1793 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001794 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001795 }
1796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001798 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799 enforceModifyPermission();
1800
1801 final long identity = Binder.clearCallingIdentity();
1802 try {
1803 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1804 logv("Shutting down Phone " + i);
1805 shutdownRadioUsingPhoneId(i);
1806 }
1807 } finally {
1808 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001809 }
1810 }
1811
1812 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001813 Phone phone = PhoneFactory.getPhone(phoneId);
1814 if (phone != null && phone.isRadioAvailable()) {
1815 phone.shutdownRadio();
1816 }
1817 }
1818
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001820 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001821
1822 final long identity = Binder.clearCallingIdentity();
1823 try {
1824 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1825 if (defaultPhone != null) {
1826 defaultPhone.setRadioPower(turnOn);
1827 return true;
1828 } else {
1829 loge("There's no default phone.");
1830 return false;
1831 }
1832 } finally {
1833 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001834 }
Wink Saville36469e72014-06-11 15:17:00 -07001835 }
1836
Wink Savilleb564aae2014-10-23 10:18:09 -07001837 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001839
1840 final long identity = Binder.clearCallingIdentity();
1841 try {
1842 final Phone phone = getPhone(subId);
1843 if (phone != null) {
1844 phone.setRadioPower(turnOn);
1845 return true;
1846 } else {
1847 return false;
1848 }
1849 } finally {
1850 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001851 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001852 }
1853
Wink Saville36469e72014-06-11 15:17:00 -07001854 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001855 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 public boolean enableDataConnectivity() {
1857 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001858
1859 final long identity = Binder.clearCallingIdentity();
1860 try {
1861 int subId = mSubscriptionController.getDefaultDataSubId();
1862 final Phone phone = getPhone(subId);
1863 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001864 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001865 return true;
1866 } else {
1867 return false;
1868 }
1869 } finally {
1870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 }
1873
Wink Saville36469e72014-06-11 15:17:00 -07001874 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 public boolean disableDataConnectivity() {
1877 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001878
1879 final long identity = Binder.clearCallingIdentity();
1880 try {
1881 int subId = mSubscriptionController.getDefaultDataSubId();
1882 final Phone phone = getPhone(subId);
1883 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001884 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001885 return true;
1886 } else {
1887 return false;
1888 }
1889 } finally {
1890 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 }
1893
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001895 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001896 final long identity = Binder.clearCallingIdentity();
1897 try {
1898 final Phone phone = getPhone(subId);
1899 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001900 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001901 } else {
1902 return false;
1903 }
1904 } finally {
1905 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 }
1908
1909 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001910 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001911 }
1912
pkanwarae03a6b2016-11-06 20:37:09 -08001913 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001914 enforceCallPermission();
1915
1916 final long identity = Binder.clearCallingIdentity();
1917 try {
1918 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1919 return;
1920 }
1921 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1922 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1923 } finally {
1924 Binder.restoreCallingIdentity(identity);
1925 }
pkanwar32d516d2016-10-14 19:37:38 -07001926 };
1927
Wink Savilleb564aae2014-10-23 10:18:09 -07001928 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001930
1931 final long identity = Binder.clearCallingIdentity();
1932 try {
1933 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1934 return false;
1935 }
1936 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1937 } finally {
1938 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001939 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 }
1941
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001943 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001944 }
1945
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001946 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001947 final long identity = Binder.clearCallingIdentity();
1948 try {
1949 Phone phone = PhoneFactory.getPhone(slotIndex);
1950 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1951 PhoneConstantConversions.convertCallState(phone.getState());
1952 } finally {
1953 Binder.restoreCallingIdentity(identity);
1954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 }
1956
Sanket Padawe356d7632015-06-22 14:03:32 -07001957 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001958 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001959 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1960 }
1961
1962 @Override
1963 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001964 final long identity = Binder.clearCallingIdentity();
1965 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001966 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001967 if (phone != null) {
1968 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1969 } else {
1970 return PhoneConstantConversions.convertDataState(
1971 PhoneConstants.DataState.DISCONNECTED);
1972 }
1973 } finally {
1974 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001975 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 }
1977
Sanket Padawe356d7632015-06-22 14:03:32 -07001978 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001979 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001980 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1981 }
1982
1983 @Override
1984 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985 final long identity = Binder.clearCallingIdentity();
1986 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001987 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001988 if (phone != null) {
1989 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1990 } else {
1991 return TelephonyManager.DATA_ACTIVITY_NONE;
1992 }
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001995 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 }
1997
1998 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001999 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002000 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002001 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002002
2003 LocationAccessPolicy.LocationPermissionResult locationResult =
2004 LocationAccessPolicy.checkLocationPermission(mApp,
2005 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2006 .setCallingPackage(callingPackage)
2007 .setCallingPid(Binder.getCallingPid())
2008 .setCallingUid(Binder.getCallingUid())
2009 .setMethod("getCellLocation")
2010 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2011 .build());
2012 switch (locationResult) {
2013 case DENIED_HARD:
2014 throw new SecurityException("Not allowed to access cell location");
2015 case DENIED_SOFT:
2016 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
2018
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002019 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 if (DBG_LOC) log("getCellLocation: is active user");
2023 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002024 int subId = mSubscriptionController.getDefaultDataSubId();
2025 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2026 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002027 return data;
2028 } finally {
2029 Binder.restoreCallingIdentity(identity);
2030 }
Svetoslav64fad262015-04-14 14:35:21 -07002031 }
2032
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002034 public String getNetworkCountryIsoForPhone(int phoneId) {
2035 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2036 // registered cell info, so return a NULL country instead.
2037 final long identity = Binder.clearCallingIdentity();
2038 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002039 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2040 // Get default phone in this case.
2041 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2042 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002043 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002044 // Todo: fix this when we can get the actual cellular network info when the device
2045 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002046 if (TelephonyManager.NETWORK_TYPE_IWLAN
2047 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2048 return "";
2049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002050 Phone phone = PhoneFactory.getPhone(phoneId);
2051 if (phone != null) {
2052 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002053 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054 if (sst != null) {
2055 LocaleTracker lt = sst.getLocaleTracker();
2056 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002057 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2058 return lt.getCurrentCountry();
2059 } else if (emergencyNumberTracker != null) {
2060 return emergencyNumberTracker.getEmergencyCountryIso();
2061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002062 }
2063 }
2064 }
2065 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002066 } finally {
2067 Binder.restoreCallingIdentity(identity);
2068 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002069 }
2070
2071 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002073 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002074 }
2075
Sanket Padawe356d7632015-06-22 14:03:32 -07002076 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002077 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078 mApp.enforceCallingOrSelfPermission(
2079 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080
2081 final long identity = Binder.clearCallingIdentity();
2082 try {
2083 final Phone phone = getPhone(subId);
2084 if (phone != null) {
2085 phone.enableLocationUpdates();
2086 }
2087 } finally {
2088 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 }
2091
2092 @Override
2093 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002094 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002095 }
2096
Sanket Padawe356d7632015-06-22 14:03:32 -07002097 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002098 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 mApp.enforceCallingOrSelfPermission(
2100 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002101
2102 final long identity = Binder.clearCallingIdentity();
2103 try {
2104 final Phone phone = getPhone(subId);
2105 if (phone != null) {
2106 phone.disableLocationUpdates();
2107 }
2108 } finally {
2109 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002110 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 }
2112
Nathan Harold31d7ff32018-10-15 20:20:30 -07002113 /**
2114 * Returns the target SDK version number for a given package name.
2115 *
Nathan Haroldec184742019-07-10 17:04:16 -07002116 * This call MUST be invoked before clearing the calling UID.
2117 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002118 * @return target SDK if the package is found or INT_MAX.
2119 */
2120 private int getTargetSdk(String packageName) {
2121 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002122 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002123 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002124 if (ai != null) return ai.targetSdkVersion;
2125 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002126 loge("Failed to get package info for pkg="
2127 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002128 }
2129 return Integer.MAX_VALUE;
2130 }
2131
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 @Override
2133 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002134 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2135 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002136 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2137 throw new SecurityException(
2138 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2139 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002140
Jordan Liu1617b712019-07-10 15:06:26 -07002141 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002142 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2143 return null;
2144 }
Svetoslav64fad262015-04-14 14:35:21 -07002145
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002146 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147
Nathan Haroldf180aac2018-06-01 18:43:55 -07002148 List<CellInfo> info = getAllCellInfo(callingPackage);
2149 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150
Nathan Haroldf180aac2018-06-01 18:43:55 -07002151 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2152 for (CellInfo ci : info) {
2153 if (ci instanceof CellInfoGsm) {
2154 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2155 } else if (ci instanceof CellInfoWcdma) {
2156 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002159 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 }
2161
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002162 private List<CellInfo> getCachedCellInfo() {
2163 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2164 for (Phone phone : PhoneFactory.getPhones()) {
2165 List<CellInfo> info = phone.getAllCellInfo();
2166 if (info != null) cellInfos.addAll(info);
2167 }
2168 return cellInfos;
2169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170
2171 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002172 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002173 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002174 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002175
2176 LocationAccessPolicy.LocationPermissionResult locationResult =
2177 LocationAccessPolicy.checkLocationPermission(mApp,
2178 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2179 .setCallingPackage(callingPackage)
2180 .setCallingPid(Binder.getCallingPid())
2181 .setCallingUid(Binder.getCallingUid())
2182 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002183 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002184 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2185 .build());
2186 switch (locationResult) {
2187 case DENIED_HARD:
2188 throw new SecurityException("Not allowed to access cell info");
2189 case DENIED_SOFT:
2190 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 }
2192
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002193 final int targetSdk = getTargetSdk(callingPackage);
2194 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2195 return getCachedCellInfo();
2196 }
2197
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002198 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002199 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002200 final long identity = Binder.clearCallingIdentity();
2201 try {
2202 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2203 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002204 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002205 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002206 if (info != null) cellInfos.addAll(info);
2207 }
2208 return cellInfos;
2209 } finally {
2210 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 }
2212 }
2213
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002214 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002215 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2216 requestCellInfoUpdateInternal(
2217 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2218 }
2219
2220 @Override
2221 public void requestCellInfoUpdateWithWorkSource(
2222 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2223 enforceModifyPermission();
2224 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2225 }
2226
2227 private void requestCellInfoUpdateInternal(
2228 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002229 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002230 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002231
2232 LocationAccessPolicy.LocationPermissionResult locationResult =
2233 LocationAccessPolicy.checkLocationPermission(mApp,
2234 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2235 .setCallingPackage(callingPackage)
2236 .setCallingPid(Binder.getCallingPid())
2237 .setCallingUid(Binder.getCallingUid())
2238 .setMethod("requestCellInfoUpdate")
2239 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2240 .build());
2241 switch (locationResult) {
2242 case DENIED_HARD:
2243 throw new SecurityException("Not allowed to access cell info");
2244 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002245 try {
2246 cb.onCellInfo(new ArrayList<CellInfo>());
2247 } catch (RemoteException re) {
2248 // Drop without consequences
2249 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002250 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002251 }
2252
Nathan Harolda939a962019-05-09 10:13:47 -07002253
2254 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002255 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2256
2257 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2258 }
2259
2260 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002262 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264
2265 final long identity = Binder.clearCallingIdentity();
2266 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002267 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002268 } finally {
2269 Binder.restoreCallingIdentity(identity);
2270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 }
2272
Shishir Agrawala9f32182016-04-12 12:00:16 -07002273 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002274 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002275 Phone phone = PhoneFactory.getPhone(slotIndex);
2276 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002277 return null;
2278 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002279 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002280 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2281 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002282 return null;
2283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002284
2285 final long identity = Binder.clearCallingIdentity();
2286 try {
2287 return phone.getImei();
2288 } finally {
2289 Binder.restoreCallingIdentity(identity);
2290 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002291 }
2292
2293 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002294 public String getTypeAllocationCodeForSlot(int slotIndex) {
2295 Phone phone = PhoneFactory.getPhone(slotIndex);
2296 String tac = null;
2297 if (phone != null) {
2298 String imei = phone.getImei();
2299 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2300 }
2301 return tac;
2302 }
2303
2304 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002305 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002306 Phone phone = PhoneFactory.getPhone(slotIndex);
2307 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002308 return null;
2309 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002310
Jeff Davidson913390f2018-02-23 17:11:49 -08002311 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002312 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2313 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002314 return null;
2315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002316
2317 final long identity = Binder.clearCallingIdentity();
2318 try {
2319 return phone.getMeid();
2320 } finally {
2321 Binder.restoreCallingIdentity(identity);
2322 }
Jack Yu2af8d712017-03-15 17:14:14 -07002323 }
2324
2325 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002326 public String getManufacturerCodeForSlot(int slotIndex) {
2327 Phone phone = PhoneFactory.getPhone(slotIndex);
2328 String manufacturerCode = null;
2329 if (phone != null) {
2330 String meid = phone.getMeid();
2331 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2332 }
2333 return manufacturerCode;
2334 }
2335
2336 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002337 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002338 Phone phone = PhoneFactory.getPhone(slotIndex);
2339 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002340 return null;
2341 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002342 int subId = phone.getSubId();
2343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2344 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2345 return null;
2346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 return phone.getDeviceSvn();
2351 } finally {
2352 Binder.restoreCallingIdentity(identity);
2353 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002354 }
2355
fionaxu43304da2017-11-27 22:51:16 -08002356 @Override
2357 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002358 final long identity = Binder.clearCallingIdentity();
2359 try {
2360 final Phone phone = getPhone(subId);
2361 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2362 } finally {
2363 Binder.restoreCallingIdentity(identity);
2364 }
fionaxu43304da2017-11-27 22:51:16 -08002365 }
2366
2367 @Override
2368 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002369 final long identity = Binder.clearCallingIdentity();
2370 try {
2371 final Phone phone = getPhone(subId);
2372 return phone == null ? null : phone.getCarrierName();
2373 } finally {
2374 Binder.restoreCallingIdentity(identity);
2375 }
fionaxu43304da2017-11-27 22:51:16 -08002376 }
2377
calvinpanffe225e2018-11-01 19:43:06 +08002378 @Override
chen xu0026ca62019-03-06 15:28:50 -08002379 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 final Phone phone = getPhone(subId);
2383 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002384 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002385 } finally {
2386 Binder.restoreCallingIdentity(identity);
2387 }
2388 }
2389
2390 @Override
chen xu0026ca62019-03-06 15:28:50 -08002391 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002392 final long identity = Binder.clearCallingIdentity();
2393 try {
2394 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002395 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002396 } finally {
2397 Binder.restoreCallingIdentity(identity);
2398 }
2399 }
2400
chen xu651eec72018-11-11 19:03:44 -08002401 @Override
chen xu864e11c2018-12-06 22:10:03 -08002402 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2403 if (!isSubscriptionMccMnc) {
2404 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2405 }
chen xu651eec72018-11-11 19:03:44 -08002406 final Phone phone = PhoneFactory.getPhone(slotIndex);
2407 if (phone == null) {
2408 return TelephonyManager.UNKNOWN_CARRIER_ID;
2409 }
2410 final long identity = Binder.clearCallingIdentity();
2411 try {
2412 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2413 } finally {
2414 Binder.restoreCallingIdentity(identity);
2415 }
2416 }
2417
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 //
2419 // Internal helper methods.
2420 //
2421
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002422 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2424 *
2425 * @throws SecurityException if the caller does not have the required permission
2426 */
2427 private void enforceModifyPermission() {
2428 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2429 }
2430
Shuo Qianf2b2df42019-11-13 17:43:31 -08002431 private void enforceActiveEmergencySessionPermission() {
2432 mApp.enforceCallingOrSelfPermission(
2433 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2434 }
2435
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 /**
2437 * Make sure the caller has the CALL_PHONE permission.
2438 *
2439 * @throws SecurityException if the caller does not have the required permission
2440 */
2441 private void enforceCallPermission() {
2442 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2443 }
2444
paulhu423b5f22019-08-23 19:17:33 +08002445 private void enforceSettingsPermission() {
2446 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002447 }
2448
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 private String createTelUrl(String number) {
2450 if (TextUtils.isEmpty(number)) {
2451 return null;
2452 }
2453
Jake Hambye994d462014-02-03 13:10:13 -08002454 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 }
2456
Ihab Awadf9e92732013-12-05 18:02:52 -08002457 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2459 }
2460
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002461 private static void logv(String msg) {
2462 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2463 }
2464
Ihab Awadf9e92732013-12-05 18:02:52 -08002465 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2467 }
2468
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002469 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002471 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002472 }
2473
Sanket Padawe356d7632015-06-22 14:03:32 -07002474 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002475 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002476 final long identity = Binder.clearCallingIdentity();
2477 try {
2478 final Phone phone = PhoneFactory.getPhone(slotIndex);
2479 if (phone == null) {
2480 return PhoneConstants.PHONE_TYPE_NONE;
2481 } else {
2482 return phone.getPhoneType();
2483 }
2484 } finally {
2485 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 }
2488
2489 /**
2490 * Returns the CDMA ERI icon index to display
2491 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002492 @Override
2493 public int getCdmaEriIconIndex(String callingPackage) {
2494 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002495 }
2496
Sanket Padawe356d7632015-06-22 14:03:32 -07002497 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002498 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002500 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002501 return -1;
2502 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503
2504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 final Phone phone = getPhone(subId);
2507 if (phone != null) {
2508 return phone.getCdmaEriIconIndex();
2509 } else {
2510 return -1;
2511 }
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516
2517 /**
2518 * Returns the CDMA ERI icon mode,
2519 * 0 - ON
2520 * 1 - FLASHING
2521 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002522 @Override
2523 public int getCdmaEriIconMode(String callingPackage) {
2524 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002525 }
2526
Sanket Padawe356d7632015-06-22 14:03:32 -07002527 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002528 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002530 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002531 return -1;
2532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533
2534 final long identity = Binder.clearCallingIdentity();
2535 try {
2536 final Phone phone = getPhone(subId);
2537 if (phone != null) {
2538 return phone.getCdmaEriIconMode();
2539 } else {
2540 return -1;
2541 }
2542 } finally {
2543 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002545 }
2546
2547 /**
2548 * Returns the CDMA ERI text,
2549 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002550 @Override
2551 public String getCdmaEriText(String callingPackage) {
2552 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002553 }
2554
Sanket Padawe356d7632015-06-22 14:03:32 -07002555 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002556 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002558 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002559 return null;
2560 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002561
2562 final long identity = Binder.clearCallingIdentity();
2563 try {
2564 final Phone phone = getPhone(subId);
2565 if (phone != null) {
2566 return phone.getCdmaEriText();
2567 } else {
2568 return null;
2569 }
2570 } finally {
2571 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002573 }
2574
2575 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002576 * Returns the CDMA MDN.
2577 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002578 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002579 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2581 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582
2583 final long identity = Binder.clearCallingIdentity();
2584 try {
2585 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002586 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002587 return phone.getLine1Number();
2588 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002589 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590 return null;
2591 }
2592 } finally {
2593 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002594 }
2595 }
2596
2597 /**
2598 * Returns the CDMA MIN.
2599 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002600 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002601 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2603 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604
2605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 final Phone phone = getPhone(subId);
2608 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2609 return phone.getCdmaMin();
2610 } else {
2611 return null;
2612 }
2613 } finally {
2614 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002615 }
2616 }
2617
Hall Liud892bec2018-11-30 14:51:45 -08002618 @Override
2619 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2620 INumberVerificationCallback callback, String callingPackage) {
2621 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2622 != PERMISSION_GRANTED) {
2623 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2624 }
2625 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2626
2627 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2628 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2629 throw new SecurityException("Calling package must be configured in the device config");
2630 }
2631
2632 if (range == null) {
2633 throw new NullPointerException("Range must be non-null");
2634 }
2635
2636 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002637 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002638
2639 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2640 }
2641
Junda Liuca05d5d2014-08-14 22:36:34 -07002642 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643 * Returns true if CDMA provisioning needs to run.
2644 */
2645 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646 final long identity = Binder.clearCallingIdentity();
2647 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002648 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649 } finally {
2650 Binder.restoreCallingIdentity(identity);
2651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 }
2653
2654 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002655 * Sets the voice mail number of a given subId.
2656 */
2657 @Override
2658 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002659 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660
2661 final long identity = Binder.clearCallingIdentity();
2662 try {
2663 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2664 new Pair<String, String>(alphaTag, number), new Integer(subId));
2665 return success;
2666 } finally {
2667 Binder.restoreCallingIdentity(identity);
2668 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002669 }
2670
Ta-wei Yen87c49842016-05-13 21:19:52 -07002671 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002672 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2673 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002674 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2675 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002676 if (!TextUtils.equals(callingPackage, systemDialer)) {
2677 throw new SecurityException("caller must be system dialer");
2678 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679
2680 final long identity = Binder.clearCallingIdentity();
2681 try {
2682 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2683 if (phoneAccountHandle == null) {
2684 return null;
2685 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002686 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687 } finally {
2688 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002689 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002690 }
2691
2692 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002693 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002694 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002696 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002697 return null;
2698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002700 final long identity = Binder.clearCallingIdentity();
2701 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002702 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002703 } finally {
2704 Binder.restoreCallingIdentity(identity);
2705 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002706 }
2707
2708 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002709 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2710 VisualVoicemailSmsFilterSettings settings) {
2711 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712
2713 final long identity = Binder.clearCallingIdentity();
2714 try {
2715 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002716 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 } finally {
2718 Binder.restoreCallingIdentity(identity);
2719 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002720 }
2721
2722 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002723 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2724 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725
2726 final long identity = Binder.clearCallingIdentity();
2727 try {
2728 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002729 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730 } finally {
2731 Binder.restoreCallingIdentity(identity);
2732 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002733 }
2734
2735 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002736 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2737 String callingPackage, int subId) {
2738 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739
2740 final long identity = Binder.clearCallingIdentity();
2741 try {
2742 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002743 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744 } finally {
2745 Binder.restoreCallingIdentity(identity);
2746 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002747 }
2748
2749 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002750 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002751 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002752
2753 final long identity = Binder.clearCallingIdentity();
2754 try {
2755 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002756 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757 } finally {
2758 Binder.restoreCallingIdentity(identity);
2759 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002760 }
2761
2762 @Override
2763 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2764 String number, int port, String text, PendingIntent sentIntent) {
2765 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002766 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002767 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002768 SmsController smsController = PhoneFactory.getSmsController();
2769 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2770 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002771 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002772
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002773 /**
fionaxu0152e512016-11-14 13:36:14 -08002774 * Sets the voice activation state of a given subId.
2775 */
2776 @Override
2777 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2779 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780
2781 final long identity = Binder.clearCallingIdentity();
2782 try {
2783 final Phone phone = getPhone(subId);
2784 if (phone != null) {
2785 phone.setVoiceActivationState(activationState);
2786 } else {
2787 loge("setVoiceActivationState fails with invalid subId: " + subId);
2788 }
2789 } finally {
2790 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002791 }
2792 }
2793
2794 /**
2795 * Sets the data activation state of a given subId.
2796 */
2797 @Override
2798 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2800 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801
2802 final long identity = Binder.clearCallingIdentity();
2803 try {
2804 final Phone phone = getPhone(subId);
2805 if (phone != null) {
2806 phone.setDataActivationState(activationState);
2807 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002808 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002809 }
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002812 }
2813 }
2814
2815 /**
2816 * Returns the voice activation state of a given subId.
2817 */
2818 @Override
2819 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002820 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821
fionaxu0152e512016-11-14 13:36:14 -08002822 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 if (phone != null) {
2826 return phone.getVoiceActivationState();
2827 } else {
2828 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2829 }
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002832 }
2833 }
2834
2835 /**
2836 * Returns the data activation state of a given subId.
2837 */
2838 @Override
2839 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002840 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002841
fionaxu0152e512016-11-14 13:36:14 -08002842 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002843 final long identity = Binder.clearCallingIdentity();
2844 try {
2845 if (phone != null) {
2846 return phone.getDataActivationState();
2847 } else {
2848 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2849 }
2850 } finally {
2851 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002852 }
2853 }
2854
2855 /**
Wink Saville36469e72014-06-11 15:17:00 -07002856 * Returns the unread count of voicemails for a subId
2857 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002859 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2860 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2861 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2862 return 0;
2863 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 final Phone phone = getPhone(subId);
2867 if (phone != null) {
2868 return phone.getVoiceMessageCount();
2869 } else {
2870 return 0;
2871 }
2872 } finally {
2873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002875 }
2876
2877 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002878 * returns true, if the device is in a state where both voice and data
2879 * are supported simultaneously. This can change based on location or network condition.
2880 */
2881 @Override
2882 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002883 final long identity = Binder.clearCallingIdentity();
2884 try {
2885 final Phone phone = getPhone(subId);
2886 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2887 } finally {
2888 Binder.restoreCallingIdentity(identity);
2889 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002890 }
2891
2892 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002893 * Send the dialer code if called from the current default dialer or the caller has
2894 * carrier privilege.
2895 * @param inputCode The dialer code to send
2896 */
2897 @Override
2898 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002899 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002900 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002901 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2902 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002903 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002904 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2905 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907
2908 final long identity = Binder.clearCallingIdentity();
2909 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002910 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002911 } finally {
2912 Binder.restoreCallingIdentity(identity);
2913 }
fionaxu235cc5e2017-03-06 22:25:57 -08002914 }
2915
Pengquan Menga1bb6272018-09-06 09:59:22 -07002916 @Override
2917 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002918 if (!isActiveSubscription(subId)) {
2919 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2920 }
2921
Pengquan Menga1bb6272018-09-06 09:59:22 -07002922 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2923 }
2924
Brad Ebinger35c841c2018-10-01 10:40:55 -07002925 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002926 public boolean isInEmergencySmsMode() {
2927 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 for (Phone phone : PhoneFactory.getPhones()) {
2931 if (phone.isInEmergencySmsMode()) {
2932 return true;
2933 }
2934 }
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
2937 }
2938 return false;
2939 }
2940
2941 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002942 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2943 throws RemoteException {
2944 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002945 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2946 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2947 "IMS not available on device.");
2948 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002949 final long token = Binder.clearCallingIdentity();
2950 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002951 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002952 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002953 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002954 } catch (ImsException e) {
2955 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002956 } finally {
2957 Binder.restoreCallingIdentity(token);
2958 }
2959 }
2960
2961 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002962 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2963 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002964 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2965 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2966 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002967 final long token = Binder.clearCallingIdentity();
2968 try {
2969 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2970 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2971 .removeRegistrationCallbackForSubscription(c, subId);
2972 } catch (ImsException e) {
2973 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2974 + "is inactive, ignoring unregister.");
2975 // If the subscription is no longer active, just return, since the callback
2976 // will already have been removed internally.
2977 } finally {
2978 Binder.restoreCallingIdentity(token);
2979 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002980 }
2981
Brad Ebinger774ba362019-10-22 17:36:18 -07002982 /**
2983 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2984 */
2985 @Override
2986 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2987 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2988 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2989 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2990 "IMS not available on device.");
2991 }
2992 final long token = Binder.clearCallingIdentity();
2993 try {
2994 Phone phone = getPhone(subId);
2995 if (phone == null) {
2996 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2997 + subId + "'");
2998 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
2999 }
3000 phone.getImsRegistrationState(regState -> {
3001 try {
3002 consumer.accept((regState == null)
3003 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3004 } catch (RemoteException e) {
3005 // Ignore if the remote process is no longer available to call back.
3006 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3007 }
3008 });
3009 } finally {
3010 Binder.restoreCallingIdentity(token);
3011 }
3012 }
3013
3014 /**
3015 * Get the transport type for the IMS service registration state.
3016 */
3017 @Override
3018 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3019 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3020 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3021 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3022 "IMS not available on device.");
3023 }
3024 final long token = Binder.clearCallingIdentity();
3025 try {
3026 Phone phone = getPhone(subId);
3027 if (phone == null) {
3028 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3029 + subId + "'");
3030 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3031 }
3032 phone.getImsRegistrationTech(regTech -> {
3033 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3034 int regTechConverted = (regTech == null)
3035 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3036 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3037 regTechConverted);
3038 try {
3039 consumer.accept(regTechConverted);
3040 } catch (RemoteException e) {
3041 // Ignore if the remote process is no longer available to call back.
3042 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3043 }
3044 });
3045 } finally {
3046 Binder.restoreCallingIdentity(token);
3047 }
3048 }
3049
Brad Ebinger35c841c2018-10-01 10:40:55 -07003050 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003051 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3052 throws RemoteException {
3053 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003054 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3055 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3056 "IMS not available on device.");
3057 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003058 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3059 final long token = Binder.clearCallingIdentity();
3060 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003061 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003062 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003063 } catch (ImsException e) {
3064 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003065 } finally {
3066 Binder.restoreCallingIdentity(token);
3067 }
3068 }
3069
3070 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003071 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3072 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003073 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3074 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3075 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003076
3077 final long token = Binder.clearCallingIdentity();
3078 try {
3079 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3080 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003081 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003082 } catch (ImsException e) {
3083 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3084 + "is inactive, ignoring unregister.");
3085 // If the subscription is no longer active, just return, since the callback
3086 // will already have been removed internally.
3087 } finally {
3088 Binder.restoreCallingIdentity(token);
3089 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003090 }
3091
3092 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003093 public boolean isCapable(int subId, int capability, int regTech) {
3094 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003095 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3096 final long token = Binder.clearCallingIdentity();
3097 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003098 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003099 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003100 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003101 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3102 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003103 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003104 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3105 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003106 } finally {
3107 Binder.restoreCallingIdentity(token);
3108 }
3109 }
3110
3111 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003112 public boolean isAvailable(int subId, int capability, int regTech) {
3113 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003114 final long token = Binder.clearCallingIdentity();
3115 try {
3116 Phone phone = getPhone(subId);
3117 if (phone == null) return false;
3118 return phone.isImsCapabilityAvailable(capability, regTech);
3119 } finally {
3120 Binder.restoreCallingIdentity(token);
3121 }
3122 }
3123
Brad Ebinger77b832e2019-10-17 17:03:22 -07003124 /**
3125 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3126 * subscription.
3127 * @param subId The subscription to use to check the configuration.
3128 * @param callback The callback that will be used to send the result.
3129 * @param capability The MmTelFeature capability that will be used to send the result.
3130 * @param transportType The transport type of the MmTelFeature capability.
3131 */
3132 @Override
3133 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3134 int transportType) {
3135 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3136 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3137 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3138 "IMS not available on device.");
3139 }
3140 final long token = Binder.clearCallingIdentity();
3141 try {
3142 int slotId = getSlotIndex(subId);
3143 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3144 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3145 + subId + "'");
3146 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3147 }
3148 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3149 transportType, aBoolean -> {
3150 try {
3151 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3152 } catch (RemoteException e) {
3153 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3154 + "running. Ignore");
3155 }
3156 });
3157 } finally {
3158 Binder.restoreCallingIdentity(token);
3159 }
3160 }
3161
Brad Ebinger35c841c2018-10-01 10:40:55 -07003162 @Override
3163 public boolean isAdvancedCallingSettingEnabled(int subId) {
3164 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3165 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3166 final long token = Binder.clearCallingIdentity();
3167 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003168 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003169 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003170 } catch (ImsException e) {
3171 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003172 } finally {
3173 Binder.restoreCallingIdentity(token);
3174 }
3175 }
3176
3177 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003178 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003180 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003181 final long identity = Binder.clearCallingIdentity();
3182 try {
3183 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003184 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003185 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003186 } catch (ImsException e) {
3187 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003188 } finally {
3189 Binder.restoreCallingIdentity(identity);
3190 }
3191 }
3192
3193 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003194 public boolean isVtSettingEnabled(int subId) {
3195 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003196 final long identity = Binder.clearCallingIdentity();
3197 try {
3198 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003199 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3200 } catch (ImsException e) {
3201 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003202 } finally {
3203 Binder.restoreCallingIdentity(identity);
3204 }
3205 }
3206
3207 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003208 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003210 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003211 final long identity = Binder.clearCallingIdentity();
3212 try {
3213 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003214 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003215 } catch (ImsException e) {
3216 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003217 } finally {
3218 Binder.restoreCallingIdentity(identity);
3219 }
3220 }
3221
3222 @Override
3223 public boolean isVoWiFiSettingEnabled(int subId) {
3224 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3225 final long identity = Binder.clearCallingIdentity();
3226 try {
3227 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003228 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003229 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003230 } catch (ImsException e) {
3231 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003232 } finally {
3233 Binder.restoreCallingIdentity(identity);
3234 }
3235 }
3236
3237 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003238 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003240 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003244 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003245 } catch (ImsException e) {
3246 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003247 } finally {
3248 Binder.restoreCallingIdentity(identity);
3249 }
3250 }
3251
3252 @Override
3253 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3254 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3255 final long identity = Binder.clearCallingIdentity();
3256 try {
3257 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003258 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003259 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003260 } catch (ImsException e) {
3261 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003262 } finally {
3263 Binder.restoreCallingIdentity(identity);
3264 }
3265 }
3266
3267 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003268 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003270 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003271 final long identity = Binder.clearCallingIdentity();
3272 try {
3273 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003274 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003275 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003276 } catch (ImsException e) {
3277 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 } finally {
3279 Binder.restoreCallingIdentity(identity);
3280 }
3281 }
3282
3283 @Override
3284 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3286 "setVoWiFiNonPersistent");
3287 final long identity = Binder.clearCallingIdentity();
3288 try {
3289 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003290 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003291 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003292 } catch (ImsException e) {
3293 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003294 } finally {
3295 Binder.restoreCallingIdentity(identity);
3296 }
3297 }
3298
3299 @Override
3300 public int getVoWiFiModeSetting(int subId) {
3301 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3302 final long identity = Binder.clearCallingIdentity();
3303 try {
3304 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003305 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003306 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003307 } catch (ImsException e) {
3308 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003309 } finally {
3310 Binder.restoreCallingIdentity(identity);
3311 }
3312 }
3313
3314 @Override
3315 public void setVoWiFiModeSetting(int subId, int mode) {
3316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3317 "setVoWiFiModeSetting");
3318 final long identity = Binder.clearCallingIdentity();
3319 try {
3320 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003321 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003322 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003323 } catch (ImsException e) {
3324 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003325 } finally {
3326 Binder.restoreCallingIdentity(identity);
3327 }
3328 }
3329
3330 @Override
3331 public int getVoWiFiRoamingModeSetting(int subId) {
3332 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3333 final long identity = Binder.clearCallingIdentity();
3334 try {
3335 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003336 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003337 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003338 } catch (ImsException e) {
3339 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
3343 }
3344
3345 @Override
3346 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3348 "setVoWiFiRoamingModeSetting");
3349 final long identity = Binder.clearCallingIdentity();
3350 try {
3351 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003352 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003353 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003354 } catch (ImsException e) {
3355 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003356 } finally {
3357 Binder.restoreCallingIdentity(identity);
3358 }
3359 }
3360
3361 @Override
3362 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3364 "setRttCapabilityEnabled");
3365 final long identity = Binder.clearCallingIdentity();
3366 try {
3367 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003368 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3369 } catch (ImsException e) {
3370 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003371 } finally {
3372 Binder.restoreCallingIdentity(identity);
3373 }
3374 }
3375
3376 @Override
3377 public boolean isTtyOverVolteEnabled(int subId) {
3378 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003382 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003384 } catch (ImsException e) {
3385 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003386 } finally {
3387 Binder.restoreCallingIdentity(identity);
3388 }
3389 }
3390
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003391 @Override
3392 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3393 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3394 final long identity = Binder.clearCallingIdentity();
3395 try {
3396 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003397 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003398 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003399 } catch (ImsException e) {
3400 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003401 } finally {
3402 Binder.restoreCallingIdentity(identity);
3403 }
3404 }
3405
3406 @Override
3407 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3408 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3409 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003410 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3411 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3412 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003413 try {
3414 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003415 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003416 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003417 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003418 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3419 + "is inactive, ignoring unregister.");
3420 // If the subscription is no longer active, just return, since the callback will already
3421 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
3425 }
3426
3427 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003428 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3429 boolean isProvisioned) {
3430 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3431 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3432 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3433 }
3434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3435 "setProvisioningStatusForCapability");
3436 final long identity = Binder.clearCallingIdentity();
3437 try {
3438 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3439 Phone phone = getPhone(subId);
3440 if (phone == null) {
3441 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3442 + subId);
3443 return;
3444 }
3445 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3446 return;
3447 }
3448
3449 // this capability requires provisioning, route to the correct API.
3450 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3451 switch (capability) {
3452 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3453 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3454 ims.setVolteProvisioned(isProvisioned);
3455 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3456 ims.setWfcProvisioned(isProvisioned);
3457 }
3458 break;
3459 }
3460 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3461 // There is currently no difference in VT provisioning type.
3462 ims.setVtProvisioned(isProvisioned);
3463 break;
3464 }
3465 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3466 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3467 // change the capability of the feature instead if needed.
3468 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3469 == isProvisioned) {
3470 // No change in provisioning.
3471 return;
3472 }
3473 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3474 try {
3475 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003476 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003477 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3478 + ", Exception" + e.getMessage());
3479 }
3480 break;
3481 }
3482 default: {
3483 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3484 + capability + "', which does not require provisioning.");
3485 }
3486 }
3487
3488 } finally {
3489 Binder.restoreCallingIdentity(identity);
3490 }
3491 }
3492
3493 @Override
3494 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3495 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3496 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3497 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3498 }
3499 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3500 final long identity = Binder.clearCallingIdentity();
3501 try {
3502 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3503 Phone phone = getPhone(subId);
3504 if (phone == null) {
3505 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3506 + subId);
3507 // We will fail with "true" as the provisioning status because this is the default
3508 // if we do not require provisioning.
3509 return true;
3510 }
3511
3512 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3513 return true;
3514 }
3515
3516 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3517 switch (capability) {
3518 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3519 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3520 return ims.isVolteProvisionedOnDevice();
3521 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3522 return ims.isWfcProvisionedOnDevice();
3523 }
3524 // This should never happen, since we are checking tech above to make sure it
3525 // is either LTE or IWLAN.
3526 throw new IllegalArgumentException("Invalid radio technology for voice "
3527 + "capability.");
3528 }
3529 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3530 // There is currently no difference in VT provisioning type.
3531 return ims.isVtProvisionedOnDevice();
3532 }
3533 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3534 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3535 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3536 }
3537 default: {
3538 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3539 + capability + "', which does not require provisioning.");
3540 }
3541 }
3542
3543 } finally {
3544 Binder.restoreCallingIdentity(identity);
3545 }
3546 }
3547
3548 @Override
3549 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3550 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3551 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3552 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3553 }
3554 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3555 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3556 return (provisionedBits & capability) > 0;
3557 }
3558
3559 @Override
3560 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3561 boolean isProvisioned) {
3562 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3563 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3564 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3565 }
3566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3567 "setProvisioningStatusForCapability");
3568 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3569 // If the current provisioning status for capability already matches isProvisioned,
3570 // do nothing.
3571 if (((provisionedBits & capability) > 0) == isProvisioned) {
3572 return;
3573 }
3574 if (isProvisioned) {
3575 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3576 } else {
3577 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3578 }
3579 }
3580
3581 /**
3582 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3583 * technology. The bitfield should mirror the bitfield defined by
3584 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3585 */
3586 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3587 String key = getMmTelProvisioningKey(subId, tech);
3588 // Default is no capabilities are provisioned.
3589 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3590 }
3591
3592 /**
3593 * Sets the MmTel capability provisioning bitfield (defined by
3594 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3595 * technology specified.
3596 *
3597 * Note: This is a synchronous command and should not be called on UI thread.
3598 */
3599 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3600 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3601 String key = getMmTelProvisioningKey(subId, tech);
3602 editor.putInt(key, newField);
3603 editor.commit();
3604 }
3605
3606 private static String getMmTelProvisioningKey(int subId, int tech) {
3607 // resulting key is provision_ims_mmtel_{subId}_{tech}
3608 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3609 }
3610
3611 /**
3612 * Query CarrierConfig to see if the specified capability requires provisioning for the
3613 * carrier associated with the subscription id.
3614 */
3615 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3616 int capability) {
3617 CarrierConfigManager configManager = new CarrierConfigManager(context);
3618 PersistableBundle c = configManager.getConfigForSubId(subId);
3619 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003620 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003621 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3622 false);
3623 boolean requireVoiceVtProvisioning = c.getBoolean(
3624 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3625
3626 // First check to make sure that the capability requires provisioning.
3627 switch (capability) {
3628 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3629 // intentional fallthrough
3630 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3631 if (requireVoiceVtProvisioning) {
3632 // Voice and Video requires provisioning
3633 return true;
3634 }
3635 break;
3636 }
3637 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3638 if (requireUtProvisioning) {
3639 // UT requires provisioning
3640 return true;
3641 }
3642 break;
3643 }
3644 }
3645 return false;
3646 }
3647
3648 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003649 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003650 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3651 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3652 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003653 enforceReadPrivilegedPermission("getImsProvisioningInt");
3654 final long identity = Binder.clearCallingIdentity();
3655 try {
3656 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003657 int slotId = getSlotIndex(subId);
3658 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3659 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3660 + subId + "' for key:" + key);
3661 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3662 }
3663 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003664 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003665 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3666 + subId + "' for key:" + key);
3667 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
3671 }
3672
3673 @Override
3674 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003675 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3676 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3677 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003678 enforceReadPrivilegedPermission("getImsProvisioningString");
3679 final long identity = Binder.clearCallingIdentity();
3680 try {
3681 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003682 int slotId = getSlotIndex(subId);
3683 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3684 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3685 + subId + "' for key:" + key);
3686 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3687 }
3688 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003689 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003690 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3691 + subId + "' for key:" + key);
3692 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003693 } finally {
3694 Binder.restoreCallingIdentity(identity);
3695 }
3696 }
3697
3698 @Override
3699 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003700 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3701 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3702 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3704 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003705 final long identity = Binder.clearCallingIdentity();
3706 try {
3707 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003708 int slotId = getSlotIndex(subId);
3709 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3710 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3711 + subId + "' for key:" + key);
3712 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3713 }
3714 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003715 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003716 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3717 + "' for key:" + key);
3718 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003719 } finally {
3720 Binder.restoreCallingIdentity(identity);
3721 }
3722 }
3723
3724 @Override
3725 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003726 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3727 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3728 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3730 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003731 final long identity = Binder.clearCallingIdentity();
3732 try {
3733 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003734 int slotId = getSlotIndex(subId);
3735 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3736 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3737 + subId + "' for key:" + key);
3738 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3739 }
3740 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003741 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003742 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3743 + "' for key:" + key);
3744 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003745 } finally {
3746 Binder.restoreCallingIdentity(identity);
3747 }
3748 }
3749
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003750 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003751 int slotId = SubscriptionManager.getSlotIndex(subId);
3752 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003753 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3754 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003755 }
3756 return slotId;
3757 }
3758
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003759 private int getSlotIndex(int subId) {
3760 int slotId = SubscriptionManager.getSlotIndex(subId);
3761 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3762 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3763 }
3764 return slotId;
3765 }
3766
Wink Saville36469e72014-06-11 15:17:00 -07003767 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003768 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003769 */
3770 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003771 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003772 final int targetSdk = getTargetSdk(callingPackage);
3773 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3774 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3775 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003776 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3777 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003778 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3779 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003781 final long identity = Binder.clearCallingIdentity();
3782 try {
3783 final Phone phone = getPhone(subId);
3784 if (phone != null) {
3785 return phone.getServiceState().getDataNetworkType();
3786 } else {
3787 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3788 }
3789 } finally {
3790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003792 }
3793
3794 /**
3795 * Returns the data network type
3796 */
3797 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003798 public int getDataNetworkType(String callingPackage) {
3799 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003800 }
3801
3802 /**
3803 * Returns the data network type for a subId
3804 */
3805 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003806 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003808 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003809 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3810 }
3811
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812 final long identity = Binder.clearCallingIdentity();
3813 try {
3814 final Phone phone = getPhone(subId);
3815 if (phone != null) {
3816 return phone.getServiceState().getDataNetworkType();
3817 } else {
3818 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3819 }
3820 } finally {
3821 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003822 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003823 }
3824
3825 /**
Wink Saville36469e72014-06-11 15:17:00 -07003826 * Returns the Voice network type for a subId
3827 */
3828 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003829 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003830 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003831 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003832 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3833 }
3834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003835 final long identity = Binder.clearCallingIdentity();
3836 try {
3837 final Phone phone = getPhone(subId);
3838 if (phone != null) {
3839 return phone.getServiceState().getVoiceNetworkType();
3840 } else {
3841 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3842 }
3843 } finally {
3844 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003845 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003846 }
3847
3848 /**
3849 * @return true if a ICC card is present
3850 */
3851 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003852 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003853 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3854 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003855 }
3856
3857 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003858 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003859 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003860 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003861 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003862 final long identity = Binder.clearCallingIdentity();
3863 try {
3864 final Phone phone = PhoneFactory.getPhone(slotIndex);
3865 if (phone != null) {
3866 return phone.getIccCard().hasIccCard();
3867 } else {
3868 return false;
3869 }
3870 } finally {
3871 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003873 }
3874
3875 /**
3876 * Return if the current radio is LTE on CDMA. This
3877 * is a tri-state return value as for a period of time
3878 * the mode may be unknown.
3879 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003880 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003881 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003882 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003883 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003884 @Override
3885 public int getLteOnCdmaMode(String callingPackage) {
3886 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003887 }
3888
Sanket Padawe356d7632015-06-22 14:03:32 -07003889 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003890 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003892 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003893 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3894 }
3895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 final Phone phone = getPhone(subId);
3899 if (phone == null) {
3900 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3901 } else {
3902 return phone.getLteOnCdmaMode();
3903 }
3904 } finally {
3905 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003906 }
Wink Saville36469e72014-06-11 15:17:00 -07003907 }
3908
Wink Saville36469e72014-06-11 15:17:00 -07003909 /**
3910 * {@hide}
3911 * Returns Default subId, 0 in the case of single standby.
3912 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003913 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003914 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003915 }
3916
Shishir Agrawala9f32182016-04-12 12:00:16 -07003917 private int getSlotForDefaultSubscription() {
3918 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3919 }
3920
Wink Savilleb564aae2014-10-23 10:18:09 -07003921 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003922 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003923 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003924
Pengquan Menge92a50d2018-09-21 15:54:48 -07003925 private boolean isActiveSubscription(int subId) {
3926 return mSubscriptionController.isActiveSubId(subId);
3927 }
3928
Ihab Awadf2177b72013-11-25 13:33:23 -08003929 /**
3930 * @see android.telephony.TelephonyManager.WifiCallingChoices
3931 */
3932 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003933 final long identity = Binder.clearCallingIdentity();
3934 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003935 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003936 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3937 getWhenToMakeWifiCallsDefaultPreference());
3938 } finally {
3939 Binder.restoreCallingIdentity(identity);
3940 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003941 }
3942
3943 /**
3944 * @see android.telephony.TelephonyManager.WifiCallingChoices
3945 */
3946 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003947 final long identity = Binder.clearCallingIdentity();
3948 try {
3949 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003950 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003951 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3952 } finally {
3953 Binder.restoreCallingIdentity(identity);
3954 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003955 }
3956
Sailesh Nepald1e68152013-12-12 19:08:02 -08003957 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003958 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003959 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003960 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003961
Jordan Liu4c733742019-02-28 12:03:40 -08003962 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3963 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3964 if (phoneId == -1) {
3965 throw new IllegalArgumentException("Given slot index: " + slotIndex
3966 + " does not correspond to an active phone");
3967 }
3968 return PhoneFactory.getPhone(phoneId);
3969 }
3970
Shishir Agrawal566b7612013-10-28 14:41:00 -07003971 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003972 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3973 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3975 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003976 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003977 if (DBG) {
3978 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3979 }
3980 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3981 p2);
3982 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003983
Jordan Liu4c733742019-02-28 12:03:40 -08003984
3985 @Override
3986 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3987 int slotIndex, String callingPackage, String aid, int p2) {
3988 enforceModifyPermission();
3989 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3990 if (DBG) {
3991 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3992 }
3993 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3994 callingPackage, aid, p2);
3995 }
3996
3997 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3998 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003999 final long identity = Binder.clearCallingIdentity();
4000 try {
4001 if (TextUtils.equals(ISDR_AID, aid)) {
4002 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004003 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4004 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005 if (bestComponent == null
4006 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4007 loge("The calling package is not allowed to access ISD-R.");
4008 throw new SecurityException(
4009 "The calling package is not allowed to access ISD-R.");
4010 }
Derek Tan740e1672017-06-27 14:56:27 -07004011 }
Derek Tan740e1672017-06-27 14:56:27 -07004012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004014 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4015 null /* workSource */);
4016 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 return response;
4018 } finally {
4019 Binder.restoreCallingIdentity(identity);
4020 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004021 }
4022
4023 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004024 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4026 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004027 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4028 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4029 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004030
Jordan Liu4c733742019-02-28 12:03:40 -08004031 @Override
4032 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4033 enforceModifyPermission();
4034 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4035 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4036 channel);
4037 }
4038
4039 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004040 final long identity = Binder.clearCallingIdentity();
4041 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042 if (channel < 0) {
4043 return false;
4044 }
Jordan Liu4c733742019-02-28 12:03:40 -08004045 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4046 null /* workSource */);
4047 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048 return success;
4049 } finally {
4050 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004051 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004052 }
4053
4054 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004055 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004056 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4058 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004059 if (DBG) {
4060 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4061 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4062 + p3 + " data=" + data);
4063 }
4064 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4065 command, p1, p2, p3, data);
4066 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004067
Jordan Liu4c733742019-02-28 12:03:40 -08004068 @Override
4069 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4070 int command, int p1, int p2, int p3, String data) {
4071 enforceModifyPermission();
4072 if (DBG) {
4073 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4074 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4075 + p3 + " data=" + data);
4076 }
4077 return iccTransmitApduLogicalChannelWithPermission(
4078 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4079 data);
4080 }
4081
4082 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4083 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004084 final long identity = Binder.clearCallingIdentity();
4085 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004086 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087 return "";
4088 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004090 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004091 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4092 null /* workSource */);
4093 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095 // Append the returned status code to the end of the response payload.
4096 String s = Integer.toHexString(
4097 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4098 if (response.payload != null) {
4099 s = IccUtils.bytesToHexString(response.payload) + s;
4100 }
4101 return s;
4102 } finally {
4103 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004104 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004105 }
Jake Hambye994d462014-02-03 13:10:13 -08004106
Evan Charltonc66da362014-05-16 14:06:40 -07004107 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004108 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4109 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4111 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004113 if (DBG) {
4114 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4115 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4116 }
4117 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4118 cla, command, p1, p2, p3, data);
4119 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004120
Jordan Liu4c733742019-02-28 12:03:40 -08004121 @Override
4122 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4123 int command, int p1, int p2, int p3, String data) {
4124 enforceModifyPermission();
4125 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4126 if (DBG) {
4127 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4128 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4129 + " data=" + data);
4130 }
4131
4132 return iccTransmitApduBasicChannelWithPermission(
4133 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4134 p2, p3, data);
4135 }
4136
4137 // open APDU basic channel assuming the caller has sufficient permissions
4138 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4139 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004140 final long identity = Binder.clearCallingIdentity();
4141 try {
4142 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4143 && TextUtils.equals(ISDR_AID, data)) {
4144 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004145 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4146 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004147 if (bestComponent == null
4148 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4149 loge("The calling package is not allowed to select ISD-R.");
4150 throw new SecurityException(
4151 "The calling package is not allowed to select ISD-R.");
4152 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004153 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004155 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004156 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4157 null /* workSource */);
4158 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004159
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160 // Append the returned status code to the end of the response payload.
4161 String s = Integer.toHexString(
4162 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4163 if (response.payload != null) {
4164 s = IccUtils.bytesToHexString(response.payload) + s;
4165 }
4166 return s;
4167 } finally {
4168 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004169 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004170 }
4171
4172 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004173 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004174 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4176 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004178 final long identity = Binder.clearCallingIdentity();
4179 try {
4180 if (DBG) {
4181 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4182 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4183 }
4184
4185 IccIoResult response =
4186 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4187 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4188 subId);
4189
4190 if (DBG) {
4191 log("Exchange SIM_IO [R]" + response);
4192 }
4193
4194 byte[] result = null;
4195 int length = 2;
4196 if (response.payload != null) {
4197 length = 2 + response.payload.length;
4198 result = new byte[length];
4199 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4200 } else {
4201 result = new byte[length];
4202 }
4203
4204 result[length - 1] = (byte) response.sw2;
4205 result[length - 2] = (byte) response.sw1;
4206 return result;
4207 } finally {
4208 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004209 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004210 }
4211
Nathan Haroldb3014052017-01-25 15:57:32 -08004212 /**
4213 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4214 * on a particular subscription
4215 */
sqianb6e41952018-03-12 14:54:01 -07004216 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4218 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4219 return null;
4220 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004221
4222 final long identity = Binder.clearCallingIdentity();
4223 try {
4224 if (appType != TelephonyManager.APPTYPE_USIM
4225 && appType != TelephonyManager.APPTYPE_SIM) {
4226 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4227 return null;
4228 }
4229 Object response = sendRequest(
4230 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4231 if (response instanceof String[]) {
4232 return (String[]) response;
4233 }
yincheng zhaod698b842019-09-06 17:06:54 -07004234 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004235 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004236 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004237 } finally {
4238 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004239 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004240 }
4241
yincheng zhaod698b842019-09-06 17:06:54 -07004242 /**
4243 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4244 * subscription.
4245 *
4246 * @param subId the id of the subscription.
4247 * @param appType the uicc app type, must be USIM or SIM.
4248 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4249 * @param callingPackage the op Package name.
4250 * @return number of fplmns that is successfully written to the SIM.
4251 */
4252 public int setForbiddenPlmns(
4253 int subId, int appType, List<String> fplmns, String callingPackage) {
4254 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4255 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4256 if (DBG) logv("no permissions for setForbiddenplmns");
4257 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4258 }
4259 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4260 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4261 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4262 }
4263 if (fplmns == null) {
4264 throw new IllegalArgumentException("Fplmn List provided is null");
4265 }
4266 for (String fplmn : fplmns) {
4267 if (!CellIdentity.isValidPlmn(fplmn)) {
4268 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4269 }
4270 }
4271 final long identity = Binder.clearCallingIdentity();
4272 try {
4273 Object response = sendRequest(
4274 CMD_SET_FORBIDDEN_PLMNS,
4275 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4276 subId);
4277 return (int) response;
4278 } finally {
4279 Binder.restoreCallingIdentity(identity);
4280 }
4281 }
4282
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004283 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004284 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4286 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004288 final long identity = Binder.clearCallingIdentity();
4289 try {
4290 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4291 if (response.payload == null) {
4292 return "";
4293 }
Evan Charltonc66da362014-05-16 14:06:40 -07004294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004295 // Append the returned status code to the end of the response payload.
4296 String s = Integer.toHexString(
4297 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4298 s = IccUtils.bytesToHexString(response.payload) + s;
4299 return s;
4300 } finally {
4301 Binder.restoreCallingIdentity(identity);
4302 }
Evan Charltonc66da362014-05-16 14:06:40 -07004303 }
4304
Jake Hambye994d462014-02-03 13:10:13 -08004305 /**
4306 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4307 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4308 *
4309 * @param itemID the ID of the item to read
4310 * @return the NV item as a String, or null on error.
4311 */
4312 @Override
4313 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004314 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4316 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004317
4318 final long identity = Binder.clearCallingIdentity();
4319 try {
4320 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004321 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004322 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4323 return value;
4324 } finally {
4325 Binder.restoreCallingIdentity(identity);
4326 }
Jake Hambye994d462014-02-03 13:10:13 -08004327 }
4328
4329 /**
4330 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4331 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4332 *
4333 * @param itemID the ID of the item to read
4334 * @param itemValue the value to write, as a String
4335 * @return true on success; false on any failure
4336 */
4337 @Override
4338 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004339 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4341 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004342
4343 final long identity = Binder.clearCallingIdentity();
4344 try {
4345 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4346 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004347 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004348 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4349 return success;
4350 } finally {
4351 Binder.restoreCallingIdentity(identity);
4352 }
Jake Hambye994d462014-02-03 13:10:13 -08004353 }
4354
4355 /**
4356 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4357 * Used for device configuration by some CDMA operators.
4358 *
4359 * @param preferredRoamingList byte array containing the new PRL
4360 * @return true on success; false on any failure
4361 */
4362 @Override
4363 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4365 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366
4367 final long identity = Binder.clearCallingIdentity();
4368 try {
4369 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4370 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4371 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4372 return success;
4373 } finally {
4374 Binder.restoreCallingIdentity(identity);
4375 }
Jake Hambye994d462014-02-03 13:10:13 -08004376 }
4377
4378 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004379 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004380 * Used for device configuration by some CDMA operators.
4381 *
chen xu6dac5ab2018-10-26 17:39:23 -07004382 * @param slotIndex - device slot.
4383 *
Jake Hambye994d462014-02-03 13:10:13 -08004384 * @return true on success; false on any failure
4385 */
4386 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004387 public boolean resetModemConfig(int slotIndex) {
4388 Phone phone = PhoneFactory.getPhone(slotIndex);
4389 if (phone != null) {
4390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4391 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004392
chen xu6dac5ab2018-10-26 17:39:23 -07004393 final long identity = Binder.clearCallingIdentity();
4394 try {
4395 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4396 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4397 return success;
4398 } finally {
4399 Binder.restoreCallingIdentity(identity);
4400 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 }
chen xu6dac5ab2018-10-26 17:39:23 -07004402 return false;
4403 }
4404
4405 /**
4406 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4407 *
4408 * @param slotIndex - device slot.
4409 *
4410 * @return true on success; false on any failure
4411 */
4412 @Override
4413 public boolean rebootModem(int slotIndex) {
4414 Phone phone = PhoneFactory.getPhone(slotIndex);
4415 if (phone != null) {
4416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4417 mApp, phone.getSubId(), "rebootModem");
4418
4419 final long identity = Binder.clearCallingIdentity();
4420 try {
4421 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4422 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4423 return success;
4424 } finally {
4425 Binder.restoreCallingIdentity(identity);
4426 }
4427 }
4428 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004429 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004430
Svet Ganovb320e182015-04-16 12:30:10 -07004431 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004432 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004433 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004434 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004435 return new String[0];
4436 }
4437
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004438 final long identity = Binder.clearCallingIdentity();
4439 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004440 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441 } finally {
4442 Binder.restoreCallingIdentity(identity);
4443 }
Wink Saville36469e72014-06-11 15:17:00 -07004444 }
4445
Brad Ebinger51f743a2017-01-23 13:50:20 -08004446 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004447 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4448 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004449 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004450 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004451 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004452
4453 final long identity = Binder.clearCallingIdentity();
4454 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004455 ImsResolver resolver = PhoneFactory.getImsResolver();
4456 if (resolver == null) {
4457 // may happen if the device does not support IMS.
4458 return;
4459 }
4460 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004461 } finally {
4462 Binder.restoreCallingIdentity(identity);
4463 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004464 }
4465
4466 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004467 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4468 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004469 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004470 public void disableIms(int slotId) {
4471 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472
4473 final long identity = Binder.clearCallingIdentity();
4474 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004475 ImsResolver resolver = PhoneFactory.getImsResolver();
4476 if (resolver == null) {
4477 // may happen if the device does not support IMS.
4478 return;
4479 }
4480 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004484 }
4485
4486 /**
4487 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4488 * feature or {@link null} if the service is not available. If the feature is available, the
4489 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4490 */
4491 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004492 IImsServiceFeatureCallback callback) {
4493 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004494
4495 final long identity = Binder.clearCallingIdentity();
4496 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004497 ImsResolver resolver = PhoneFactory.getImsResolver();
4498 if (resolver == null) {
4499 // may happen if the device does not support IMS.
4500 return null;
4501 }
4502 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004506 }
4507
4508 /**
4509 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4510 * feature during emergency calling or {@link null} if the service is not available. If the
4511 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4512 * listener for feature updates.
4513 */
4514 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4515 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004516
4517 final long identity = Binder.clearCallingIdentity();
4518 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004519 ImsResolver resolver = PhoneFactory.getImsResolver();
4520 if (resolver == null) {
4521 // may happen if the device does not support IMS.
4522 return null;
4523 }
4524 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004525 } finally {
4526 Binder.restoreCallingIdentity(identity);
4527 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004528 }
4529
Brad Ebinger5f64b052017-12-14 14:26:15 -08004530 /**
4531 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004532 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004533 */
4534 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4535 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004536
4537 final long identity = Binder.clearCallingIdentity();
4538 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004539 ImsResolver resolver = PhoneFactory.getImsResolver();
4540 if (resolver == null) {
4541 // may happen if the device does not support IMS.
4542 return null;
4543 }
4544 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004545 } finally {
4546 Binder.restoreCallingIdentity(identity);
4547 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004548 }
4549
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004550 /**
4551 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004552 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004553 */
4554 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556
4557 final long identity = Binder.clearCallingIdentity();
4558 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004559 ImsResolver resolver = PhoneFactory.getImsResolver();
4560 if (resolver == null) {
4561 // may happen if the device does not support IMS.
4562 return null;
4563 }
4564 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004565 } finally {
4566 Binder.restoreCallingIdentity(identity);
4567 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004568 }
4569
Brad Ebinger884c07b2018-02-15 16:17:40 -08004570 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004571 * Sets the ImsService Package Name that Telephony will bind to.
4572 *
4573 * @param slotId the slot ID that the ImsService should bind for.
4574 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4575 * ImsService is the device default ImsService.
4576 * @param packageName The package name of the application that contains the ImsService to bind
4577 * to.
4578 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4579 * @hide
4580 */
4581 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004582 int[] subIds = SubscriptionManager.getSubId(slotId);
4583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4584 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4585 "setImsService");
4586
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004587 final long identity = Binder.clearCallingIdentity();
4588 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004589 ImsResolver resolver = PhoneFactory.getImsResolver();
4590 if (resolver == null) {
4591 // may happen if the device does not support IMS.
4592 return false;
4593 }
4594 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4595 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004596 } finally {
4597 Binder.restoreCallingIdentity(identity);
4598 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004599 }
4600
4601 /**
4602 * Return the ImsService configuration.
4603 *
4604 * @param slotId The slot that the ImsService is associated with.
4605 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4606 * the device default.
4607 * @return the package name of the ImsService configuration.
4608 */
4609 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004610 int[] subIds = SubscriptionManager.getSubId(slotId);
4611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4612 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4613 "getImsService");
4614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004615 final long identity = Binder.clearCallingIdentity();
4616 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004617 ImsResolver resolver = PhoneFactory.getImsResolver();
4618 if (resolver == null) {
4619 // may happen if the device does not support IMS.
4620 return "";
4621 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004622 // TODO: change API to query RCS separately.
4623 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4624 ImsFeature.FEATURE_MMTEL);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 } finally {
4626 Binder.restoreCallingIdentity(identity);
4627 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004628 }
4629
Brad Ebinger77b832e2019-10-17 17:03:22 -07004630 /**
4631 * Get the MmTelFeature state associated with the requested subscription id.
4632 * @param subId The subscription that the MmTelFeature is associated with.
4633 * @param callback A callback with an integer containing the
4634 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4635 */
4636 @Override
4637 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4638 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4639 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4640 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4641 "IMS not available on device.");
4642 }
4643 final long token = Binder.clearCallingIdentity();
4644 try {
4645 int slotId = getSlotIndex(subId);
4646 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4647 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4648 + subId + "'");
4649 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4650 }
4651 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4652 try {
4653 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4654 } catch (RemoteException e) {
4655 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4656 + "Ignore");
4657 }
4658 });
4659 } finally {
4660 Binder.restoreCallingIdentity(token);
4661 }
4662 }
4663
Wink Saville36469e72014-06-11 15:17:00 -07004664 public void setImsRegistrationState(boolean registered) {
4665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004666
4667 final long identity = Binder.clearCallingIdentity();
4668 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004669 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004670 } finally {
4671 Binder.restoreCallingIdentity(identity);
4672 }
Wink Saville36469e72014-06-11 15:17:00 -07004673 }
4674
4675 /**
Stuart Scott54788802015-03-30 13:18:01 -07004676 * Set the network selection mode to automatic.
4677 *
4678 */
4679 @Override
4680 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4682 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683
Pengquan Menge92a50d2018-09-21 15:54:48 -07004684 if (!isActiveSubscription(subId)) {
4685 return;
4686 }
4687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004688 final long identity = Binder.clearCallingIdentity();
4689 try {
4690 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4691 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4692 } finally {
4693 Binder.restoreCallingIdentity(identity);
4694 }
Stuart Scott54788802015-03-30 13:18:01 -07004695 }
4696
Pengquan Mengea84e042018-09-20 14:57:26 -07004697 /**
4698 * Ask the radio to connect to the input network and change selection mode to manual.
4699 *
4700 * @param subId the id of the subscription.
4701 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4702 * the operator to attach to.
4703 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4704 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4705 * normal network selection next time.
4706 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004707 */
4708 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004709 public boolean setNetworkSelectionModeManual(
4710 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4712 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004713
4714 if (!isActiveSubscription(subId)) {
4715 return false;
4716 }
4717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004718 final long identity = Binder.clearCallingIdentity();
4719 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004720 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004721 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004722 if (DBG) {
4723 log("setNetworkSelectionModeManual: subId: " + subId
4724 + " operator: " + operatorInfo);
4725 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004726 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4727 } finally {
4728 Binder.restoreCallingIdentity(identity);
4729 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004730 }
4731
4732 /**
4733 * Scans for available networks.
4734 */
4735 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004736 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4738 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004739 LocationAccessPolicy.LocationPermissionResult locationResult =
4740 LocationAccessPolicy.checkLocationPermission(mApp,
4741 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4742 .setCallingPackage(callingPackage)
4743 .setCallingPid(Binder.getCallingPid())
4744 .setCallingUid(Binder.getCallingUid())
4745 .setMethod("getCellNetworkScanResults")
4746 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4747 .build());
4748 switch (locationResult) {
4749 case DENIED_HARD:
4750 throw new SecurityException("Not allowed to access scan results -- location");
4751 case DENIED_SOFT:
4752 return null;
4753 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004754
Pengquan Menga1bb6272018-09-06 09:59:22 -07004755 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004756 try {
4757 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004758 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004760 } finally {
4761 Binder.restoreCallingIdentity(identity);
4762 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004763 }
4764
4765 /**
yinxub1bed742017-04-17 11:45:04 -07004766 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004767 *
yinxub1bed742017-04-17 11:45:04 -07004768 * @param subId id of the subscription
4769 * @param request contains the radio access networks with bands/channels to scan
4770 * @param messenger callback messenger for scan results or errors
4771 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004772 * @return the id of the requested scan which can be used to stop the scan.
4773 */
4774 @Override
4775 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004776 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4778 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004779 LocationAccessPolicy.LocationPermissionResult locationResult =
4780 LocationAccessPolicy.checkLocationPermission(mApp,
4781 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4782 .setCallingPackage(callingPackage)
4783 .setCallingPid(Binder.getCallingPid())
4784 .setCallingUid(Binder.getCallingUid())
4785 .setMethod("requestNetworkScan")
4786 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4787 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004788 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004789 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004790 if (e != null) {
4791 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4792 throw e;
4793 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004794 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004795 return TelephonyScanManager.INVALID_SCAN_ID;
4796 }
4797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798 }
Hall Liu912dfd32019-04-25 14:02:26 -07004799 int callingUid = Binder.getCallingUid();
4800 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004801 final long identity = Binder.clearCallingIdentity();
4802 try {
4803 return mNetworkScanRequestTracker.startNetworkScan(
4804 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004805 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004806 } finally {
4807 Binder.restoreCallingIdentity(identity);
4808 }
yinxu504e1392017-04-12 16:03:22 -07004809 }
4810
Hall Liub2ac8ef2019-02-28 15:56:23 -08004811 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004812 NetworkScanRequest request, int subId) {
4813 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4814 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4815 boolean hasNetworkScanPermission =
4816 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4817 == PERMISSION_GRANTED;
4818
4819 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4820 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4821 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004822 }
4823
4824 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4825 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004826 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4827 return new SecurityException("Specific channels must not be"
4828 + " scanned without location access.");
4829 }
4830 }
4831 }
4832
Hall Liub2ac8ef2019-02-28 15:56:23 -08004833 return null;
4834 }
4835
yinxu504e1392017-04-12 16:03:22 -07004836 /**
4837 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004838 *
4839 * @param subId id of the subscription
4840 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004841 */
4842 @Override
4843 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4845 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004846
Hall Liu912dfd32019-04-25 14:02:26 -07004847 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004848 final long identity = Binder.clearCallingIdentity();
4849 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004850 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004851 } finally {
4852 Binder.restoreCallingIdentity(identity);
4853 }
yinxu504e1392017-04-12 16:03:22 -07004854 }
4855
4856 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004857 * Get the calculated preferred network type.
4858 * Used for debugging incorrect network type.
4859 *
4860 * @return the preferred network type, defined in RILConstants.java.
4861 */
4862 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004863 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004864 final Phone defaultPhone = getDefaultPhone();
4865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4866 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004867 return RILConstants.PREFERRED_NETWORK_MODE;
4868 }
4869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004870 final long identity = Binder.clearCallingIdentity();
4871 try {
4872 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004873 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 } finally {
4875 Binder.restoreCallingIdentity(identity);
4876 }
Junda Liu84d15a22014-07-02 11:21:04 -07004877 }
4878
4879 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004880 * Get the preferred network type.
4881 * Used for device configuration by some CDMA operators.
4882 *
4883 * @return the preferred network type, defined in RILConstants.java.
4884 */
4885 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004886 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004887 TelephonyPermissions
4888 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4889 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890
4891 final long identity = Binder.clearCallingIdentity();
4892 try {
4893 if (DBG) log("getPreferredNetworkType");
4894 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4895 int networkType = (result != null ? result[0] : -1);
4896 if (DBG) log("getPreferredNetworkType: " + networkType);
4897 return networkType;
4898 } finally {
4899 Binder.restoreCallingIdentity(identity);
4900 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004901 }
4902
4903 /**
4904 * Set the preferred network type.
4905 * Used for device configuration by some CDMA operators.
4906 *
4907 * @param networkType the preferred network type, defined in RILConstants.java.
4908 * @return true on success; false on any failure.
4909 */
4910 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004911 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4913 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914
4915 final long identity = Binder.clearCallingIdentity();
4916 try {
4917 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4918 Boolean success = (Boolean) sendRequest(
4919 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4920 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4921 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004922 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4924 }
4925 return success;
4926 } finally {
4927 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004928 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004929 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004930
4931 /**
Miaoa84611c2019-03-15 09:21:10 +08004932 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004933 *
Miaoa84611c2019-03-15 09:21:10 +08004934 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004935 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004936 * @hide
4937 */
4938 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004939 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004940 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004941 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004942 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943 try {
Miaoa84611c2019-03-15 09:21:10 +08004944 if (phone != null) {
4945 return phone.hasMatchedTetherApnSetting();
4946 } else {
4947 return false;
4948 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 } finally {
4950 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004951 }
Junda Liu475951f2014-11-07 16:45:03 -08004952 }
4953
4954 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004955 * Set mobile data enabled
4956 * Used by the user through settings etc to turn on/off mobile data
4957 *
4958 * @param enable {@code true} turn turn data on, else {@code false}
4959 */
4960 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004961 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4963 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964
4965 final long identity = Binder.clearCallingIdentity();
4966 try {
4967 int phoneId = mSubscriptionController.getPhoneId(subId);
4968 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4969 Phone phone = PhoneFactory.getPhone(phoneId);
4970 if (phone != null) {
4971 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004972 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004974 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975 }
4976 } finally {
4977 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004978 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004979 }
4980
4981 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004982 * Get the user enabled state of Mobile Data.
4983 *
4984 * TODO: remove and use isUserDataEnabled.
4985 * This can't be removed now because some vendor codes
4986 * calls through ITelephony directly while they should
4987 * use TelephonyManager.
4988 *
4989 * @return true on enabled
4990 */
4991 @Override
4992 public boolean getDataEnabled(int subId) {
4993 return isUserDataEnabled(subId);
4994 }
4995
4996 /**
4997 * Get whether mobile data is enabled per user setting.
4998 *
4999 * There are other factors deciding whether mobile data is actually enabled, but they are
5000 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005001 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005002 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005003 *
5004 * @return {@code true} if data is enabled else {@code false}
5005 */
5006 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005007 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005008 try {
5009 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5010 null);
5011 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5013 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005014 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005015
5016 final long identity = Binder.clearCallingIdentity();
5017 try {
5018 int phoneId = mSubscriptionController.getPhoneId(subId);
5019 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5020 Phone phone = PhoneFactory.getPhone(phoneId);
5021 if (phone != null) {
5022 boolean retVal = phone.isUserDataEnabled();
5023 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5024 return retVal;
5025 } else {
5026 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5027 return false;
5028 }
5029 } finally {
5030 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005031 }
5032 }
5033
5034 /**
5035 * Get whether mobile data is enabled.
5036 *
5037 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5038 * whether mobile data is actually enabled.
5039 *
5040 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5041 *
5042 * @return {@code true} if data is enabled else {@code false}
5043 */
5044 @Override
5045 public boolean isDataEnabled(int subId) {
5046 try {
5047 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5048 null);
5049 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5051 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005053
5054 final long identity = Binder.clearCallingIdentity();
5055 try {
5056 int phoneId = mSubscriptionController.getPhoneId(subId);
5057 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5058 Phone phone = PhoneFactory.getPhone(phoneId);
5059 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005060 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005061 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5062 return retVal;
5063 } else {
5064 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5065 return false;
5066 }
5067 } finally {
5068 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005069 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005070 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005071
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005072 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5073 Phone phone) {
5074 //load access rules from carrier configs, and check those as well: b/139133814
5075 SubscriptionController subController = SubscriptionController.getInstance();
5076 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5077 || subController == null) return privilegeFromSim;
5078
5079 int uid = Binder.getCallingUid();
5080 PackageManager pkgMgr = phone.getContext().getPackageManager();
5081 String[] packages = pkgMgr.getPackagesForUid(uid);
5082
5083 final long identity = Binder.clearCallingIdentity();
5084 try {
5085 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5086 SubscriptionManager subManager = (SubscriptionManager)
5087 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5088 for (String pkg : packages) {
5089 if (subManager.canManageSubscription(subInfo, pkg)) {
5090 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5091 }
5092 }
5093 return privilegeFromSim;
5094 } finally {
5095 Binder.restoreCallingIdentity(identity);
5096 }
5097 }
5098
5099 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5100 String pkgName) {
5101 //load access rules from carrier configs, and check those as well: b/139133814
5102 SubscriptionController subController = SubscriptionController.getInstance();
5103 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5104 || subController == null) return privilegeFromSim;
5105
5106 final long identity = Binder.clearCallingIdentity();
5107 try {
5108 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5109 SubscriptionManager subManager = (SubscriptionManager)
5110 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5111 return subManager.canManageSubscription(subInfo, pkgName)
5112 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5113 } finally {
5114 Binder.restoreCallingIdentity(identity);
5115 }
5116 }
5117
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005118 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005119 public int getCarrierPrivilegeStatus(int subId) {
5120 final Phone phone = getPhone(subId);
5121 if (phone == null) {
5122 loge("getCarrierPrivilegeStatus: Invalid subId");
5123 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5124 }
5125 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005126 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005127 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005128 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5129 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005130
5131 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5132 card.getCarrierPrivilegeStatusForCurrentTransaction(
5133 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005134 }
Junda Liu29340342014-07-10 15:23:27 -07005135
5136 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005137 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5138 final Phone phone = getPhone(subId);
5139 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005140 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005141 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5142 }
5143 UiccProfile profile =
5144 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5145 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005146 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005147 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5148 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005149 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5150 profile.getCarrierPrivilegeStatusForUid(
5151 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005152 }
5153
5154 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005155 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5156 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005157 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005158 }
5159
5160 int phoneId = SubscriptionManager.getPhoneId(subId);
5161 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005162 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005163 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005164 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5165 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005166 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5167 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5168 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005169 }
5170
5171 @Override
5172 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005173 if (TextUtils.isEmpty(pkgName))
5174 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005175 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5176 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5177 UiccCard card = UiccController.getInstance().getUiccCard(i);
5178 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005179 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005180 continue;
5181 }
5182
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005183 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5184 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5185 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005186 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5187 break;
5188 }
5189 }
5190
5191 return result;
Junda Liu29340342014-07-10 15:23:27 -07005192 }
Derek Tan89e89d42014-07-08 17:00:10 -07005193
5194 @Override
Junda Liue64de782015-04-16 17:19:16 -07005195 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5196 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5197 loge("phoneId " + phoneId + " is not valid.");
5198 return null;
5199 }
5200 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005201 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005202 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005203 return null ;
5204 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005205 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005206 }
5207
Amith Yamasani6e118872016-02-19 12:53:51 -08005208 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005209 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005210 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005211 List<String> privilegedPackages = new ArrayList<>();
5212 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005213 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5214 // has UICC in that slot.
5215 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005216 if (card.hasCarrierPrivilegeRules()) {
5217 if (packages == null) {
5218 // Only check packages in user 0 for now
5219 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005220 PackageManager.MATCH_DISABLED_COMPONENTS
5221 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005222 | PackageManager.GET_SIGNING_CERTIFICATES,
5223 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005224 }
5225 for (int p = packages.size() - 1; p >= 0; p--) {
5226 PackageInfo pkgInfo = packages.get(p);
5227 if (pkgInfo != null && pkgInfo.packageName != null
5228 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005229 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005230 privilegedPackages.add(pkgInfo.packageName);
5231 }
5232 }
5233 }
5234 }
5235 return privilegedPackages;
5236 }
5237
chen xuf7e9fe82019-05-09 19:31:02 -07005238 @Override
5239 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005240 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5241
5242 final long identity = Binder.clearCallingIdentity();
5243
chen xuf7e9fe82019-05-09 19:31:02 -07005244 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005245 try {
5246 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5247 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5248 }
5249 } finally {
5250 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005251 }
5252 return privilegedPackages;
5253 }
5254
Wink Savilleb564aae2014-10-23 10:18:09 -07005255 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005256 final Phone phone = getPhone(subId);
5257 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005258 if (card == null) {
5259 loge("getIccId: No UICC");
5260 return null;
5261 }
5262 String iccId = card.getIccId();
5263 if (TextUtils.isEmpty(iccId)) {
5264 loge("getIccId: ICC ID is null or empty.");
5265 return null;
5266 }
5267 return iccId;
5268 }
5269
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005270 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005271 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5272 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005273 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5274 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 final long identity = Binder.clearCallingIdentity();
5277 try {
5278 final String iccId = getIccId(subId);
5279 final Phone phone = getPhone(subId);
5280 if (phone == null) {
5281 return false;
5282 }
5283 final String subscriberId = phone.getSubscriberId();
5284
5285 if (DBG_MERGE) {
5286 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5287 + subscriberId + " to " + number);
5288 }
5289
5290 if (TextUtils.isEmpty(iccId)) {
5291 return false;
5292 }
5293
5294 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5295
5296 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5297 if (alphaTag == null) {
5298 editor.remove(alphaTagPrefKey);
5299 } else {
5300 editor.putString(alphaTagPrefKey, alphaTag);
5301 }
5302
5303 // Record both the line number and IMSI for this ICCID, since we need to
5304 // track all merged IMSIs based on line number
5305 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5306 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5307 if (number == null) {
5308 editor.remove(numberPrefKey);
5309 editor.remove(subscriberPrefKey);
5310 } else {
5311 editor.putString(numberPrefKey, number);
5312 editor.putString(subscriberPrefKey, subscriberId);
5313 }
5314
5315 editor.commit();
5316 return true;
5317 } finally {
5318 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005319 }
Derek Tan7226c842014-07-02 17:42:23 -07005320 }
5321
5322 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005323 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005324 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005326 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005327 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005328 return null;
5329 }
Derek Tan97ebb422014-09-05 16:55:38 -07005330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331 final long identity = Binder.clearCallingIdentity();
5332 try {
5333 String iccId = getIccId(subId);
5334 if (iccId != null) {
5335 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5336 if (DBG_MERGE) {
5337 log("getLine1NumberForDisplay returning "
5338 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5339 }
5340 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005341 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005342 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5343 return null;
5344 } finally {
5345 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005346 }
Derek Tan7226c842014-07-02 17:42:23 -07005347 }
5348
5349 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005350 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005352 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005353 return null;
5354 }
Derek Tan97ebb422014-09-05 16:55:38 -07005355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 final long identity = Binder.clearCallingIdentity();
5357 try {
5358 String iccId = getIccId(subId);
5359 if (iccId != null) {
5360 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5361 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5362 }
5363 return null;
5364 } finally {
5365 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005366 }
Derek Tan7226c842014-07-02 17:42:23 -07005367 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005368
5369 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005370 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005371 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5372 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005373 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005374 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5375 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005376 return null;
5377 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005378
Jordan Liub49b04b2019-05-06 14:45:15 -07005379 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5380 // the process, where TelephonyManager was instantiated.
5381 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005382 final long identity = Binder.clearCallingIdentity();
5383 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005384 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005385 final TelephonyManager tele = TelephonyManager.from(context);
5386 final SubscriptionManager sub = SubscriptionManager.from(context);
5387
5388 // Figure out what subscribers are currently active
5389 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005390
Jordan Liub49b04b2019-05-06 14:45:15 -07005391 // Only consider subs which match the current subId
5392 // This logic can be simplified. See b/131189269 for progress.
5393 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005394 activeSubscriberIds.add(tele.getSubscriberId(subId));
5395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396
5397 // First pass, find a number override for an active subscriber
5398 String mergeNumber = null;
5399 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5400 for (String key : prefs.keySet()) {
5401 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5402 final String subscriberId = (String) prefs.get(key);
5403 if (activeSubscriberIds.contains(subscriberId)) {
5404 final String iccId = key.substring(
5405 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5406 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5407 mergeNumber = (String) prefs.get(numberKey);
5408 if (DBG_MERGE) {
5409 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5410 + " for active subscriber " + subscriberId);
5411 }
5412 if (!TextUtils.isEmpty(mergeNumber)) {
5413 break;
5414 }
5415 }
5416 }
5417 }
5418
5419 // Shortcut when no active merged subscribers
5420 if (TextUtils.isEmpty(mergeNumber)) {
5421 return null;
5422 }
5423
5424 // Second pass, find all subscribers under that line override
5425 final ArraySet<String> result = new ArraySet<>();
5426 for (String key : prefs.keySet()) {
5427 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5428 final String number = (String) prefs.get(key);
5429 if (mergeNumber.equals(number)) {
5430 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5431 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5432 final String subscriberId = (String) prefs.get(subscriberKey);
5433 if (!TextUtils.isEmpty(subscriberId)) {
5434 result.add(subscriberId);
5435 }
5436 }
5437 }
5438 }
5439
5440 final String[] resultArray = result.toArray(new String[result.size()]);
5441 Arrays.sort(resultArray);
5442 if (DBG_MERGE) {
5443 Slog.d(LOG_TAG,
5444 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5445 }
5446 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005447 } finally {
5448 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005449 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005450 }
5451
5452 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005453 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5454 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5455
5456 final long identity = Binder.clearCallingIdentity();
5457 try {
5458 final TelephonyManager telephonyManager = mApp.getSystemService(
5459 TelephonyManager.class);
5460 String subscriberId = telephonyManager.getSubscriberId(subId);
5461 if (subscriberId == null) {
5462 if (DBG) {
5463 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5464 + subId);
5465 }
5466 return null;
5467 }
5468
5469 final SubscriptionInfo info = SubscriptionController.getInstance()
5470 .getSubscriptionInfo(subId);
5471 final ParcelUuid groupUuid = info.getGroupUuid();
5472 // If it doesn't belong to any group, return just subscriberId of itself.
5473 if (groupUuid == null) {
5474 return new String[]{subscriberId};
5475 }
5476
5477 // Get all subscriberIds from the group.
5478 final List<String> mergedSubscriberIds = new ArrayList<>();
5479 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5480 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5481 for (SubscriptionInfo subInfo : groupInfos) {
5482 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5483 if (subscriberId != null) {
5484 mergedSubscriberIds.add(subscriberId);
5485 }
5486 }
5487
5488 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5489 } finally {
5490 Binder.restoreCallingIdentity(identity);
5491
5492 }
5493 }
5494
5495 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005496 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005497 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5498 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499
5500 final long identity = Binder.clearCallingIdentity();
5501 try {
5502 final Phone phone = getPhone(subId);
5503 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5504 } finally {
5505 Binder.restoreCallingIdentity(identity);
5506 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005507 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005508
5509 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005510 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005511 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5512 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005513 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514
5515 final long identity = Binder.clearCallingIdentity();
5516 try {
5517 final Phone phone = getPhone(subId);
5518 if (phone == null) {
5519 return false;
5520 }
5521 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5522 cdmaNonRoamingList);
5523 } finally {
5524 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005525 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005526 }
5527
5528 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005529 @Deprecated
5530 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5531 enforceModifyPermission();
5532
5533 int returnValue = 0;
5534 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005535 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005536 if(result.exception == null) {
5537 if (result.result != null) {
5538 byte[] responseData = (byte[])(result.result);
5539 if(responseData.length > oemResp.length) {
5540 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5541 responseData.length + "bytes. Buffer Size is " +
5542 oemResp.length + "bytes.");
5543 }
5544 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5545 returnValue = responseData.length;
5546 }
5547 } else {
5548 CommandException ex = (CommandException) result.exception;
5549 returnValue = ex.getCommandError().ordinal();
5550 if(returnValue > 0) returnValue *= -1;
5551 }
5552 } catch (RuntimeException e) {
5553 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5554 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5555 if(returnValue > 0) returnValue *= -1;
5556 }
5557
5558 return returnValue;
5559 }
5560
5561 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005562 public void setRadioCapability(RadioAccessFamily[] rafs) {
5563 try {
5564 ProxyController.getInstance().setRadioCapability(rafs);
5565 } catch (RuntimeException e) {
5566 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5567 }
5568 }
5569
5570 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005571 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005572 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005573 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005574 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005575 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005576 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577 final long identity = Binder.clearCallingIdentity();
5578 try {
chen xub97461a2018-10-26 14:17:57 -07005579 TelephonyPermissions
5580 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5581 mApp, phone.getSubId(), "getRadioAccessFamily");
5582 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 } finally {
5584 Binder.restoreCallingIdentity(identity);
5585 }
chen xub97461a2018-10-26 14:17:57 -07005586 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005587 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005588
5589 @Override
5590 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005591 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005592 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593
5594 final long identity = Binder.clearCallingIdentity();
5595 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005596 ImsManager.getInstance(defaultPhone.getContext(),
5597 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598 } finally {
5599 Binder.restoreCallingIdentity(identity);
5600 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005601 }
5602
5603 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005604 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005605 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005606 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005607 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005608 return false;
5609 }
Svet Ganovb320e182015-04-16 12:30:10 -07005610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 final long identity = Binder.clearCallingIdentity();
5612 try {
5613 // Check the user preference and the system-level IMS setting. Even if the user has
5614 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5615 // In the long run, we may instead need to check if there exists a connection service
5616 // which can support video calling.
5617 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005618 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 return imsManager.isVtEnabledByPlatform()
5620 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5621 && imsManager.isVtEnabledByUser();
5622 } finally {
5623 Binder.restoreCallingIdentity(identity);
5624 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005625 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005626
Andrew Leea1239f22015-03-02 17:44:07 -08005627 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5630 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5631 return false;
5632 }
5633
5634 final long identity = Binder.clearCallingIdentity();
5635 try {
5636 CarrierConfigManager configManager =
5637 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005638 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5640 } finally {
5641 Binder.restoreCallingIdentity(identity);
5642 }
Andrew Leea1239f22015-03-02 17:44:07 -08005643 }
5644
5645 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646 public boolean isWorldPhone(int subId, String callingPackage) {
5647 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5648 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5649 return false;
5650 }
5651
5652 final long identity = Binder.clearCallingIdentity();
5653 try {
5654 CarrierConfigManager configManager =
5655 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005656 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5658 } finally {
5659 Binder.restoreCallingIdentity(identity);
5660 }
Andrew Leea1239f22015-03-02 17:44:07 -08005661 }
5662
Andrew Lee9431b832015-03-09 18:46:45 -07005663 @Override
5664 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005665 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005666 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005667 }
5668
5669 @Override
5670 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 final long identity = Binder.clearCallingIdentity();
5672 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005673 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
Andrew Lee9431b832015-03-09 18:46:45 -07005677 }
5678
Hall Liuf6668912018-10-31 17:05:23 -07005679 /**
5680 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5681 * support for the feature and device firmware support.
5682 *
5683 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5684 */
5685 @Override
5686 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005688 final Phone phone = getPhone(subscriptionId);
5689 if (phone == null) {
5690 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5691 return false;
5692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005694 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5696 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005697 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 return isCarrierSupported && isDeviceSupported;
5699 } finally {
5700 Binder.restoreCallingIdentity(identity);
5701 }
Hall Liu98187582018-01-22 19:15:32 -08005702 }
5703
Hall Liuf6668912018-10-31 17:05:23 -07005704 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005705 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5706 * RTT setting, will return true if the device and carrier both support RTT.
5707 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005708 */
5709 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710 final long identity = Binder.clearCallingIdentity();
5711 try {
Hall Liu81eb08c2019-10-29 16:50:20 -07005712 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713 } finally {
5714 Binder.restoreCallingIdentity(identity);
5715 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005716 }
5717
Sanket Padawe7310cc72015-01-14 09:53:20 -08005718 /**
5719 * Returns the unique device ID of phone, for example, the IMEI for
5720 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5721 *
5722 * <p>Requires Permission:
5723 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5724 */
5725 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005726 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005727 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005728 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005729 return null;
5730 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005731 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005732 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5733 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005734 return null;
5735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736
5737 final long identity = Binder.clearCallingIdentity();
5738 try {
5739 return phone.getDeviceId();
5740 } finally {
5741 Binder.restoreCallingIdentity(identity);
5742 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005743 }
5744
Ping Sunc67b7c22016-03-02 19:16:45 +08005745 /**
5746 * {@hide}
5747 * Returns the IMS Registration Status on a particular subid
5748 *
5749 * @param subId
5750 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005751 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005752 Phone phone = getPhone(subId);
5753 if (phone != null) {
5754 return phone.isImsRegistered();
5755 } else {
5756 return false;
5757 }
5758 }
5759
Santos Cordon7a1885b2015-02-03 11:15:19 -08005760 @Override
5761 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 final long identity = Binder.clearCallingIdentity();
5763 try {
5764 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5765 } finally {
5766 Binder.restoreCallingIdentity(identity);
5767 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005768 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005769
Tyler Gunnf70ed162019-04-03 15:28:53 -07005770 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005771 public int getSubIdForPhoneAccountHandle(
5772 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5773 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5774 callingPackage, "getSubIdForPhoneAccountHandle")) {
5775 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5776 }
5777 final long identity = Binder.clearCallingIdentity();
5778 try {
5779 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5780 } finally {
5781 Binder.restoreCallingIdentity(identity);
5782 }
5783 }
5784
5785 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005786 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5787 final long identity = Binder.clearCallingIdentity();
5788 try {
5789 Phone phone = getPhone(subscriptionId);
5790 if (phone == null) {
5791 return null;
5792 }
5793 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5794 } finally {
5795 Binder.restoreCallingIdentity(identity);
5796 }
5797 }
5798
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005799 /**
5800 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005801 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005802 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803 final long identity = Binder.clearCallingIdentity();
5804 try {
5805 Phone phone = getPhone(subId);
5806 if (phone != null) {
5807 return phone.isWifiCallingEnabled();
5808 } else {
5809 return false;
5810 }
5811 } finally {
5812 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005813 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005814 }
5815
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005816 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005817 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005818 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005819 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005820 final long identity = Binder.clearCallingIdentity();
5821 try {
5822 Phone phone = getPhone(subId);
5823 if (phone != null) {
5824 return phone.isVideoEnabled();
5825 } else {
5826 return false;
5827 }
5828 } finally {
5829 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005830 }
5831 }
5832
5833 /**
5834 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5835 * defined in {@link ImsRegistrationImplBase}.
5836 */
5837 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005838 final long identity = Binder.clearCallingIdentity();
5839 try {
5840 Phone phone = getPhone(subId);
5841 if (phone != null) {
5842 return phone.getImsRegistrationTech();
5843 } else {
5844 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5845 }
5846 } finally {
5847 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005848 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005849 }
5850
Stuart Scott8eef64f2015-04-08 15:13:54 -07005851 @Override
5852 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08005853 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005854 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5855 return;
5856 }
5857
Svet Ganovcc087f82015-05-12 20:35:54 -07005858 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005859
Svet Ganovcc087f82015-05-12 20:35:54 -07005860 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005861 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5862 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005863 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005864 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005865 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005866 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5867 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005868 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005869 // There has been issues when Sms raw table somehow stores orphan
5870 // fragments. They lead to garbled message when new fragments come
5871 // in and combined with those stale ones. In case this happens again,
5872 // user can reset all network settings which will clean up this table.
5873 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005874 // Clean up IMS settings as well here.
5875 int slotId = getSlotIndex(subId);
5876 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5877 ImsManager.getInstance(mApp, slotId).factoryReset();
5878 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07005879
5880 // Erase modem config if erase modem on network setting is enabled.
5881 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5882 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5883 if (configValue != null && Boolean.parseBoolean(configValue)) {
5884 sendEraseModemConfig(getDefaultPhone());
5885 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005886 } finally {
5887 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005888 }
5889 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005890
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005891 private void cleanUpSmsRawTable(Context context) {
5892 ContentResolver resolver = context.getContentResolver();
5893 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5894 resolver.delete(uri, null, null);
5895 }
5896
Narayan Kamath1c496c22015-04-16 14:40:19 +01005897 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005898 public String getSimLocaleForSubscriber(int subId) {
5899 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5900 final Phone phone = getPhone(subId);
5901 if (phone == null) {
5902 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005903 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005904 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005905 final long identity = Binder.clearCallingIdentity();
5906 try {
chen xu5d3637b2019-01-21 23:31:38 -08005907 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5908 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005909 if (info == null) {
5910 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5911 return null;
5912 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913 // Try and fetch the locale from the carrier properties or from the SIM language
5914 // preferences (EF-PL and EF-LI)...
5915 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005917 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5918 if (localeFromDefaultSim != null) {
5919 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5920 if (DBG) log("Using locale from subId: " + subId + " locale: "
5921 + localeFromDefaultSim);
5922 return localeFromDefaultSim.toLanguageTag();
5923 } else {
5924 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925 }
5926 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928 // The SIM language preferences only store a language (e.g. fr = French), not an
5929 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5930 // the SIM and carrier preferences does not include a country we add the country
5931 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005932 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005934 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 return mccLocale.toLanguageTag();
5936 }
5937
5938 if (DBG) log("No locale found - returning null");
5939 return null;
5940 } finally {
5941 Binder.restoreCallingIdentity(identity);
5942 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005943 }
5944
5945 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005946 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005947 }
5948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 /**
5950 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5951 */
5952 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005953 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005954 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005955
Chenjie Yu1ba97252018-01-11 18:16:20 -08005956 private final ModemActivityInfo mLastModemActivityInfo =
5957 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5958
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005959 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005960 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5961 * representing the state of the modem.
5962 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005963 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5964 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005965 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005966 */
5967 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005968 public void requestModemActivityInfo(ResultReceiver result) {
5969 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005970 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971
5972 final long identity = Binder.clearCallingIdentity();
5973 try {
5974 ModemActivityInfo ret = null;
5975 synchronized (mLastModemActivityInfo) {
5976 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5977 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005978 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005979 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5981 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005982 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5983 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 }
5985 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005986 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5987 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 mLastModemActivityInfo.setIdleTimeMillis(
5989 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5990 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5991 mLastModemActivityInfo.setRxTimeMillis(
5992 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5993 mLastModemActivityInfo.setEnergyUsed(
5994 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5997 mLastModemActivityInfo.getSleepTimeMillis(),
5998 mLastModemActivityInfo.getIdleTimeMillis(),
5999 mLastModemActivityInfo.getTxTimeMillis(),
6000 mLastModemActivityInfo.getRxTimeMillis(),
6001 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 Bundle bundle = new Bundle();
6004 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6005 result.send(0, bundle);
6006 } finally {
6007 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006008 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006009 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006010
Siddharth Rayb8114062018-06-17 15:02:38 -07006011 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6012 // less than total activity duration.
6013 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6014 if (info == null) {
6015 return false;
6016 }
6017 int activityDurationMs =
6018 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6019 int totalTxTimeMs = 0;
6020 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
6021 totalTxTimeMs += info.getTxTimeMillis()[i];
6022 }
6023 return (info.isValid()
6024 && (info.getSleepTimeMillis() <= activityDurationMs)
6025 && (info.getIdleTimeMillis() <= activityDurationMs)
6026 && (info.getRxTimeMillis() <= activityDurationMs)
6027 && (totalTxTimeMs <= activityDurationMs));
6028 }
6029
Jack Yu85bd38a2015-11-09 11:34:32 -08006030 /**
6031 * {@hide}
6032 * Returns the service state information on specified subscription.
6033 */
6034 @Override
6035 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006037 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006038 return null;
6039 }
6040
Hall Liuf19c44f2018-11-27 14:38:17 -08006041 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6042 LocationAccessPolicy.checkLocationPermission(mApp,
6043 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6044 .setCallingPackage(callingPackage)
6045 .setCallingPid(Binder.getCallingPid())
6046 .setCallingUid(Binder.getCallingUid())
6047 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006048 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006049 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6050 .build());
6051
6052 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6053 LocationAccessPolicy.checkLocationPermission(mApp,
6054 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6055 .setCallingPackage(callingPackage)
6056 .setCallingPid(Binder.getCallingPid())
6057 .setCallingUid(Binder.getCallingUid())
6058 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006059 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006060 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6061 .build());
6062 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6063 boolean hasFinePermission =
6064 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6065 boolean hasCoarsePermission =
6066 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6067
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 final long identity = Binder.clearCallingIdentity();
6069 try {
6070 final Phone phone = getPhone(subId);
6071 if (phone == null) {
6072 return null;
6073 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006074
Hall Liuf19c44f2018-11-27 14:38:17 -08006075 ServiceState ss = phone.getServiceState();
6076
6077 // Scrub out the location info in ServiceState depending on what level of access
6078 // the caller has.
6079 if (hasFinePermission) return ss;
6080 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6081 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 } finally {
6083 Binder.restoreCallingIdentity(identity);
6084 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006085 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006086
6087 /**
6088 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6089 *
6090 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6091 * voicemail ringtone.
6092 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6093 * PhoneAccount.
6094 */
6095 @Override
6096 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097 final long identity = Binder.clearCallingIdentity();
6098 try {
6099 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6100 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006101 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006102 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006104 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6105 } finally {
6106 Binder.restoreCallingIdentity(identity);
6107 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006108 }
6109
6110 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006111 * Sets the per-account voicemail ringtone.
6112 *
6113 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6114 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6115 *
6116 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6117 * voicemail ringtone.
6118 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6119 * PhoneAccount.
6120 */
6121 @Override
6122 public void setVoicemailRingtoneUri(String callingPackage,
6123 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006124 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006125 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006126 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6127 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6129 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6130 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006131 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132
6133 final long identity = Binder.clearCallingIdentity();
6134 try {
6135 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6136 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006137 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138 }
6139 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6140 } finally {
6141 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006142 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006143 }
6144
6145 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006146 * Returns whether vibration is set for voicemail notification in Phone settings.
6147 *
6148 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6149 * voicemail vibration setting.
6150 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6151 */
6152 @Override
6153 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154 final long identity = Binder.clearCallingIdentity();
6155 try {
6156 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6157 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006158 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006161 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6162 } finally {
6163 Binder.restoreCallingIdentity(identity);
6164 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006165 }
6166
Youhan Wange64578a2016-05-02 15:32:42 -07006167 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006168 * Sets the per-account voicemail vibration.
6169 *
6170 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6171 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6172 *
6173 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6174 * voicemail vibration setting.
6175 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6176 * specific PhoneAccount.
6177 */
6178 @Override
6179 public void setVoicemailVibrationEnabled(String callingPackage,
6180 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006181 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006182 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006183 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6184 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6186 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6187 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006188 }
6189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190 final long identity = Binder.clearCallingIdentity();
6191 try {
6192 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6193 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006194 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006195 }
6196 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6197 } finally {
6198 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006199 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006200 }
6201
6202 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006203 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6204 *
6205 * @throws SecurityException if the caller does not have the required permission
6206 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006207 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006208 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006209 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006210 }
6211
6212 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006213 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6214 * permission.
6215 *
6216 * @throws SecurityException if the caller does not have the required permission
6217 */
6218 private void enforceSendSmsPermission() {
6219 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6220 }
6221
6222 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006223 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006224 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006225 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006226 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006227 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006228 final long identity = Binder.clearCallingIdentity();
6229 try {
6230 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006231 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232 if (componentName == null) {
6233 throw new SecurityException(
6234 "Caller not current active visual voicemail package[null]");
6235 }
6236 String vvmPackage = componentName.getPackageName();
6237 if (!callingPackage.equals(vvmPackage)) {
6238 throw new SecurityException("Caller not current active visual voicemail package["
6239 + vvmPackage + "]");
6240 }
6241 } finally {
6242 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006243 }
6244 }
6245
6246 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006247 * Return the application ID for the app type.
6248 *
6249 * @param subId the subscription ID that this request applies to.
6250 * @param appType the uicc app type.
6251 * @return Application ID for specificied app type, or null if no uicc.
6252 */
6253 @Override
6254 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006255 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006256 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257
6258 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006259 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260 if (phone == null) {
6261 return null;
6262 }
6263 String aid = null;
6264 try {
6265 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6266 .getApplicationByType(appType).getAid();
6267 } catch (Exception e) {
6268 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6269 }
6270 return aid;
6271 } finally {
6272 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006273 }
Youhan Wange64578a2016-05-02 15:32:42 -07006274 }
6275
Youhan Wang4001d252016-05-11 10:29:41 -07006276 /**
6277 * Return the Electronic Serial Number.
6278 *
6279 * @param subId the subscription ID that this request applies to.
6280 * @return ESN or null if error.
6281 */
6282 @Override
6283 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006284 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006285 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286
6287 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006288 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 if (phone == null) {
6290 return null;
6291 }
6292 String esn = null;
6293 try {
6294 esn = phone.getEsn();
6295 } catch (Exception e) {
6296 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6297 }
6298 return esn;
6299 } finally {
6300 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006301 }
Youhan Wang4001d252016-05-11 10:29:41 -07006302 }
6303
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006304 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006305 * Return the Preferred Roaming List Version.
6306 *
6307 * @param subId the subscription ID that this request applies to.
6308 * @return PRLVersion or null if error.
6309 */
6310 @Override
6311 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006312 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006313 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314
6315 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006316 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317 if (phone == null) {
6318 return null;
6319 }
6320 String cdmaPrlVersion = null;
6321 try {
6322 cdmaPrlVersion = phone.getCdmaPrlVersion();
6323 } catch (Exception e) {
6324 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6325 }
6326 return cdmaPrlVersion;
6327 } finally {
6328 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006329 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006330 }
6331
6332 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006333 * Get snapshot of Telephony histograms
6334 * @return List of Telephony histograms
6335 * @hide
6336 */
6337 @Override
6338 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6340 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006341
6342 final long identity = Binder.clearCallingIdentity();
6343 try {
6344 return RIL.getTelephonyRILTimingHistograms();
6345 } finally {
6346 Binder.restoreCallingIdentity(identity);
6347 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006348 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006349
6350 /**
6351 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006352 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6353 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006354 * Require system privileges. In the future we may add this to carrier APIs.
6355 *
Michele Berionne482f8202018-11-27 18:57:59 -08006356 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006357 */
6358 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006359 @TelephonyManager.SetCarrierRestrictionResult
6360 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006361 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006362 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006363
Michele Berionne482f8202018-11-27 18:57:59 -08006364 if (carrierRestrictionRules == null) {
6365 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006366 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 final long identity = Binder.clearCallingIdentity();
6369 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006370 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006371 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006372 } finally {
6373 Binder.restoreCallingIdentity(identity);
6374 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006375 }
6376
6377 /**
6378 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006379 * Get the allowed carrier list and the excluded carrier list, including the priority between
6380 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006381 * Require system privileges. In the future we may add this to carrier APIs.
6382 *
Michele Berionne482f8202018-11-27 18:57:59 -08006383 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006384 */
6385 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006386 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006387 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006388 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389
6390 final long identity = Binder.clearCallingIdentity();
6391 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006392 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6393 if (response instanceof CarrierRestrictionRules) {
6394 return (CarrierRestrictionRules) response;
6395 }
6396 // Response is an Exception of some kind,
6397 // which is signalled to the user as a NULL retval
6398 return null;
6399 } catch (Exception e) {
6400 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6401 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 } finally {
6403 Binder.restoreCallingIdentity(identity);
6404 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006405 }
6406
fionaxu59545b42016-05-25 15:53:37 -07006407 /**
6408 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6409 * @param subId the subscription ID that this action applies to.
6410 * @param enabled control enable or disable metered apns.
6411 * {@hide}
6412 */
6413 @Override
6414 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6415 enforceModifyPermission();
6416 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417
6418 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006419 if (phone == null) {
6420 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6421 return;
6422 }
6423 try {
6424 phone.carrierActionSetMeteredApnsEnabled(enabled);
6425 } catch (Exception e) {
6426 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427 } finally {
6428 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006429 }
6430 }
6431
6432 /**
6433 * Action set from carrier signalling broadcast receivers to enable/disable radio
6434 * @param subId the subscription ID that this action applies to.
6435 * @param enabled control enable or disable radio.
6436 * {@hide}
6437 */
6438 @Override
6439 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6440 enforceModifyPermission();
6441 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006442
6443 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006444 if (phone == null) {
6445 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6446 return;
6447 }
6448 try {
6449 phone.carrierActionSetRadioEnabled(enabled);
6450 } catch (Exception e) {
6451 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006452 } finally {
6453 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006454 }
6455 }
6456
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006457 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006458 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6459 * network status based on which carrier apps could apply actions accordingly,
6460 * enable/disable default url handler for example.
6461 *
6462 * @param subId the subscription ID that this action applies to.
6463 * @param report control start/stop reporting the default network status.
6464 * {@hide}
6465 */
6466 @Override
6467 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6468 enforceModifyPermission();
6469 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006470
6471 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006472 if (phone == null) {
6473 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6474 return;
6475 }
6476 try {
6477 phone.carrierActionReportDefaultNetworkStatus(report);
6478 } catch (Exception e) {
6479 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 } finally {
6481 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006482 }
6483 }
6484
6485 /**
fionaxud9622282017-07-17 17:51:30 -07006486 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6487 * @param subId the subscription ID that this action applies to.
6488 * {@hide}
6489 */
6490 @Override
6491 public void carrierActionResetAll(int subId) {
6492 enforceModifyPermission();
6493 final Phone phone = getPhone(subId);
6494 if (phone == null) {
6495 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6496 return;
6497 }
6498 try {
6499 phone.carrierActionResetAll();
6500 } catch (Exception e) {
6501 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6502 }
6503 }
6504
6505 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006506 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6507 * bug report is being generated.
6508 */
6509 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006510 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006511 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6512 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006513 writer.println("Permission Denial: can't dump Phone from pid="
6514 + Binder.getCallingPid()
6515 + ", uid=" + Binder.getCallingUid()
6516 + "without permission "
6517 + android.Manifest.permission.DUMP);
6518 return;
6519 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006520 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006521 }
Jack Yueb89b242016-06-22 13:27:47 -07006522
Brad Ebingerdac2f002018-04-03 15:17:52 -07006523 @Override
6524 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6525 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6526 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006527 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6528 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006529 }
6530
Jack Yueb89b242016-06-22 13:27:47 -07006531 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006532 * Get aggregated video call data usage since boot.
6533 *
6534 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6535 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006536 * {@hide}
6537 */
6538 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006539 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006540 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6541 null);
6542
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006543 final long identity = Binder.clearCallingIdentity();
6544 try {
6545 // NetworkStatsService keeps tracking the active network interface and identity. It
6546 // records the delta with the corresponding network identity.
6547 // We just return the total video call data usage snapshot since boot.
6548 Phone phone = getPhone(subId);
6549 if (phone != null) {
6550 return phone.getVtDataUsage(perUidStats);
6551 }
6552 return null;
6553 } finally {
6554 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006555 }
Jack Yueb89b242016-06-22 13:27:47 -07006556 }
Jack Yu75ab2952016-07-08 14:29:33 -07006557
6558 /**
6559 * Policy control of data connection. Usually used when data limit is passed.
6560 * @param enabled True if enabling the data, otherwise disabling.
6561 * @param subId Subscription index
6562 * {@hide}
6563 */
6564 @Override
6565 public void setPolicyDataEnabled(boolean enabled, int subId) {
6566 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006567
6568 final long identity = Binder.clearCallingIdentity();
6569 try {
6570 Phone phone = getPhone(subId);
6571 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006572 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573 }
6574 } finally {
6575 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006576 }
6577 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006578
6579 /**
6580 * Get Client request stats
6581 * @return List of Client Request Stats
6582 * @hide
6583 */
6584 @Override
6585 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006587 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006588 return null;
6589 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006590 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006592 final long identity = Binder.clearCallingIdentity();
6593 try {
6594 if (phone != null) {
6595 return phone.getClientRequestStats();
6596 }
6597
6598 return null;
6599 } finally {
6600 Binder.restoreCallingIdentity(identity);
6601 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006602 }
6603
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006604 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006605 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006606 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006607 }
Jack Yueb4124c2017-02-16 15:32:43 -08006608
6609 /**
Grace Chen70990072017-03-24 17:21:30 -07006610 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006611 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006612 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006613 * @param state State of SIM (power down, power up, pass through)
6614 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6615 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6616 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006617 *
6618 **/
6619 @Override
Grace Chen70990072017-03-24 17:21:30 -07006620 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006621 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006622 Phone phone = PhoneFactory.getPhone(slotIndex);
6623
vagdeviaf9a5b92018-08-15 16:01:53 -07006624 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6625
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006626 final long identity = Binder.clearCallingIdentity();
6627 try {
6628 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006629 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006630 }
6631 } finally {
6632 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006633 }
6634 }
Shuo Qiandd210312017-04-12 22:11:33 +00006635
Tyler Gunn65d45c22017-06-05 11:22:26 -07006636 private boolean isUssdApiAllowed(int subId) {
6637 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006638 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006639 if (configManager == null) {
6640 return false;
6641 }
6642 PersistableBundle pb = configManager.getConfigForSubId(subId);
6643 if (pb == null) {
6644 return false;
6645 }
6646 return pb.getBoolean(
6647 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6648 }
6649
Shuo Qiandd210312017-04-12 22:11:33 +00006650 /**
6651 * Check if phone is in emergency callback mode
6652 * @return true if phone is in emergency callback mode
6653 * @param subId sub id
6654 */
goneil9c5f4872017-12-05 14:07:56 -08006655 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006656 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006657 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006658 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659
6660 final long identity = Binder.clearCallingIdentity();
6661 try {
6662 if (phone != null) {
6663 return phone.isInEcm();
6664 } else {
6665 return false;
6666 }
6667 } finally {
6668 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006669 }
6670 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006671
6672 /**
6673 * Get the current signal strength information for the given subscription.
6674 * Because this information is not updated when the device is in a low power state
6675 * it should not be relied-upon to be current.
6676 * @param subId Subscription index
6677 * @return the most recent cached signal strength info from the modem
6678 */
6679 @Override
6680 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006681 final long identity = Binder.clearCallingIdentity();
6682 try {
6683 Phone p = getPhone(subId);
6684 if (p == null) {
6685 return null;
6686 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006688 return p.getSignalStrength();
6689 } finally {
6690 Binder.restoreCallingIdentity(identity);
6691 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006692 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006693
Pengquan Meng77b7f132018-08-22 14:49:57 -07006694 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006695 * Get the current modem radio state for the given slot.
6696 * @param slotIndex slot index.
6697 * @param callingPackage the name of the package making the call.
6698 * @return the current radio power state from the modem
6699 */
6700 @Override
6701 public int getRadioPowerState(int slotIndex, String callingPackage) {
6702 Phone phone = PhoneFactory.getPhone(slotIndex);
6703 if (phone != null) {
6704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6705 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6706 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6707 }
6708
6709 final long identity = Binder.clearCallingIdentity();
6710 try {
6711 return phone.getRadioPowerState();
6712 } finally {
6713 Binder.restoreCallingIdentity(identity);
6714 }
6715 }
6716 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6717 }
6718
6719 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006720 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6721 *
6722 * <p>Requires one of the following permissions:
6723 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6724 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6725 * privileges.
6726 *
6727 * @param subId subscription id
6728 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6729 * {@code false}.
6730 */
6731 @Override
6732 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006733 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6734 null /* message */);
6735
Pengquan Menga1bb6272018-09-06 09:59:22 -07006736 boolean isEnabled = false;
6737 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006738 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006739 Phone phone = getPhone(subId);
6740 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006741 } catch (Exception e) {
6742 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6743 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006744 } finally {
6745 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006746 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006747 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006748 }
6749
6750
6751 /**
6752 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6753 *
6754 * <p> Requires permission:
6755 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6756 * privileges.
6757 *
6758 * @param subId subscription id
6759 * @param isEnabled {@code true} means enable, {@code false} means disable.
6760 */
6761 @Override
6762 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6764 mApp, subId, "setDataRoamingEnabled");
6765
Pengquan Menga1bb6272018-09-06 09:59:22 -07006766 final long identity = Binder.clearCallingIdentity();
6767 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006768 Phone phone = getPhone(subId);
6769 if (phone != null) {
6770 phone.setDataRoamingEnabled(isEnabled);
6771 }
6772 } finally {
6773 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006774 }
6775 }
6776
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006777 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006778 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006779 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6780 mApp, subId, "isManualNetworkSelectionAllowed");
6781
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006782 boolean isAllowed = true;
6783 final long identity = Binder.clearCallingIdentity();
6784 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006785 Phone phone = getPhone(subId);
6786 if (phone != null) {
6787 isAllowed = phone.isCspPlmnEnabled();
6788 }
6789 } finally {
6790 Binder.restoreCallingIdentity(identity);
6791 }
6792 return isAllowed;
6793 }
6794
6795 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006796 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006797 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006798 try {
6799 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006800 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006801 } catch (SecurityException e) {
6802 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6803 // has carrier privileges on an active UICC
6804 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6805 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006806 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006807 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006808 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006809
6810 final long identity = Binder.clearCallingIdentity();
6811 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006812 UiccController uiccController = UiccController.getInstance();
6813 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006814 if (hasReadPermission) {
6815 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006816 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006817
6818 // Remove private info if the caller doesn't have access
6819 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6820 for (UiccCardInfo cardInfo : cardInfos) {
6821 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6822 // is available
6823 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6824 if (card == null || card.getUiccProfile() == null) {
6825 // assume no access if the card or profile is unavailable
6826 filteredInfos.add(cardInfo.getUnprivileged());
6827 continue;
6828 }
6829 UiccProfile profile = card.getUiccProfile();
6830 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6831 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6832 filteredInfos.add(cardInfo);
6833 } else {
6834 filteredInfos.add(cardInfo.getUnprivileged());
6835 }
6836 }
6837 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006838 } finally {
6839 Binder.restoreCallingIdentity(identity);
6840 }
6841 }
6842
6843 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006844 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006845 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006847 final long identity = Binder.clearCallingIdentity();
6848 try {
6849 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6850 if (slots == null) {
6851 Rlog.i(LOG_TAG, "slots is null.");
6852 return null;
6853 }
6854
6855 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6856 for (int i = 0; i < slots.length; i++) {
6857 UiccSlot slot = slots[i];
6858 if (slot == null) {
6859 continue;
6860 }
6861
Jordan Liu7be7e652019-05-06 18:55:02 +00006862 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863 UiccCard card = slot.getUiccCard();
6864 if (card != null) {
6865 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006866 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006867 cardId = slot.getEid();
6868 if (TextUtils.isEmpty(cardId)) {
6869 cardId = slot.getIccId();
6870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871 }
6872
Jordan Liu857451f2019-05-09 16:35:35 -07006873 if (cardId != null) {
6874 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6875 // if cardId is an EID, it's all digits so this is fine
6876 cardId = IccUtils.stripTrailingFs(cardId);
6877 }
6878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006879 int cardState = 0;
6880 switch (slot.getCardState()) {
6881 case CARDSTATE_ABSENT:
6882 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6883 break;
6884 case CARDSTATE_PRESENT:
6885 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6886 break;
6887 case CARDSTATE_ERROR:
6888 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6889 break;
6890 case CARDSTATE_RESTRICTED:
6891 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6892 break;
6893 default:
6894 break;
6895
6896 }
6897
6898 infos[i] = new UiccSlotInfo(
6899 slot.isActive(),
6900 slot.isEuicc(),
6901 cardId,
6902 cardState,
6903 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006904 slot.isExtendedApduSupported(),
6905 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006906 }
6907 return infos;
6908 } finally {
6909 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006910 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006911 }
6912
6913 @Override
6914 public boolean switchSlots(int[] physicalSlots) {
6915 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006916
6917 final long identity = Binder.clearCallingIdentity();
6918 try {
6919 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6920 } finally {
6921 Binder.restoreCallingIdentity(identity);
6922 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006923 }
Jack Yu4c988042018-02-27 15:30:01 -08006924
6925 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006926 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006927 final long identity = Binder.clearCallingIdentity();
6928 try {
6929 return UiccController.getInstance().getCardIdForDefaultEuicc();
6930 } finally {
6931 Binder.restoreCallingIdentity(identity);
6932 }
6933 }
6934
6935 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006936 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6937 enforceModifyPermission();
6938 final Phone phone = getPhone(subId);
6939 if (phone == null) {
6940 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6941 return;
6942 }
6943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006944 final long identity = Binder.clearCallingIdentity();
6945 try {
6946 phone.setRadioIndicationUpdateMode(filters, mode);
6947 } finally {
6948 Binder.restoreCallingIdentity(identity);
6949 }
Jack Yu4c988042018-02-27 15:30:01 -08006950 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006951
6952 /**
goneil47ffb6e2018-04-06 15:40:58 -07006953 * A test API to reload the UICC profile.
6954 *
6955 * <p>Requires that the calling app has permission
6956 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6957 * @hide
6958 */
6959 @Override
6960 public void refreshUiccProfile(int subId) {
6961 enforceModifyPermission();
6962
6963 final long identity = Binder.clearCallingIdentity();
6964 try {
6965 Phone phone = getPhone(subId);
6966 if (phone == null) {
6967 return;
6968 }
6969 UiccCard uiccCard = phone.getUiccCard();
6970 if (uiccCard == null) {
6971 return;
6972 }
6973 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6974 if (uiccProfile == null) {
6975 return;
6976 }
6977 uiccProfile.refresh();
6978 } finally {
6979 Binder.restoreCallingIdentity(identity);
6980 }
6981 }
6982
6983 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006984 * Returns false if the mobile data is disabled by default, otherwise return true.
6985 */
6986 private boolean getDefaultDataEnabled() {
6987 return "true".equalsIgnoreCase(
6988 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6989 }
6990
6991 /**
6992 * Returns true if the data roaming is enabled by default, i.e the system property
6993 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6994 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6995 */
6996 private boolean getDefaultDataRoamingEnabled(int subId) {
6997 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006998 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006999 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
7000 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
7001 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7002 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7003 return isDataRoamingEnabled;
7004 }
7005
7006 /**
7007 * Returns the default network type for the given {@code subId}, if the default network type is
7008 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7009 */
7010 private int getDefaultNetworkType(int subId) {
7011 return Integer.parseInt(
7012 TelephonyManager.getTelephonyProperty(
7013 mSubscriptionController.getPhoneId(subId),
7014 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
7015 String.valueOf(Phone.PREFERRED_NT_MODE)));
7016 }
fionaxua13278b2018-03-21 00:08:13 -07007017
7018 @Override
7019 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007020 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007021 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022
7023 final long identity = Binder.clearCallingIdentity();
7024 try {
7025 final Phone phone = getPhone(subId);
7026 if (phone == null) {
7027 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7028 return;
7029 }
chen xueaba88a2019-03-15 13:15:10 -07007030 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7031 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007032 } finally {
7033 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007034 }
fionaxua13278b2018-03-21 00:08:13 -07007035 }
7036
7037 @Override
7038 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007039 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040
7041 final long identity = Binder.clearCallingIdentity();
7042 try {
7043 final Phone phone = getPhone(subId);
7044 if (phone == null) {
7045 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7046 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7047 }
7048 return phone.getCarrierIdListVersion();
7049 } finally {
7050 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007051 }
fionaxua13278b2018-03-21 00:08:13 -07007052 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007053
7054 @Override
7055 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
7056 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7057 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
7058 return -1;
7059 }
7060
7061 final long identity = Binder.clearCallingIdentity();
7062 try {
7063 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7064 } finally {
7065 Binder.restoreCallingIdentity(identity);
7066 }
7067 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007068
7069 @Override
7070 public int getCdmaRoamingMode(int subId) {
7071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7072 mApp, subId, "getCdmaRoamingMode");
7073
7074 final long identity = Binder.clearCallingIdentity();
7075 try {
7076 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7077 } finally {
7078 Binder.restoreCallingIdentity(identity);
7079 }
7080 }
7081
7082 @Override
7083 public boolean setCdmaRoamingMode(int subId, int mode) {
7084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7085 mApp, subId, "setCdmaRoamingMode");
7086
7087 final long identity = Binder.clearCallingIdentity();
7088 try {
7089 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7090 } finally {
7091 Binder.restoreCallingIdentity(identity);
7092 }
7093 }
7094
7095 @Override
7096 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7098 mApp, subId, "setCdmaSubscriptionMode");
7099
7100 final long identity = Binder.clearCallingIdentity();
7101 try {
7102 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7103 } finally {
7104 Binder.restoreCallingIdentity(identity);
7105 }
7106 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007107
sqianc5eccab2018-10-19 18:46:41 -07007108 @Override
sqian8c685422019-02-22 15:55:18 -08007109 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007110 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007112 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007113 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7114 }
7115 final long identity = Binder.clearCallingIdentity();
7116 try {
sqian854d44b2018-12-12 16:48:18 -08007117 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7118 for (Phone phone: PhoneFactory.getPhones()) {
7119 if (phone.getEmergencyNumberTracker() != null
7120 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7121 emergencyNumberListInternal.put(
7122 phone.getSubId(),
7123 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7124 }
sqian11b7a0e2018-12-05 18:48:28 -08007125 }
sqian854d44b2018-12-12 16:48:18 -08007126 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007127 } finally {
7128 Binder.restoreCallingIdentity(identity);
7129 }
sqianc5eccab2018-10-19 18:46:41 -07007130 }
7131
7132 @Override
sqian8c685422019-02-22 15:55:18 -08007133 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007134 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007135 if (!exactMatch) {
7136 TelephonyPermissions
7137 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007138 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007139 }
7140 final long identity = Binder.clearCallingIdentity();
7141 try {
sqian854d44b2018-12-12 16:48:18 -08007142 for (Phone phone: PhoneFactory.getPhones()) {
7143 if (phone.getEmergencyNumberTracker() != null
7144 && phone.getEmergencyNumberTracker() != null) {
7145 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7146 number, exactMatch)) {
7147 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007148 }
7149 }
sqian11b7a0e2018-12-05 18:48:28 -08007150 }
7151 return false;
7152 } finally {
7153 Binder.restoreCallingIdentity(identity);
7154 }
7155 }
7156
sqianf4ca7ed2019-01-15 18:32:07 -08007157 /**
7158 * Update emergency number list for test mode.
7159 */
7160 @Override
7161 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7162 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7163 "updateEmergencyNumberListTestMode");
7164
7165 final long identity = Binder.clearCallingIdentity();
7166 try {
7167 for (Phone phone: PhoneFactory.getPhones()) {
7168 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7169 if (tracker != null) {
7170 tracker.executeEmergencyNumberTestModeCommand(action, num);
7171 }
7172 }
7173 } finally {
7174 Binder.restoreCallingIdentity(identity);
7175 }
7176 }
7177
7178 /**
7179 * Get the full emergency number list for test mode.
7180 */
7181 @Override
7182 public List<String> getEmergencyNumberListTestMode() {
7183 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7184 "getEmergencyNumberListTestMode");
7185
7186 final long identity = Binder.clearCallingIdentity();
7187 try {
7188 Set<String> emergencyNumbers = new HashSet<>();
7189 for (Phone phone: PhoneFactory.getPhones()) {
7190 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7191 if (tracker != null) {
7192 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7193 emergencyNumbers.add(num.getNumber());
7194 }
7195 }
7196 }
7197 return new ArrayList<>(emergencyNumbers);
7198 } finally {
7199 Binder.restoreCallingIdentity(identity);
7200 }
7201 }
7202
chen xud6b45bd2018-10-30 22:27:10 -07007203 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007204 public int getEmergencyNumberDbVersion(int subId) {
7205 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7206
7207 final long identity = Binder.clearCallingIdentity();
7208 try {
7209 final Phone phone = getPhone(subId);
7210 if (phone == null) {
7211 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7212 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7213 }
7214 return phone.getEmergencyNumberDbVersion();
7215 } finally {
7216 Binder.restoreCallingIdentity(identity);
7217 }
7218 }
7219
7220 @Override
7221 public void notifyOtaEmergencyNumberDbInstalled() {
7222 enforceModifyPermission();
7223
7224 final long identity = Binder.clearCallingIdentity();
7225 try {
7226 for (Phone phone: PhoneFactory.getPhones()) {
7227 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7228 if (tracker != null) {
7229 tracker.updateOtaEmergencyNumberDatabase();
7230 }
7231 }
7232 } finally {
7233 Binder.restoreCallingIdentity(identity);
7234 }
7235 }
7236
7237 @Override
7238 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7239 enforceActiveEmergencySessionPermission();
7240
7241 final long identity = Binder.clearCallingIdentity();
7242 try {
7243 for (Phone phone: PhoneFactory.getPhones()) {
7244 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7245 if (tracker != null) {
7246 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7247 }
7248 }
7249 } finally {
7250 Binder.restoreCallingIdentity(identity);
7251 }
7252 }
7253
7254 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007255 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7256 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7257 Phone phone = getPhone(subId);
7258 if (phone == null) {
7259 return null;
7260 }
7261 final long identity = Binder.clearCallingIdentity();
7262 try {
7263 UiccProfile profile = UiccController.getInstance()
7264 .getUiccProfileForPhone(phone.getPhoneId());
7265 if (profile != null) {
7266 return profile.getCertsFromCarrierPrivilegeAccessRules();
7267 }
7268 } finally {
7269 Binder.restoreCallingIdentity(identity);
7270 }
7271 return null;
7272 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007273
7274 /**
7275 * Enable or disable a modem stack.
7276 */
7277 @Override
7278 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7279 enforceModifyPermission();
7280
7281 final long identity = Binder.clearCallingIdentity();
7282 try {
7283 Phone phone = PhoneFactory.getPhone(slotIndex);
7284 if (phone == null) {
7285 return false;
7286 } else {
7287 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7288 }
7289 } finally {
7290 Binder.restoreCallingIdentity(identity);
7291 }
7292 }
Michelecea4cf22018-12-21 15:00:11 -08007293
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007294 /**
7295 * Whether a modem stack is enabled or not.
7296 */
7297 @Override
7298 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7299 Phone phone = PhoneFactory.getPhone(slotIndex);
7300 if (phone == null) return false;
7301
7302 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7303 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7304 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7305 }
7306
7307 final long identity = Binder.clearCallingIdentity();
7308 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007309 try {
7310 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7311 } catch (NoSuchElementException ex) {
7312 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7313 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007314 } finally {
7315 Binder.restoreCallingIdentity(identity);
7316 }
7317 }
7318
Michelecea4cf22018-12-21 15:00:11 -08007319 @Override
Michele0ea7d782019-03-19 14:58:42 -07007320 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007321 enforceModifyPermission();
7322
7323 final long identity = Binder.clearCallingIdentity();
7324 try {
7325 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007326 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007327 .commit();
7328 } finally {
7329 Binder.restoreCallingIdentity(identity);
7330 }
7331 }
7332
7333 @Override
Michele0ea7d782019-03-19 14:58:42 -07007334 @TelephonyManager.IsMultiSimSupportedResult
7335 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007337 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7338 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007339 }
Michelecea4cf22018-12-21 15:00:11 -08007340
7341 final long identity = Binder.clearCallingIdentity();
7342 try {
Michele0ea7d782019-03-19 14:58:42 -07007343 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007344 } finally {
7345 Binder.restoreCallingIdentity(identity);
7346 }
7347 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007348
Michele0ea7d782019-03-19 14:58:42 -07007349 @TelephonyManager.IsMultiSimSupportedResult
7350 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007351 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7352 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7353 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007354 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7355 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007356 }
7357 // Check if the hardware supports multisim functionality. If usage of multisim is not
7358 // supported by the modem, indicate that it is restricted.
7359 PhoneCapability staticCapability =
7360 mPhoneConfigurationManager.getStaticPhoneCapability();
7361 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007362 loge("isMultiSimSupportedInternal: no static configuration available");
7363 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007364 }
7365 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007366 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7367 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007368 }
7369 // Check if support of multiple SIMs is restricted by carrier
7370 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007371 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007372 }
7373
Michele0ea7d782019-03-19 14:58:42 -07007374 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007375 }
7376
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007377 /**
7378 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007379 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7380 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7381 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007382 * @param numOfSims number of active sims we want to switch to
7383 */
7384 @Override
7385 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007386 if (numOfSims == 1) {
7387 enforceModifyPermission();
7388 } else {
7389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7390 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7391 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007392 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007393
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007394 try {
Michele30b57b22019-03-01 12:01:14 -08007395 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007396 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007397 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7398 return;
7399 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007400 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7401 } finally {
7402 Binder.restoreCallingIdentity(identity);
7403 }
7404 }
7405
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007406 @Override
7407 public boolean isApplicationOnUicc(int subId, int appType) {
7408 enforceReadPrivilegedPermission("isApplicationOnUicc");
7409 Phone phone = getPhone(subId);
7410 if (phone == null) {
7411 return false;
7412 }
7413 final long identity = Binder.clearCallingIdentity();
7414 try {
7415 UiccCard uiccCard = phone.getUiccCard();
7416 if (uiccCard == null) {
7417 return false;
7418 }
7419 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7420 if (uiccProfile == null) {
7421 return false;
7422 }
7423 if (TelephonyManager.APPTYPE_SIM <= appType
7424 && appType <= TelephonyManager.APPTYPE_ISIM) {
7425 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7426 }
7427 return false;
7428 } finally {
7429 Binder.restoreCallingIdentity(identity);
7430 }
7431 }
7432
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007433 /**
chen xub4baa772019-04-03 10:23:41 -07007434 * Get whether making changes to modem configurations will trigger reboot.
7435 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007436 */
7437 @Override
chen xub4baa772019-04-03 10:23:41 -07007438 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7439 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7440 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7441 return false;
7442 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007443 final long identity = Binder.clearCallingIdentity();
7444 try {
7445 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7446 } finally {
7447 Binder.restoreCallingIdentity(identity);
7448 }
7449 }
7450
Nathan Harold29f5f052019-02-15 13:41:57 -08007451 private void updateModemStateMetrics() {
7452 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7453 // TODO: check the state for each modem if the api is ready.
7454 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7455 }
7456
Pengquan Meng3889a572019-01-23 11:16:29 -08007457 @Override
7458 public int[] getSlotsMapping() {
7459 enforceReadPrivilegedPermission("getSlotsMapping");
7460
7461 final long identity = Binder.clearCallingIdentity();
7462 try {
7463 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7464 // All logical slots should have a mapping to a physical slot.
7465 int[] logicalSlotsMapping = new int[phoneCount];
7466 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7467 for (int i = 0; i < slotInfos.length; i++) {
7468 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7469 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7470 }
7471 }
7472 return logicalSlotsMapping;
7473 } finally {
7474 Binder.restoreCallingIdentity(identity);
7475 }
7476 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007477
7478 /**
7479 * Get the IRadio HAL Version
7480 */
7481 @Override
7482 public int getRadioHalVersion() {
7483 Phone phone = getDefaultPhone();
7484 if (phone == null) return -1;
7485 HalVersion hv = phone.getHalVersion();
7486 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7487 return hv.major * 100 + hv.minor;
7488 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007489
7490 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007491 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7492 * corresponding network requests on a subId.
7493 *
7494 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007495 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007496 * 2) APN is un-metered for this subscription, or
7497 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7498 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7499 *
7500 * @return whether data is allowed for a apn type.
7501 *
7502 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007503 */
7504 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007505 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007506 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7507 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007508
7509 // Now that all security checks passes, perform the operation as ourselves.
7510 final long identity = Binder.clearCallingIdentity();
7511 try {
7512 Phone phone = getPhone(subId);
7513 if (phone == null) return false;
7514
Jack Yu41407ee2019-05-13 16:54:09 -07007515 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007516 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7517 } finally {
7518 Binder.restoreCallingIdentity(identity);
7519 }
7520 }
7521
7522 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007523 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007524 enforceReadPrivilegedPermission("isApnMetered");
7525
7526 // Now that all security checks passes, perform the operation as ourselves.
7527 final long identity = Binder.clearCallingIdentity();
7528 try {
7529 Phone phone = getPhone(subId);
7530 if (phone == null) return true; // By default return true.
7531
Jack Yu41407ee2019-05-13 16:54:09 -07007532 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007533 } finally {
7534 Binder.restoreCallingIdentity(identity);
7535 }
7536 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007537
7538 @Override
7539 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7540 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7541 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7542 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7543 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7544 }
7545 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7546 Intent intent = new Intent();
7547 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7548 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7549 // Bring up choose default SMS subscription dialog right now
7550 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7551 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7552 mApp.startActivity(intent);
7553 }
chen xud5ca2d52019-05-28 15:20:57 -07007554
7555 @Override
7556 public String getMmsUAProfUrl(int subId) {
7557 //TODO investigate if this API should require proper permission check in R b/133791609
7558 final long identity = Binder.clearCallingIdentity();
7559 try {
7560 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7561 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7562 } finally {
7563 Binder.restoreCallingIdentity(identity);
7564 }
7565 }
7566
7567 @Override
7568 public String getMmsUserAgent(int subId) {
7569 //TODO investigate if this API should require proper permission check in R b/133791609
7570 final long identity = Binder.clearCallingIdentity();
7571 try {
7572 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7573 .getString(com.android.internal.R.string.config_mms_user_agent);
7574 } finally {
7575 Binder.restoreCallingIdentity(identity);
7576 }
7577 }
Jack Yub07d4972019-05-28 16:12:25 -07007578
7579 @Override
7580 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7581 enforceModifyPermission();
7582
7583 // Now that all security checks passes, perform the operation as ourselves.
7584 final long identity = Binder.clearCallingIdentity();
7585 try {
7586 Phone phone = getPhone(subId);
7587 if (phone == null) return false;
7588
7589 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7590 } finally {
7591 Binder.restoreCallingIdentity(identity);
7592 }
7593 }
7594
7595 @Override
7596 public boolean isDataAllowedInVoiceCall(int subId) {
7597 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7598
7599 // Now that all security checks passes, perform the operation as ourselves.
7600 final long identity = Binder.clearCallingIdentity();
7601 try {
7602 Phone phone = getPhone(subId);
7603 if (phone == null) return false;
7604
7605 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7606 } finally {
7607 Binder.restoreCallingIdentity(identity);
7608 }
7609 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007610
7611 /**
7612 * Updates whether conference event pacakge handling is enabled.
7613 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7614 * otherwise.
7615 */
7616 @Override
7617 public void setCepEnabled(boolean isCepEnabled) {
7618 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7619
7620 final long identity = Binder.clearCallingIdentity();
7621 try {
7622 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7623 for (Phone phone : PhoneFactory.getPhones()) {
7624 Phone defaultPhone = phone.getImsPhone();
7625 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7626 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7627 ImsPhoneCallTracker imsPhoneCallTracker =
7628 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7629 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7630 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7631 + imsPhone.getMsisdn());
7632 }
7633 }
7634 } finally {
7635 Binder.restoreCallingIdentity(identity);
7636 }
7637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007638}