blob: 7fe72ae3099eabfc168a97663c5f054928bdf7ae [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 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001226 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001227 case CMD_ERASE_MODEM_CONFIG:
1228 request = (MainThreadRequest) msg.obj;
1229 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1230 defaultPhone.eraseModemConfig(onCompleted);
1231 break;
1232 case EVENT_ERASE_MODEM_CONFIG_DONE:
1233 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001234 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 default:
1236 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1237 break;
1238 }
1239 }
Jake Hambye994d462014-02-03 13:10:13 -08001240
Pengquan Menga1bb6272018-09-06 09:59:22 -07001241 private void notifyRequester(MainThreadRequest request) {
1242 synchronized (request) {
1243 request.notifyAll();
1244 }
1245 }
1246
Jake Hambye994d462014-02-03 13:10:13 -08001247 private void handleNullReturnEvent(Message msg, String command) {
1248 AsyncResult ar = (AsyncResult) msg.obj;
1249 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1250 if (ar.exception == null) {
1251 request.result = true;
1252 } else {
1253 request.result = false;
1254 if (ar.exception instanceof CommandException) {
1255 loge(command + ": CommandException: " + ar.exception);
1256 } else {
1257 loge(command + ": Unknown exception");
1258 }
1259 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001260 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 }
1263
1264 /**
1265 * Posts the specified command to be executed on the main thread,
1266 * waits for the request to complete, and returns the result.
1267 * @see #sendRequestAsync
1268 */
1269 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001270 return sendRequest(
1271 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001272 }
1273
1274 /**
1275 * Posts the specified command to be executed on the main thread,
1276 * waits for the request to complete, and returns the result.
1277 * @see #sendRequestAsync
1278 */
1279 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1280 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001281 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001282 }
1283
1284 /**
1285 * Posts the specified command to be executed on the main thread,
1286 * waits for the request to complete, and returns the result.
1287 * @see #sendRequestAsync
1288 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001289 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001290 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001291 }
1292
1293 /**
1294 * Posts the specified command to be executed on the main thread,
1295 * waits for the request to complete, and returns the result.
1296 * @see #sendRequestAsync
1297 */
Nathan Harold92bed182018-10-12 18:16:49 -07001298 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1299 return sendRequest(command, argument, subId, null, workSource);
1300 }
1301
1302 /**
1303 * Posts the specified command to be executed on the main thread,
1304 * waits for the request to complete, and returns the result.
1305 * @see #sendRequestAsync
1306 */
1307 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1308 return sendRequest(
1309 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1310 }
1311
1312 /**
1313 * Posts the specified command to be executed on the main thread,
1314 * waits for the request to complete, and returns the result.
1315 * @see #sendRequestAsync
1316 */
1317 private Object sendRequest(
1318 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1320 throw new RuntimeException("This method will deadlock if called from the main thread.");
1321 }
1322
Nathan Harold92bed182018-10-12 18:16:49 -07001323 MainThreadRequest request = null;
1324 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1325 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1326 } else if (phone != null) {
1327 request = new MainThreadRequest(argument, phone, workSource);
1328 } else {
1329 request = new MainThreadRequest(argument, subId, workSource);
1330 }
1331
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001332 Message msg = mMainThreadHandler.obtainMessage(command, request);
1333 msg.sendToTarget();
1334
1335 // Wait for the request to complete
1336 synchronized (request) {
1337 while (request.result == null) {
1338 try {
1339 request.wait();
1340 } catch (InterruptedException e) {
1341 // Do nothing, go back and wait until the request is complete
1342 }
1343 }
1344 }
1345 return request.result;
1346 }
1347
1348 /**
1349 * Asynchronous ("fire and forget") version of sendRequest():
1350 * Posts the specified command to be executed on the main thread, and
1351 * returns immediately.
1352 * @see #sendRequest
1353 */
1354 private void sendRequestAsync(int command) {
1355 mMainThreadHandler.sendEmptyMessage(command);
1356 }
1357
1358 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001359 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001360 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001361 */
1362 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001363 sendRequestAsync(command, argument, null, null);
1364 }
1365
1366 /**
1367 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1368 * @see {@link #sendRequest(int,Object)}
1369 */
1370 private void sendRequestAsync(
1371 int command, Object argument, Phone phone, WorkSource workSource) {
1372 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001373 Message msg = mMainThreadHandler.obtainMessage(command, request);
1374 msg.sendToTarget();
1375 }
1376
1377 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 * Initialize the singleton PhoneInterfaceManager instance.
1379 * This is only done once, at startup, from PhoneApp.onCreate().
1380 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001381 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 synchronized (PhoneInterfaceManager.class) {
1383 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001384 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 } else {
1386 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1387 }
1388 return sInstance;
1389 }
1390 }
1391
1392 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001393 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001396 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001397 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1398 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001399 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001400 mTelephonySharedPreferences =
1401 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001402 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001403 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001404
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001405 publish();
1406 }
1407
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001408 private Phone getDefaultPhone() {
1409 Phone thePhone = getPhone(getDefaultSubscription());
1410 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1411 }
1412
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413 private void publish() {
1414 if (DBG) log("publish: " + this);
1415
1416 ServiceManager.addService("phone", this);
1417 }
1418
Stuart Scott584921c2015-01-15 17:10:34 -08001419 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001420 if (request.phone != null) {
1421 return request.phone;
1422 } else {
1423 return getPhoneFromSubId(request.subId);
1424 }
1425 }
1426
1427 private Phone getPhoneFromSubId(int subId) {
1428 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1429 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001430 }
1431
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001432 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1433 Phone phone = getPhoneFromRequest(request);
1434 return phone == null ? null :
1435 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1436 }
1437
Wink Saville36469e72014-06-11 15:17:00 -07001438 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001439 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001440 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001443 private void sendEraseModemConfig(Phone phone) {
1444 if (phone != null) {
1445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1446 mApp, phone.getSubId(), "eraseModemConfig");
1447 final long identity = Binder.clearCallingIdentity();
1448 try {
1449 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1450 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1451 } finally {
1452 Binder.restoreCallingIdentity(identity);
1453 }
1454 }
1455 }
1456
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001457 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001458 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001459 }
1460
Wink Savilleb564aae2014-10-23 10:18:09 -07001461 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 if (DBG) log("dial: " + number);
1463 // No permission check needed here: This is just a wrapper around the
1464 // ACTION_DIAL intent, which is available to any app since it puts up
1465 // the UI before it does anything.
1466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001467 final long identity = Binder.clearCallingIdentity();
1468 try {
1469 String url = createTelUrl(number);
1470 if (url == null) {
1471 return;
1472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001474 // PENDING: should we just silently fail if phone is offhook or ringing?
1475 PhoneConstants.State state = mCM.getState(subId);
1476 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1477 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1478 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1479 mApp.startActivity(intent);
1480 }
1481 } finally {
1482 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484 }
1485
1486 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001487 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001488 }
1489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 if (DBG) log("call: " + number);
1492
1493 // This is just a wrapper around the ACTION_CALL intent, but we still
1494 // need to do a permission check since we're calling startActivity()
1495 // from the context of the phone app.
1496 enforceCallPermission();
1497
Jordan Liu1617b712019-07-10 15:06:26 -07001498 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001499 != AppOpsManager.MODE_ALLOWED) {
1500 return;
1501 }
1502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001503 final long identity = Binder.clearCallingIdentity();
1504 try {
1505 String url = createTelUrl(number);
1506 if (url == null) {
1507 return;
1508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001510 boolean isValid = false;
1511 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1512 if (slist != null) {
1513 for (SubscriptionInfo subInfoRecord : slist) {
1514 if (subInfoRecord.getSubscriptionId() == subId) {
1515 isValid = true;
1516 break;
1517 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001518 }
Wink Saville08874612014-08-31 19:19:58 -07001519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001520 if (!isValid) {
1521 return;
1522 }
Wink Saville08874612014-08-31 19:19:58 -07001523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001524 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1525 intent.putExtra(SUBSCRIPTION_KEY, subId);
1526 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1527 mApp.startActivity(intent);
1528 } finally {
1529 Binder.restoreCallingIdentity(identity);
1530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 }
1532
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001534 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001535 }
1536
Wink Savilleb564aae2014-10-23 10:18:09 -07001537 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001538 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001539 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1540 }
1541
1542 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001543 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001544 }
1545
Wink Savilleb564aae2014-10-23 10:18:09 -07001546 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001547 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001548 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1549 }
1550
1551 /** {@hide} */
1552 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001553 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001554 }
1555
Wink Savilleb564aae2014-10-23 10:18:09 -07001556 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001558
1559 final long identity = Binder.clearCallingIdentity();
1560 try {
1561 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1562 checkSimPin.start();
1563 return checkSimPin.unlockSim(null, pin);
1564 } finally {
1565 Binder.restoreCallingIdentity(identity);
1566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 }
1568
Wink Saville9de0f752013-10-22 19:04:03 -07001569 /** {@hide} */
1570 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001571 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001572 }
1573
Wink Savilleb564aae2014-10-23 10:18:09 -07001574 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001575 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001576
1577 final long identity = Binder.clearCallingIdentity();
1578 try {
1579 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1580 checkSimPuk.start();
1581 return checkSimPuk.unlockSim(puk, pin);
1582 } finally {
1583 Binder.restoreCallingIdentity(identity);
1584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001585 }
1586
1587 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001588 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 * a synchronous one.
1590 */
1591 private static class UnlockSim extends Thread {
1592
1593 private final IccCard mSimCard;
1594
1595 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001596 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1597 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598
1599 // For replies from SimCard interface
1600 private Handler mHandler;
1601
1602 // For async handler to identify request type
1603 private static final int SUPPLY_PIN_COMPLETE = 100;
1604
1605 public UnlockSim(IccCard simCard) {
1606 mSimCard = simCard;
1607 }
1608
1609 @Override
1610 public void run() {
1611 Looper.prepare();
1612 synchronized (UnlockSim.this) {
1613 mHandler = new Handler() {
1614 @Override
1615 public void handleMessage(Message msg) {
1616 AsyncResult ar = (AsyncResult) msg.obj;
1617 switch (msg.what) {
1618 case SUPPLY_PIN_COMPLETE:
1619 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1620 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001621 mRetryCount = msg.arg1;
1622 if (ar.exception != null) {
1623 if (ar.exception instanceof CommandException &&
1624 ((CommandException)(ar.exception)).getCommandError()
1625 == CommandException.Error.PASSWORD_INCORRECT) {
1626 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1627 } else {
1628 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1629 }
1630 } else {
1631 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001633 mDone = true;
1634 UnlockSim.this.notifyAll();
1635 }
1636 break;
1637 }
1638 }
1639 };
1640 UnlockSim.this.notifyAll();
1641 }
1642 Looper.loop();
1643 }
1644
1645 /*
1646 * Use PIN or PUK to unlock SIM card
1647 *
1648 * If PUK is null, unlock SIM card with PIN
1649 *
1650 * If PUK is not null, unlock SIM card with PUK and set PIN code
1651 */
Wink Saville9de0f752013-10-22 19:04:03 -07001652 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653
1654 while (mHandler == null) {
1655 try {
1656 wait();
1657 } catch (InterruptedException e) {
1658 Thread.currentThread().interrupt();
1659 }
1660 }
1661 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1662
1663 if (puk == null) {
1664 mSimCard.supplyPin(pin, callback);
1665 } else {
1666 mSimCard.supplyPuk(puk, pin, callback);
1667 }
1668
1669 while (!mDone) {
1670 try {
1671 Log.d(LOG_TAG, "wait for done");
1672 wait();
1673 } catch (InterruptedException e) {
1674 // Restore the interrupted status
1675 Thread.currentThread().interrupt();
1676 }
1677 }
1678 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001679 int[] resultArray = new int[2];
1680 resultArray[0] = mResult;
1681 resultArray[1] = mRetryCount;
1682 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 }
1684 }
1685
1686 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001687 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001688
1689 }
1690
Wink Savilleb564aae2014-10-23 10:18:09 -07001691 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 // No permission check needed here: this call is harmless, and it's
1693 // needed for the ServiceState.requestStateUpdate() call (which is
1694 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001695 final long identity = Binder.clearCallingIdentity();
1696 try {
1697 final Phone phone = getPhone(subId);
1698 if (phone != null) {
1699 phone.updateServiceLocation();
1700 }
1701 } finally {
1702 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 }
1705
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001706 @Override
1707 public boolean isRadioOn(String callingPackage) {
1708 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001709 }
1710
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001711 @Override
1712 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001714 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001715 return false;
1716 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001717
1718 final long identity = Binder.clearCallingIdentity();
1719 try {
1720 return isRadioOnForSubscriber(subId);
1721 } finally {
1722 Binder.restoreCallingIdentity(identity);
1723 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001724 }
1725
1726 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001727 final long identity = Binder.clearCallingIdentity();
1728 try {
1729 final Phone phone = getPhone(subId);
1730 if (phone != null) {
1731 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1732 } else {
1733 return false;
1734 }
1735 } finally {
1736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
1739
1740 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001741 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 }
Wink Saville36469e72014-06-11 15:17:00 -07001743
Wink Savilleb564aae2014-10-23 10:18:09 -07001744 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001746
1747 final long identity = Binder.clearCallingIdentity();
1748 try {
1749 final Phone phone = getPhone(subId);
1750 if (phone != null) {
1751 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1752 }
1753 } finally {
1754 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001755 }
Wink Saville36469e72014-06-11 15:17:00 -07001756 }
1757
1758 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001759 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001760 }
1761
Wink Savilleb564aae2014-10-23 10:18:09 -07001762 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001763 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001764
1765 final long identity = Binder.clearCallingIdentity();
1766 try {
1767 final Phone phone = getPhone(subId);
1768 if (phone == null) {
1769 return false;
1770 }
1771 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1772 toggleRadioOnOffForSubscriber(subId);
1773 }
1774 return true;
1775 } finally {
1776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 }
Wink Saville36469e72014-06-11 15:17:00 -07001779
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001780 public boolean needMobileRadioShutdown() {
1781 /*
1782 * If any of the Radios are available, it will need to be
1783 * shutdown. So return true if any Radio is available.
1784 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001785 final long identity = Binder.clearCallingIdentity();
1786 try {
1787 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1788 Phone phone = PhoneFactory.getPhone(i);
1789 if (phone != null && phone.isRadioAvailable()) return true;
1790 }
1791 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1792 return false;
1793 } finally {
1794 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001795 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001796 }
1797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001798 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001799 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001800 enforceModifyPermission();
1801
1802 final long identity = Binder.clearCallingIdentity();
1803 try {
1804 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1805 logv("Shutting down Phone " + i);
1806 shutdownRadioUsingPhoneId(i);
1807 }
1808 } finally {
1809 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001810 }
1811 }
1812
1813 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001814 Phone phone = PhoneFactory.getPhone(phoneId);
1815 if (phone != null && phone.isRadioAvailable()) {
1816 phone.shutdownRadio();
1817 }
1818 }
1819
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001821 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001822
1823 final long identity = Binder.clearCallingIdentity();
1824 try {
1825 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1826 if (defaultPhone != null) {
1827 defaultPhone.setRadioPower(turnOn);
1828 return true;
1829 } else {
1830 loge("There's no default phone.");
1831 return false;
1832 }
1833 } finally {
1834 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001835 }
Wink Saville36469e72014-06-11 15:17:00 -07001836 }
1837
Wink Savilleb564aae2014-10-23 10:18:09 -07001838 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001840
1841 final long identity = Binder.clearCallingIdentity();
1842 try {
1843 final Phone phone = getPhone(subId);
1844 if (phone != null) {
1845 phone.setRadioPower(turnOn);
1846 return true;
1847 } else {
1848 return false;
1849 }
1850 } finally {
1851 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001852 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 }
1854
Wink Saville36469e72014-06-11 15:17:00 -07001855 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001856 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 public boolean enableDataConnectivity() {
1858 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001859
1860 final long identity = Binder.clearCallingIdentity();
1861 try {
1862 int subId = mSubscriptionController.getDefaultDataSubId();
1863 final Phone phone = getPhone(subId);
1864 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001865 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001866 return true;
1867 } else {
1868 return false;
1869 }
1870 } finally {
1871 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 }
1874
Wink Saville36469e72014-06-11 15:17:00 -07001875 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001876 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 public boolean disableDataConnectivity() {
1878 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001879
1880 final long identity = Binder.clearCallingIdentity();
1881 try {
1882 int subId = mSubscriptionController.getDefaultDataSubId();
1883 final Phone phone = getPhone(subId);
1884 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001885 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001886 return true;
1887 } else {
1888 return false;
1889 }
1890 } finally {
1891 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 }
1894
Sanket Padawe356d7632015-06-22 14:03:32 -07001895 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001896 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001897 final long identity = Binder.clearCallingIdentity();
1898 try {
1899 final Phone phone = getPhone(subId);
1900 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001901 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001902 } else {
1903 return false;
1904 }
1905 } finally {
1906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 }
1909
1910 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001911 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001912 }
1913
pkanwarae03a6b2016-11-06 20:37:09 -08001914 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001915 enforceCallPermission();
1916
1917 final long identity = Binder.clearCallingIdentity();
1918 try {
1919 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1920 return;
1921 }
1922 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1923 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1924 } finally {
1925 Binder.restoreCallingIdentity(identity);
1926 }
pkanwar32d516d2016-10-14 19:37:38 -07001927 };
1928
Wink Savilleb564aae2014-10-23 10:18:09 -07001929 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001931
1932 final long identity = Binder.clearCallingIdentity();
1933 try {
1934 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1935 return false;
1936 }
1937 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1938 } finally {
1939 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001940 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
1942
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001944 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001945 }
1946
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001947 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001948 final long identity = Binder.clearCallingIdentity();
1949 try {
1950 Phone phone = PhoneFactory.getPhone(slotIndex);
1951 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1952 PhoneConstantConversions.convertCallState(phone.getState());
1953 } finally {
1954 Binder.restoreCallingIdentity(identity);
1955 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 }
1957
Sanket Padawe356d7632015-06-22 14:03:32 -07001958 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001959 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001960 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1961 }
1962
1963 @Override
1964 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001965 final long identity = Binder.clearCallingIdentity();
1966 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001967 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001968 if (phone != null) {
1969 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1970 } else {
1971 return PhoneConstantConversions.convertDataState(
1972 PhoneConstants.DataState.DISCONNECTED);
1973 }
1974 } finally {
1975 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 }
1978
Sanket Padawe356d7632015-06-22 14:03:32 -07001979 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001980 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001981 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1982 }
1983
1984 @Override
1985 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 final long identity = Binder.clearCallingIdentity();
1987 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001988 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001989 if (phone != null) {
1990 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1991 } else {
1992 return TelephonyManager.DATA_ACTIVITY_NONE;
1993 }
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 }
1998
1999 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002000 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002001 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002002 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002003
2004 LocationAccessPolicy.LocationPermissionResult locationResult =
2005 LocationAccessPolicy.checkLocationPermission(mApp,
2006 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2007 .setCallingPackage(callingPackage)
2008 .setCallingPid(Binder.getCallingPid())
2009 .setCallingUid(Binder.getCallingUid())
2010 .setMethod("getCellLocation")
2011 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2012 .build());
2013 switch (locationResult) {
2014 case DENIED_HARD:
2015 throw new SecurityException("Not allowed to access cell location");
2016 case DENIED_SOFT:
2017 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 }
2019
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002020 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002021 final long identity = Binder.clearCallingIdentity();
2022 try {
2023 if (DBG_LOC) log("getCellLocation: is active user");
2024 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002025 int subId = mSubscriptionController.getDefaultDataSubId();
2026 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2027 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002028 return data;
2029 } finally {
2030 Binder.restoreCallingIdentity(identity);
2031 }
Svetoslav64fad262015-04-14 14:35:21 -07002032 }
2033
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 @Override
Jack Yu7c5d91a2019-09-26 11:48:33 -07002035 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) {
2036 if (!TextUtils.isEmpty(callingPackage)) {
2037 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
2038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2039 mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) {
2040 return "";
2041 }
2042 }
2043
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002044 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2045 // registered cell info, so return a NULL country instead.
2046 final long identity = Binder.clearCallingIdentity();
2047 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002048 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2049 // Get default phone in this case.
2050 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2051 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002052 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002053 // Todo: fix this when we can get the actual cellular network info when the device
2054 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002055 if (TelephonyManager.NETWORK_TYPE_IWLAN
2056 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2057 return "";
2058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002059 Phone phone = PhoneFactory.getPhone(phoneId);
2060 if (phone != null) {
2061 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002062 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002063 if (sst != null) {
2064 LocaleTracker lt = sst.getLocaleTracker();
2065 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002066 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2067 return lt.getCurrentCountry();
2068 } else if (emergencyNumberTracker != null) {
2069 return emergencyNumberTracker.getEmergencyCountryIso();
2070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002071 }
2072 }
2073 }
2074 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002075 } finally {
2076 Binder.restoreCallingIdentity(identity);
2077 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002078 }
2079
2080 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002082 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002083 }
2084
Sanket Padawe356d7632015-06-22 14:03:32 -07002085 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002086 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 mApp.enforceCallingOrSelfPermission(
2088 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002089
2090 final long identity = Binder.clearCallingIdentity();
2091 try {
2092 final Phone phone = getPhone(subId);
2093 if (phone != null) {
2094 phone.enableLocationUpdates();
2095 }
2096 } finally {
2097 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002098 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 }
2100
2101 @Override
2102 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002103 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002104 }
2105
Sanket Padawe356d7632015-06-22 14:03:32 -07002106 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002107 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 mApp.enforceCallingOrSelfPermission(
2109 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002110
2111 final long identity = Binder.clearCallingIdentity();
2112 try {
2113 final Phone phone = getPhone(subId);
2114 if (phone != null) {
2115 phone.disableLocationUpdates();
2116 }
2117 } finally {
2118 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 }
2121
Nathan Harold31d7ff32018-10-15 20:20:30 -07002122 /**
2123 * Returns the target SDK version number for a given package name.
2124 *
Nathan Haroldec184742019-07-10 17:04:16 -07002125 * This call MUST be invoked before clearing the calling UID.
2126 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002127 * @return target SDK if the package is found or INT_MAX.
2128 */
2129 private int getTargetSdk(String packageName) {
2130 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002131 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002132 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002133 if (ai != null) return ai.targetSdkVersion;
2134 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002135 loge("Failed to get package info for pkg="
2136 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002137 }
2138 return Integer.MAX_VALUE;
2139 }
2140
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002141 @Override
2142 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002143 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2144 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002145 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2146 throw new SecurityException(
2147 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2148 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002149
Jordan Liu1617b712019-07-10 15:06:26 -07002150 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2152 return null;
2153 }
Svetoslav64fad262015-04-14 14:35:21 -07002154
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002155 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156
Nathan Haroldf180aac2018-06-01 18:43:55 -07002157 List<CellInfo> info = getAllCellInfo(callingPackage);
2158 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159
Nathan Haroldf180aac2018-06-01 18:43:55 -07002160 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2161 for (CellInfo ci : info) {
2162 if (ci instanceof CellInfoGsm) {
2163 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2164 } else if (ci instanceof CellInfoWcdma) {
2165 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002168 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 }
2170
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002171 private List<CellInfo> getCachedCellInfo() {
2172 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2173 for (Phone phone : PhoneFactory.getPhones()) {
2174 List<CellInfo> info = phone.getAllCellInfo();
2175 if (info != null) cellInfos.addAll(info);
2176 }
2177 return cellInfos;
2178 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179
2180 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002181 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002182 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002183 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002184
2185 LocationAccessPolicy.LocationPermissionResult locationResult =
2186 LocationAccessPolicy.checkLocationPermission(mApp,
2187 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2188 .setCallingPackage(callingPackage)
2189 .setCallingPid(Binder.getCallingPid())
2190 .setCallingUid(Binder.getCallingUid())
2191 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002192 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002193 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2194 .build());
2195 switch (locationResult) {
2196 case DENIED_HARD:
2197 throw new SecurityException("Not allowed to access cell info");
2198 case DENIED_SOFT:
2199 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
2201
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002202 final int targetSdk = getTargetSdk(callingPackage);
2203 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2204 return getCachedCellInfo();
2205 }
2206
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002207 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002208 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209 final long identity = Binder.clearCallingIdentity();
2210 try {
2211 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2212 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002213 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002214 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002215 if (info != null) cellInfos.addAll(info);
2216 }
2217 return cellInfos;
2218 } finally {
2219 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221 }
2222
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002223 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002224 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2225 requestCellInfoUpdateInternal(
2226 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2227 }
2228
2229 @Override
2230 public void requestCellInfoUpdateWithWorkSource(
2231 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2232 enforceModifyPermission();
2233 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2234 }
2235
2236 private void requestCellInfoUpdateInternal(
2237 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002238 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002239 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002240
2241 LocationAccessPolicy.LocationPermissionResult locationResult =
2242 LocationAccessPolicy.checkLocationPermission(mApp,
2243 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2244 .setCallingPackage(callingPackage)
2245 .setCallingPid(Binder.getCallingPid())
2246 .setCallingUid(Binder.getCallingUid())
2247 .setMethod("requestCellInfoUpdate")
2248 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2249 .build());
2250 switch (locationResult) {
2251 case DENIED_HARD:
2252 throw new SecurityException("Not allowed to access cell info");
2253 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002254 try {
2255 cb.onCellInfo(new ArrayList<CellInfo>());
2256 } catch (RemoteException re) {
2257 // Drop without consequences
2258 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002259 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002260 }
2261
Nathan Harolda939a962019-05-09 10:13:47 -07002262
2263 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002264 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2265
2266 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2267 }
2268
2269 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002271 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002272 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002273
2274 final long identity = Binder.clearCallingIdentity();
2275 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002276 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002277 } finally {
2278 Binder.restoreCallingIdentity(identity);
2279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 }
2281
Shishir Agrawala9f32182016-04-12 12:00:16 -07002282 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002283 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002284 Phone phone = PhoneFactory.getPhone(slotIndex);
2285 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002286 return null;
2287 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002288 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002289 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2290 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002291 return null;
2292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002293
2294 final long identity = Binder.clearCallingIdentity();
2295 try {
2296 return phone.getImei();
2297 } finally {
2298 Binder.restoreCallingIdentity(identity);
2299 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002300 }
2301
2302 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002303 public String getTypeAllocationCodeForSlot(int slotIndex) {
2304 Phone phone = PhoneFactory.getPhone(slotIndex);
2305 String tac = null;
2306 if (phone != null) {
2307 String imei = phone.getImei();
2308 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2309 }
2310 return tac;
2311 }
2312
2313 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002314 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002315 Phone phone = PhoneFactory.getPhone(slotIndex);
2316 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002317 return null;
2318 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002319
Jeff Davidson913390f2018-02-23 17:11:49 -08002320 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002321 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2322 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002323 return null;
2324 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002325
2326 final long identity = Binder.clearCallingIdentity();
2327 try {
2328 return phone.getMeid();
2329 } finally {
2330 Binder.restoreCallingIdentity(identity);
2331 }
Jack Yu2af8d712017-03-15 17:14:14 -07002332 }
2333
2334 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002335 public String getManufacturerCodeForSlot(int slotIndex) {
2336 Phone phone = PhoneFactory.getPhone(slotIndex);
2337 String manufacturerCode = null;
2338 if (phone != null) {
2339 String meid = phone.getMeid();
2340 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2341 }
2342 return manufacturerCode;
2343 }
2344
2345 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002346 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002347 Phone phone = PhoneFactory.getPhone(slotIndex);
2348 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002349 return null;
2350 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002351 int subId = phone.getSubId();
2352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2353 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2354 return null;
2355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002356
2357 final long identity = Binder.clearCallingIdentity();
2358 try {
2359 return phone.getDeviceSvn();
2360 } finally {
2361 Binder.restoreCallingIdentity(identity);
2362 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002363 }
2364
fionaxu43304da2017-11-27 22:51:16 -08002365 @Override
2366 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002367 final long identity = Binder.clearCallingIdentity();
2368 try {
2369 final Phone phone = getPhone(subId);
2370 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2371 } finally {
2372 Binder.restoreCallingIdentity(identity);
2373 }
fionaxu43304da2017-11-27 22:51:16 -08002374 }
2375
2376 @Override
2377 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 final Phone phone = getPhone(subId);
2381 return phone == null ? null : phone.getCarrierName();
2382 } finally {
2383 Binder.restoreCallingIdentity(identity);
2384 }
fionaxu43304da2017-11-27 22:51:16 -08002385 }
2386
calvinpanffe225e2018-11-01 19:43:06 +08002387 @Override
chen xu0026ca62019-03-06 15:28:50 -08002388 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002389 final long identity = Binder.clearCallingIdentity();
2390 try {
2391 final Phone phone = getPhone(subId);
2392 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002393 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002394 } finally {
2395 Binder.restoreCallingIdentity(identity);
2396 }
2397 }
2398
2399 @Override
chen xu0026ca62019-03-06 15:28:50 -08002400 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002401 final long identity = Binder.clearCallingIdentity();
2402 try {
2403 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002404 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002405 } finally {
2406 Binder.restoreCallingIdentity(identity);
2407 }
2408 }
2409
chen xu651eec72018-11-11 19:03:44 -08002410 @Override
chen xu864e11c2018-12-06 22:10:03 -08002411 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2412 if (!isSubscriptionMccMnc) {
2413 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2414 }
chen xu651eec72018-11-11 19:03:44 -08002415 final Phone phone = PhoneFactory.getPhone(slotIndex);
2416 if (phone == null) {
2417 return TelephonyManager.UNKNOWN_CARRIER_ID;
2418 }
2419 final long identity = Binder.clearCallingIdentity();
2420 try {
2421 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2422 } finally {
2423 Binder.restoreCallingIdentity(identity);
2424 }
2425 }
2426
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 //
2428 // Internal helper methods.
2429 //
2430
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002431 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2433 *
2434 * @throws SecurityException if the caller does not have the required permission
2435 */
2436 private void enforceModifyPermission() {
2437 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2438 }
2439
Shuo Qianf2b2df42019-11-13 17:43:31 -08002440 private void enforceActiveEmergencySessionPermission() {
2441 mApp.enforceCallingOrSelfPermission(
2442 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2443 }
2444
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 /**
2446 * Make sure the caller has the CALL_PHONE permission.
2447 *
2448 * @throws SecurityException if the caller does not have the required permission
2449 */
2450 private void enforceCallPermission() {
2451 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2452 }
2453
paulhu423b5f22019-08-23 19:17:33 +08002454 private void enforceSettingsPermission() {
2455 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002456 }
2457
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 private String createTelUrl(String number) {
2459 if (TextUtils.isEmpty(number)) {
2460 return null;
2461 }
2462
Jake Hambye994d462014-02-03 13:10:13 -08002463 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465
Ihab Awadf9e92732013-12-05 18:02:52 -08002466 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2468 }
2469
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002470 private static void logv(String msg) {
2471 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2472 }
2473
Ihab Awadf9e92732013-12-05 18:02:52 -08002474 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2476 }
2477
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002478 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002480 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002481 }
2482
Sanket Padawe356d7632015-06-22 14:03:32 -07002483 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002484 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002485 final long identity = Binder.clearCallingIdentity();
2486 try {
2487 final Phone phone = PhoneFactory.getPhone(slotIndex);
2488 if (phone == null) {
2489 return PhoneConstants.PHONE_TYPE_NONE;
2490 } else {
2491 return phone.getPhoneType();
2492 }
2493 } finally {
2494 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 }
2497
2498 /**
2499 * Returns the CDMA ERI icon index to display
2500 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002501 @Override
2502 public int getCdmaEriIconIndex(String callingPackage) {
2503 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002504 }
2505
Sanket Padawe356d7632015-06-22 14:03:32 -07002506 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002507 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002509 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002510 return -1;
2511 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512
2513 final long identity = Binder.clearCallingIdentity();
2514 try {
2515 final Phone phone = getPhone(subId);
2516 if (phone != null) {
2517 return phone.getCdmaEriIconIndex();
2518 } else {
2519 return -1;
2520 }
2521 } finally {
2522 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002524 }
2525
2526 /**
2527 * Returns the CDMA ERI icon mode,
2528 * 0 - ON
2529 * 1 - FLASHING
2530 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002531 @Override
2532 public int getCdmaEriIconMode(String callingPackage) {
2533 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002534 }
2535
Sanket Padawe356d7632015-06-22 14:03:32 -07002536 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002537 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002539 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002540 return -1;
2541 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542
2543 final long identity = Binder.clearCallingIdentity();
2544 try {
2545 final Phone phone = getPhone(subId);
2546 if (phone != null) {
2547 return phone.getCdmaEriIconMode();
2548 } else {
2549 return -1;
2550 }
2551 } finally {
2552 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 }
2555
2556 /**
2557 * Returns the CDMA ERI text,
2558 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002559 @Override
2560 public String getCdmaEriText(String callingPackage) {
2561 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002562 }
2563
Sanket Padawe356d7632015-06-22 14:03:32 -07002564 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002565 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002567 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002568 return null;
2569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 final Phone phone = getPhone(subId);
2574 if (phone != null) {
2575 return phone.getCdmaEriText();
2576 } else {
2577 return null;
2578 }
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 }
2583
2584 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002585 * Returns the CDMA MDN.
2586 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002587 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002588 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2590 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002591
2592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002595 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596 return phone.getLine1Number();
2597 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002598 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599 return null;
2600 }
2601 } finally {
2602 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002603 }
2604 }
2605
2606 /**
2607 * Returns the CDMA MIN.
2608 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002609 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002610 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2612 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613
2614 final long identity = Binder.clearCallingIdentity();
2615 try {
2616 final Phone phone = getPhone(subId);
2617 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2618 return phone.getCdmaMin();
2619 } else {
2620 return null;
2621 }
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002624 }
2625 }
2626
Hall Liud892bec2018-11-30 14:51:45 -08002627 @Override
2628 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2629 INumberVerificationCallback callback, String callingPackage) {
2630 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2631 != PERMISSION_GRANTED) {
2632 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2633 }
2634 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2635
2636 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2637 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2638 throw new SecurityException("Calling package must be configured in the device config");
2639 }
2640
2641 if (range == null) {
2642 throw new NullPointerException("Range must be non-null");
2643 }
2644
2645 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002646 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002647
2648 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2649 }
2650
Junda Liuca05d5d2014-08-14 22:36:34 -07002651 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652 * Returns true if CDMA provisioning needs to run.
2653 */
2654 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655 final long identity = Binder.clearCallingIdentity();
2656 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002657 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 } finally {
2659 Binder.restoreCallingIdentity(identity);
2660 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 }
2662
2663 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002664 * Sets the voice mail number of a given subId.
2665 */
2666 @Override
2667 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002668 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669
2670 final long identity = Binder.clearCallingIdentity();
2671 try {
2672 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2673 new Pair<String, String>(alphaTag, number), new Integer(subId));
2674 return success;
2675 } finally {
2676 Binder.restoreCallingIdentity(identity);
2677 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002678 }
2679
Ta-wei Yen87c49842016-05-13 21:19:52 -07002680 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002681 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2682 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002683 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2684 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002685 if (!TextUtils.equals(callingPackage, systemDialer)) {
2686 throw new SecurityException("caller must be system dialer");
2687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688
2689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2692 if (phoneAccountHandle == null) {
2693 return null;
2694 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002695 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696 } finally {
2697 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002698 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002699 }
2700
2701 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002702 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002705 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002706 return null;
2707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002709 final long identity = Binder.clearCallingIdentity();
2710 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002711 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002712 } finally {
2713 Binder.restoreCallingIdentity(identity);
2714 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002715 }
2716
2717 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002718 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2719 VisualVoicemailSmsFilterSettings settings) {
2720 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721
2722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002725 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 } finally {
2727 Binder.restoreCallingIdentity(identity);
2728 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002729 }
2730
2731 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002732 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2733 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734
2735 final long identity = Binder.clearCallingIdentity();
2736 try {
2737 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002738 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 } finally {
2740 Binder.restoreCallingIdentity(identity);
2741 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002742 }
2743
2744 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002745 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2746 String callingPackage, int subId) {
2747 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002748
2749 final long identity = Binder.clearCallingIdentity();
2750 try {
2751 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002752 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753 } finally {
2754 Binder.restoreCallingIdentity(identity);
2755 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002756 }
2757
2758 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002759 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002760 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002761
2762 final long identity = Binder.clearCallingIdentity();
2763 try {
2764 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002765 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766 } finally {
2767 Binder.restoreCallingIdentity(identity);
2768 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002769 }
2770
2771 @Override
2772 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2773 String number, int port, String text, PendingIntent sentIntent) {
2774 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002775 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002776 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002777 SmsController smsController = PhoneFactory.getSmsController();
2778 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2779 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002780 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002781
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002782 /**
fionaxu0152e512016-11-14 13:36:14 -08002783 * Sets the voice activation state of a given subId.
2784 */
2785 @Override
2786 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2788 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789
2790 final long identity = Binder.clearCallingIdentity();
2791 try {
2792 final Phone phone = getPhone(subId);
2793 if (phone != null) {
2794 phone.setVoiceActivationState(activationState);
2795 } else {
2796 loge("setVoiceActivationState fails with invalid subId: " + subId);
2797 }
2798 } finally {
2799 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002800 }
2801 }
2802
2803 /**
2804 * Sets the data activation state of a given subId.
2805 */
2806 @Override
2807 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2809 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810
2811 final long identity = Binder.clearCallingIdentity();
2812 try {
2813 final Phone phone = getPhone(subId);
2814 if (phone != null) {
2815 phone.setDataActivationState(activationState);
2816 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002817 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818 }
2819 } finally {
2820 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002821 }
2822 }
2823
2824 /**
2825 * Returns the voice activation state of a given subId.
2826 */
2827 @Override
2828 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002829 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830
fionaxu0152e512016-11-14 13:36:14 -08002831 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002832 final long identity = Binder.clearCallingIdentity();
2833 try {
2834 if (phone != null) {
2835 return phone.getVoiceActivationState();
2836 } else {
2837 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2838 }
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002841 }
2842 }
2843
2844 /**
2845 * Returns the data activation state of a given subId.
2846 */
2847 @Override
2848 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002849 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850
fionaxu0152e512016-11-14 13:36:14 -08002851 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 if (phone != null) {
2855 return phone.getDataActivationState();
2856 } else {
2857 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2858 }
2859 } finally {
2860 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002861 }
2862 }
2863
2864 /**
Wink Saville36469e72014-06-11 15:17:00 -07002865 * Returns the unread count of voicemails for a subId
2866 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002867 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002868 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2870 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2871 return 0;
2872 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 final Phone phone = getPhone(subId);
2876 if (phone != null) {
2877 return phone.getVoiceMessageCount();
2878 } else {
2879 return 0;
2880 }
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884 }
2885
2886 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002887 * returns true, if the device is in a state where both voice and data
2888 * are supported simultaneously. This can change based on location or network condition.
2889 */
2890 @Override
2891 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 final long identity = Binder.clearCallingIdentity();
2893 try {
2894 final Phone phone = getPhone(subId);
2895 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2896 } finally {
2897 Binder.restoreCallingIdentity(identity);
2898 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002899 }
2900
2901 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002902 * Send the dialer code if called from the current default dialer or the caller has
2903 * carrier privilege.
2904 * @param inputCode The dialer code to send
2905 */
2906 @Override
2907 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002908 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002909 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002910 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2911 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002912 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002913 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2914 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002915 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916
2917 final long identity = Binder.clearCallingIdentity();
2918 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002919 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920 } finally {
2921 Binder.restoreCallingIdentity(identity);
2922 }
fionaxu235cc5e2017-03-06 22:25:57 -08002923 }
2924
Pengquan Menga1bb6272018-09-06 09:59:22 -07002925 @Override
2926 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002927 if (!isActiveSubscription(subId)) {
2928 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2929 }
2930
Pengquan Menga1bb6272018-09-06 09:59:22 -07002931 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2932 }
2933
Brad Ebinger35c841c2018-10-01 10:40:55 -07002934 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002935 public boolean isInEmergencySmsMode() {
2936 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2937 final long identity = Binder.clearCallingIdentity();
2938 try {
2939 for (Phone phone : PhoneFactory.getPhones()) {
2940 if (phone.isInEmergencySmsMode()) {
2941 return true;
2942 }
2943 }
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
2946 }
2947 return false;
2948 }
2949
2950 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002951 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2952 throws RemoteException {
2953 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002954 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2955 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2956 "IMS not available on device.");
2957 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002958 final long token = Binder.clearCallingIdentity();
2959 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002960 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002961 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002962 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002963 } catch (ImsException e) {
2964 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002965 } finally {
2966 Binder.restoreCallingIdentity(token);
2967 }
2968 }
2969
2970 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002971 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2972 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002973 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2974 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2975 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002976 final long token = Binder.clearCallingIdentity();
2977 try {
2978 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2979 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2980 .removeRegistrationCallbackForSubscription(c, subId);
2981 } catch (ImsException e) {
2982 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2983 + "is inactive, ignoring unregister.");
2984 // If the subscription is no longer active, just return, since the callback
2985 // will already have been removed internally.
2986 } finally {
2987 Binder.restoreCallingIdentity(token);
2988 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002989 }
2990
Brad Ebinger774ba362019-10-22 17:36:18 -07002991 /**
2992 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2993 */
2994 @Override
2995 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2996 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2997 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2998 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2999 "IMS not available on device.");
3000 }
3001 final long token = Binder.clearCallingIdentity();
3002 try {
3003 Phone phone = getPhone(subId);
3004 if (phone == null) {
3005 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3006 + subId + "'");
3007 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3008 }
3009 phone.getImsRegistrationState(regState -> {
3010 try {
3011 consumer.accept((regState == null)
3012 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3013 } catch (RemoteException e) {
3014 // Ignore if the remote process is no longer available to call back.
3015 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3016 }
3017 });
3018 } finally {
3019 Binder.restoreCallingIdentity(token);
3020 }
3021 }
3022
3023 /**
3024 * Get the transport type for the IMS service registration state.
3025 */
3026 @Override
3027 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3028 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3029 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3030 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3031 "IMS not available on device.");
3032 }
3033 final long token = Binder.clearCallingIdentity();
3034 try {
3035 Phone phone = getPhone(subId);
3036 if (phone == null) {
3037 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3038 + subId + "'");
3039 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3040 }
3041 phone.getImsRegistrationTech(regTech -> {
3042 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3043 int regTechConverted = (regTech == null)
3044 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3045 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3046 regTechConverted);
3047 try {
3048 consumer.accept(regTechConverted);
3049 } catch (RemoteException e) {
3050 // Ignore if the remote process is no longer available to call back.
3051 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3052 }
3053 });
3054 } finally {
3055 Binder.restoreCallingIdentity(token);
3056 }
3057 }
3058
Brad Ebinger35c841c2018-10-01 10:40:55 -07003059 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003060 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3061 throws RemoteException {
3062 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003063 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3064 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3065 "IMS not available on device.");
3066 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003067 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3068 final long token = Binder.clearCallingIdentity();
3069 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003070 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003071 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003072 } catch (ImsException e) {
3073 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003074 } finally {
3075 Binder.restoreCallingIdentity(token);
3076 }
3077 }
3078
3079 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003080 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3081 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003082 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3083 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3084 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003085
3086 final long token = Binder.clearCallingIdentity();
3087 try {
3088 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3089 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003090 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003091 } catch (ImsException e) {
3092 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3093 + "is inactive, ignoring unregister.");
3094 // If the subscription is no longer active, just return, since the callback
3095 // will already have been removed internally.
3096 } finally {
3097 Binder.restoreCallingIdentity(token);
3098 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003099 }
3100
3101 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003102 public boolean isCapable(int subId, int capability, int regTech) {
3103 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003104 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3105 final long token = Binder.clearCallingIdentity();
3106 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003107 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003109 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003110 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3111 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003112 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003113 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3114 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003115 } finally {
3116 Binder.restoreCallingIdentity(token);
3117 }
3118 }
3119
3120 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003121 public boolean isAvailable(int subId, int capability, int regTech) {
3122 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003123 final long token = Binder.clearCallingIdentity();
3124 try {
3125 Phone phone = getPhone(subId);
3126 if (phone == null) return false;
3127 return phone.isImsCapabilityAvailable(capability, regTech);
3128 } finally {
3129 Binder.restoreCallingIdentity(token);
3130 }
3131 }
3132
Brad Ebinger77b832e2019-10-17 17:03:22 -07003133 /**
3134 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3135 * subscription.
3136 * @param subId The subscription to use to check the configuration.
3137 * @param callback The callback that will be used to send the result.
3138 * @param capability The MmTelFeature capability that will be used to send the result.
3139 * @param transportType The transport type of the MmTelFeature capability.
3140 */
3141 @Override
3142 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3143 int transportType) {
3144 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3145 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3146 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3147 "IMS not available on device.");
3148 }
3149 final long token = Binder.clearCallingIdentity();
3150 try {
3151 int slotId = getSlotIndex(subId);
3152 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3153 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3154 + subId + "'");
3155 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3156 }
3157 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3158 transportType, aBoolean -> {
3159 try {
3160 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3161 } catch (RemoteException e) {
3162 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3163 + "running. Ignore");
3164 }
3165 });
3166 } finally {
3167 Binder.restoreCallingIdentity(token);
3168 }
3169 }
3170
Brad Ebinger35c841c2018-10-01 10:40:55 -07003171 @Override
3172 public boolean isAdvancedCallingSettingEnabled(int subId) {
3173 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3174 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3175 final long token = Binder.clearCallingIdentity();
3176 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003177 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003178 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003179 } catch (ImsException e) {
3180 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003181 } finally {
3182 Binder.restoreCallingIdentity(token);
3183 }
3184 }
3185
3186 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003187 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003189 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003190 final long identity = Binder.clearCallingIdentity();
3191 try {
3192 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003193 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003194 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003195 } catch (ImsException e) {
3196 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003197 } finally {
3198 Binder.restoreCallingIdentity(identity);
3199 }
3200 }
3201
3202 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003203 public boolean isVtSettingEnabled(int subId) {
3204 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003205 final long identity = Binder.clearCallingIdentity();
3206 try {
3207 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003208 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3209 } catch (ImsException e) {
3210 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003211 } finally {
3212 Binder.restoreCallingIdentity(identity);
3213 }
3214 }
3215
3216 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003217 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003219 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003220 final long identity = Binder.clearCallingIdentity();
3221 try {
3222 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003223 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003224 } catch (ImsException e) {
3225 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003226 } finally {
3227 Binder.restoreCallingIdentity(identity);
3228 }
3229 }
3230
3231 @Override
3232 public boolean isVoWiFiSettingEnabled(int subId) {
3233 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3234 final long identity = Binder.clearCallingIdentity();
3235 try {
3236 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003237 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003238 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003239 } catch (ImsException e) {
3240 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 } finally {
3242 Binder.restoreCallingIdentity(identity);
3243 }
3244 }
3245
3246 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003247 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003249 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003250 final long identity = Binder.clearCallingIdentity();
3251 try {
3252 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003253 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003254 } catch (ImsException e) {
3255 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003256 } finally {
3257 Binder.restoreCallingIdentity(identity);
3258 }
3259 }
3260
3261 @Override
3262 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3263 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3264 final long identity = Binder.clearCallingIdentity();
3265 try {
3266 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003267 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003268 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003269 } catch (ImsException e) {
3270 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003271 } finally {
3272 Binder.restoreCallingIdentity(identity);
3273 }
3274 }
3275
3276 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003277 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003279 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003283 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003284 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003285 } catch (ImsException e) {
3286 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003287 } finally {
3288 Binder.restoreCallingIdentity(identity);
3289 }
3290 }
3291
3292 @Override
3293 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3295 "setVoWiFiNonPersistent");
3296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003299 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003300 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003301 } catch (ImsException e) {
3302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003303 } finally {
3304 Binder.restoreCallingIdentity(identity);
3305 }
3306 }
3307
3308 @Override
3309 public int getVoWiFiModeSetting(int subId) {
3310 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003314 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003315 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003316 } catch (ImsException e) {
3317 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
3321 }
3322
3323 @Override
3324 public void setVoWiFiModeSetting(int subId, int mode) {
3325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3326 "setVoWiFiModeSetting");
3327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003330 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003331 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003332 } catch (ImsException e) {
3333 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003334 } finally {
3335 Binder.restoreCallingIdentity(identity);
3336 }
3337 }
3338
3339 @Override
3340 public int getVoWiFiRoamingModeSetting(int subId) {
3341 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003345 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003346 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003347 } catch (ImsException e) {
3348 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 } finally {
3350 Binder.restoreCallingIdentity(identity);
3351 }
3352 }
3353
3354 @Override
3355 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3357 "setVoWiFiRoamingModeSetting");
3358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003361 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003362 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003363 } catch (ImsException e) {
3364 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 } finally {
3366 Binder.restoreCallingIdentity(identity);
3367 }
3368 }
3369
3370 @Override
3371 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3373 "setRttCapabilityEnabled");
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003377 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3378 } catch (ImsException e) {
3379 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003380 } finally {
3381 Binder.restoreCallingIdentity(identity);
3382 }
3383 }
3384
3385 @Override
3386 public boolean isTtyOverVolteEnabled(int subId) {
3387 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3388 final long identity = Binder.clearCallingIdentity();
3389 try {
3390 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003391 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003392 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003393 } catch (ImsException e) {
3394 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003395 } finally {
3396 Binder.restoreCallingIdentity(identity);
3397 }
3398 }
3399
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003400 @Override
3401 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3402 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3403 final long identity = Binder.clearCallingIdentity();
3404 try {
3405 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003406 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003407 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003408 } catch (ImsException e) {
3409 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003410 } finally {
3411 Binder.restoreCallingIdentity(identity);
3412 }
3413 }
3414
3415 @Override
3416 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3417 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3418 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003419 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3420 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3421 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003422 try {
3423 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003424 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003425 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003426 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003427 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3428 + "is inactive, ignoring unregister.");
3429 // If the subscription is no longer active, just return, since the callback will already
3430 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003431 } finally {
3432 Binder.restoreCallingIdentity(identity);
3433 }
3434 }
3435
3436 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003437 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3438 boolean isProvisioned) {
3439 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3440 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3441 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3442 }
3443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3444 "setProvisioningStatusForCapability");
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3448 Phone phone = getPhone(subId);
3449 if (phone == null) {
3450 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3451 + subId);
3452 return;
3453 }
3454 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3455 return;
3456 }
3457
3458 // this capability requires provisioning, route to the correct API.
3459 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3460 switch (capability) {
3461 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3462 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3463 ims.setVolteProvisioned(isProvisioned);
3464 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3465 ims.setWfcProvisioned(isProvisioned);
3466 }
3467 break;
3468 }
3469 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3470 // There is currently no difference in VT provisioning type.
3471 ims.setVtProvisioned(isProvisioned);
3472 break;
3473 }
3474 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3475 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3476 // change the capability of the feature instead if needed.
3477 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3478 == isProvisioned) {
3479 // No change in provisioning.
3480 return;
3481 }
3482 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3483 try {
3484 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003485 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003486 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3487 + ", Exception" + e.getMessage());
3488 }
3489 break;
3490 }
3491 default: {
3492 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3493 + capability + "', which does not require provisioning.");
3494 }
3495 }
3496
3497 } finally {
3498 Binder.restoreCallingIdentity(identity);
3499 }
3500 }
3501
3502 @Override
3503 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3504 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3505 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3506 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3507 }
3508 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3509 final long identity = Binder.clearCallingIdentity();
3510 try {
3511 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3512 Phone phone = getPhone(subId);
3513 if (phone == null) {
3514 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3515 + subId);
3516 // We will fail with "true" as the provisioning status because this is the default
3517 // if we do not require provisioning.
3518 return true;
3519 }
3520
3521 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3522 return true;
3523 }
3524
3525 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3526 switch (capability) {
3527 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3528 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3529 return ims.isVolteProvisionedOnDevice();
3530 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3531 return ims.isWfcProvisionedOnDevice();
3532 }
3533 // This should never happen, since we are checking tech above to make sure it
3534 // is either LTE or IWLAN.
3535 throw new IllegalArgumentException("Invalid radio technology for voice "
3536 + "capability.");
3537 }
3538 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3539 // There is currently no difference in VT provisioning type.
3540 return ims.isVtProvisionedOnDevice();
3541 }
3542 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3543 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3544 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3545 }
3546 default: {
3547 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3548 + capability + "', which does not require provisioning.");
3549 }
3550 }
3551
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
3554 }
3555 }
3556
3557 @Override
3558 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3559 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3560 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3561 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3562 }
3563 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3564 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3565 return (provisionedBits & capability) > 0;
3566 }
3567
3568 @Override
3569 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3570 boolean isProvisioned) {
3571 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3572 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3573 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3574 }
3575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3576 "setProvisioningStatusForCapability");
3577 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3578 // If the current provisioning status for capability already matches isProvisioned,
3579 // do nothing.
3580 if (((provisionedBits & capability) > 0) == isProvisioned) {
3581 return;
3582 }
3583 if (isProvisioned) {
3584 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3585 } else {
3586 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3587 }
3588 }
3589
3590 /**
3591 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3592 * technology. The bitfield should mirror the bitfield defined by
3593 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3594 */
3595 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3596 String key = getMmTelProvisioningKey(subId, tech);
3597 // Default is no capabilities are provisioned.
3598 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3599 }
3600
3601 /**
3602 * Sets the MmTel capability provisioning bitfield (defined by
3603 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3604 * technology specified.
3605 *
3606 * Note: This is a synchronous command and should not be called on UI thread.
3607 */
3608 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3609 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3610 String key = getMmTelProvisioningKey(subId, tech);
3611 editor.putInt(key, newField);
3612 editor.commit();
3613 }
3614
3615 private static String getMmTelProvisioningKey(int subId, int tech) {
3616 // resulting key is provision_ims_mmtel_{subId}_{tech}
3617 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3618 }
3619
3620 /**
3621 * Query CarrierConfig to see if the specified capability requires provisioning for the
3622 * carrier associated with the subscription id.
3623 */
3624 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3625 int capability) {
3626 CarrierConfigManager configManager = new CarrierConfigManager(context);
3627 PersistableBundle c = configManager.getConfigForSubId(subId);
3628 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003629 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003630 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3631 false);
3632 boolean requireVoiceVtProvisioning = c.getBoolean(
3633 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3634
3635 // First check to make sure that the capability requires provisioning.
3636 switch (capability) {
3637 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3638 // intentional fallthrough
3639 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3640 if (requireVoiceVtProvisioning) {
3641 // Voice and Video requires provisioning
3642 return true;
3643 }
3644 break;
3645 }
3646 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3647 if (requireUtProvisioning) {
3648 // UT requires provisioning
3649 return true;
3650 }
3651 break;
3652 }
3653 }
3654 return false;
3655 }
3656
3657 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003658 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003659 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3660 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3661 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003662 enforceReadPrivilegedPermission("getImsProvisioningInt");
3663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003666 int slotId = getSlotIndex(subId);
3667 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3668 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3669 + subId + "' for key:" + key);
3670 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3671 }
3672 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003673 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003674 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3675 + subId + "' for key:" + key);
3676 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003677 } finally {
3678 Binder.restoreCallingIdentity(identity);
3679 }
3680 }
3681
3682 @Override
3683 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003684 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3685 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3686 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003687 enforceReadPrivilegedPermission("getImsProvisioningString");
3688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003691 int slotId = getSlotIndex(subId);
3692 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3693 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3694 + subId + "' for key:" + key);
3695 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3696 }
3697 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003698 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003699 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3700 + subId + "' for key:" + key);
3701 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003702 } finally {
3703 Binder.restoreCallingIdentity(identity);
3704 }
3705 }
3706
3707 @Override
3708 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003709 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3710 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3711 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3713 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003714 final long identity = Binder.clearCallingIdentity();
3715 try {
3716 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003717 int slotId = getSlotIndex(subId);
3718 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3719 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3720 + subId + "' for key:" + key);
3721 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3722 }
3723 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003724 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003725 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3726 + "' for key:" + key);
3727 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003728 } finally {
3729 Binder.restoreCallingIdentity(identity);
3730 }
3731 }
3732
3733 @Override
3734 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003735 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3736 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3737 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3739 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003743 int slotId = getSlotIndex(subId);
3744 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3745 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3746 + subId + "' for key:" + key);
3747 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3748 }
3749 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003750 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003751 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3752 + "' for key:" + key);
3753 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003754 } finally {
3755 Binder.restoreCallingIdentity(identity);
3756 }
3757 }
3758
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003759 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003760 int slotId = SubscriptionManager.getSlotIndex(subId);
3761 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003762 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3763 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003764 }
3765 return slotId;
3766 }
3767
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003768 private int getSlotIndex(int subId) {
3769 int slotId = SubscriptionManager.getSlotIndex(subId);
3770 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3771 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3772 }
3773 return slotId;
3774 }
3775
Wink Saville36469e72014-06-11 15:17:00 -07003776 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003777 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003778 */
3779 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003780 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003781 final int targetSdk = getTargetSdk(callingPackage);
3782 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3783 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3784 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003785 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3786 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003787 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3788 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790 final long identity = Binder.clearCallingIdentity();
3791 try {
3792 final Phone phone = getPhone(subId);
3793 if (phone != null) {
3794 return phone.getServiceState().getDataNetworkType();
3795 } else {
3796 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3797 }
3798 } finally {
3799 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003800 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003801 }
3802
3803 /**
3804 * Returns the data network type
3805 */
3806 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003807 public int getDataNetworkType(String callingPackage) {
3808 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003809 }
3810
3811 /**
3812 * Returns the data network type for a subId
3813 */
3814 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003815 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003816 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003817 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003818 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3819 }
3820
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003821 final long identity = Binder.clearCallingIdentity();
3822 try {
3823 final Phone phone = getPhone(subId);
3824 if (phone != null) {
3825 return phone.getServiceState().getDataNetworkType();
3826 } else {
3827 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3828 }
3829 } finally {
3830 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003832 }
3833
3834 /**
Wink Saville36469e72014-06-11 15:17:00 -07003835 * Returns the Voice network type for a subId
3836 */
3837 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003838 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003839 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003840 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003841 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3842 }
3843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003844 final long identity = Binder.clearCallingIdentity();
3845 try {
3846 final Phone phone = getPhone(subId);
3847 if (phone != null) {
3848 return phone.getServiceState().getVoiceNetworkType();
3849 } else {
3850 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3851 }
3852 } finally {
3853 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003854 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003855 }
3856
3857 /**
3858 * @return true if a ICC card is present
3859 */
3860 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003861 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003862 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3863 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003864 }
3865
3866 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003867 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003868 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003869 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003870 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871 final long identity = Binder.clearCallingIdentity();
3872 try {
3873 final Phone phone = PhoneFactory.getPhone(slotIndex);
3874 if (phone != null) {
3875 return phone.getIccCard().hasIccCard();
3876 } else {
3877 return false;
3878 }
3879 } finally {
3880 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003882 }
3883
3884 /**
3885 * Return if the current radio is LTE on CDMA. This
3886 * is a tri-state return value as for a period of time
3887 * the mode may be unknown.
3888 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003889 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003890 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003891 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003892 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003893 @Override
3894 public int getLteOnCdmaMode(String callingPackage) {
3895 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003896 }
3897
Sanket Padawe356d7632015-06-22 14:03:32 -07003898 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003899 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003900 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003901 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003902 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3903 }
3904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003905 final long identity = Binder.clearCallingIdentity();
3906 try {
3907 final Phone phone = getPhone(subId);
3908 if (phone == null) {
3909 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3910 } else {
3911 return phone.getLteOnCdmaMode();
3912 }
3913 } finally {
3914 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003915 }
Wink Saville36469e72014-06-11 15:17:00 -07003916 }
3917
Wink Saville36469e72014-06-11 15:17:00 -07003918 /**
3919 * {@hide}
3920 * Returns Default subId, 0 in the case of single standby.
3921 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003922 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003923 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003924 }
3925
Shishir Agrawala9f32182016-04-12 12:00:16 -07003926 private int getSlotForDefaultSubscription() {
3927 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3928 }
3929
Wink Savilleb564aae2014-10-23 10:18:09 -07003930 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003931 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003932 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003933
Pengquan Menge92a50d2018-09-21 15:54:48 -07003934 private boolean isActiveSubscription(int subId) {
3935 return mSubscriptionController.isActiveSubId(subId);
3936 }
3937
Ihab Awadf2177b72013-11-25 13:33:23 -08003938 /**
3939 * @see android.telephony.TelephonyManager.WifiCallingChoices
3940 */
3941 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003942 final long identity = Binder.clearCallingIdentity();
3943 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003944 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003945 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3946 getWhenToMakeWifiCallsDefaultPreference());
3947 } finally {
3948 Binder.restoreCallingIdentity(identity);
3949 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003950 }
3951
3952 /**
3953 * @see android.telephony.TelephonyManager.WifiCallingChoices
3954 */
3955 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003956 final long identity = Binder.clearCallingIdentity();
3957 try {
3958 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003959 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003960 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3961 } finally {
3962 Binder.restoreCallingIdentity(identity);
3963 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003964 }
3965
Sailesh Nepald1e68152013-12-12 19:08:02 -08003966 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003967 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003968 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003969 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003970
Jordan Liu4c733742019-02-28 12:03:40 -08003971 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3972 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3973 if (phoneId == -1) {
3974 throw new IllegalArgumentException("Given slot index: " + slotIndex
3975 + " does not correspond to an active phone");
3976 }
3977 return PhoneFactory.getPhone(phoneId);
3978 }
3979
Shishir Agrawal566b7612013-10-28 14:41:00 -07003980 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003981 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3982 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3984 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003985 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003986 if (DBG) {
3987 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3988 }
3989 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3990 p2);
3991 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003992
Jordan Liu4c733742019-02-28 12:03:40 -08003993
3994 @Override
3995 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3996 int slotIndex, String callingPackage, String aid, int p2) {
3997 enforceModifyPermission();
3998 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3999 if (DBG) {
4000 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4001 }
4002 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4003 callingPackage, aid, p2);
4004 }
4005
4006 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4007 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 if (TextUtils.equals(ISDR_AID, aid)) {
4011 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004012 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4013 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 if (bestComponent == null
4015 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4016 loge("The calling package is not allowed to access ISD-R.");
4017 throw new SecurityException(
4018 "The calling package is not allowed to access ISD-R.");
4019 }
Derek Tan740e1672017-06-27 14:56:27 -07004020 }
Derek Tan740e1672017-06-27 14:56:27 -07004021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004022 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004023 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4024 null /* workSource */);
4025 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004026 return response;
4027 } finally {
4028 Binder.restoreCallingIdentity(identity);
4029 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004030 }
4031
4032 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004033 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4035 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004036 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4037 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4038 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004039
Jordan Liu4c733742019-02-28 12:03:40 -08004040 @Override
4041 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4042 enforceModifyPermission();
4043 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4044 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4045 channel);
4046 }
4047
4048 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049 final long identity = Binder.clearCallingIdentity();
4050 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051 if (channel < 0) {
4052 return false;
4053 }
Jordan Liu4c733742019-02-28 12:03:40 -08004054 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4055 null /* workSource */);
4056 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004057 return success;
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004060 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004061 }
4062
4063 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004064 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004065 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4067 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004068 if (DBG) {
4069 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4070 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4071 + p3 + " data=" + data);
4072 }
4073 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4074 command, p1, p2, p3, data);
4075 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004076
Jordan Liu4c733742019-02-28 12:03:40 -08004077 @Override
4078 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4079 int command, int p1, int p2, int p3, String data) {
4080 enforceModifyPermission();
4081 if (DBG) {
4082 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4083 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4084 + p3 + " data=" + data);
4085 }
4086 return iccTransmitApduLogicalChannelWithPermission(
4087 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4088 data);
4089 }
4090
4091 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4092 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093 final long identity = Binder.clearCallingIdentity();
4094 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004095 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096 return "";
4097 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004099 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004100 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4101 null /* workSource */);
4102 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104 // Append the returned status code to the end of the response payload.
4105 String s = Integer.toHexString(
4106 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4107 if (response.payload != null) {
4108 s = IccUtils.bytesToHexString(response.payload) + s;
4109 }
4110 return s;
4111 } finally {
4112 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004113 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004114 }
Jake Hambye994d462014-02-03 13:10:13 -08004115
Evan Charltonc66da362014-05-16 14:06:40 -07004116 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004117 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4118 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4120 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004122 if (DBG) {
4123 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4124 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4125 }
4126 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4127 cla, command, p1, p2, p3, data);
4128 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004129
Jordan Liu4c733742019-02-28 12:03:40 -08004130 @Override
4131 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4132 int command, int p1, int p2, int p3, String data) {
4133 enforceModifyPermission();
4134 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4135 if (DBG) {
4136 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4137 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4138 + " data=" + data);
4139 }
4140
4141 return iccTransmitApduBasicChannelWithPermission(
4142 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4143 p2, p3, data);
4144 }
4145
4146 // open APDU basic channel assuming the caller has sufficient permissions
4147 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4148 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4152 && TextUtils.equals(ISDR_AID, data)) {
4153 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004154 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4155 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004156 if (bestComponent == null
4157 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4158 loge("The calling package is not allowed to select ISD-R.");
4159 throw new SecurityException(
4160 "The calling package is not allowed to select ISD-R.");
4161 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004162 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004164 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004165 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4166 null /* workSource */);
4167 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004169 // Append the returned status code to the end of the response payload.
4170 String s = Integer.toHexString(
4171 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4172 if (response.payload != null) {
4173 s = IccUtils.bytesToHexString(response.payload) + s;
4174 }
4175 return s;
4176 } finally {
4177 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004178 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004179 }
4180
4181 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004182 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004183 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004184 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4185 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004187 final long identity = Binder.clearCallingIdentity();
4188 try {
4189 if (DBG) {
4190 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4191 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4192 }
4193
4194 IccIoResult response =
4195 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4196 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4197 subId);
4198
4199 if (DBG) {
4200 log("Exchange SIM_IO [R]" + response);
4201 }
4202
4203 byte[] result = null;
4204 int length = 2;
4205 if (response.payload != null) {
4206 length = 2 + response.payload.length;
4207 result = new byte[length];
4208 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4209 } else {
4210 result = new byte[length];
4211 }
4212
4213 result[length - 1] = (byte) response.sw2;
4214 result[length - 2] = (byte) response.sw1;
4215 return result;
4216 } finally {
4217 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004218 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004219 }
4220
Nathan Haroldb3014052017-01-25 15:57:32 -08004221 /**
4222 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4223 * on a particular subscription
4224 */
sqianb6e41952018-03-12 14:54:01 -07004225 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4226 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4227 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4228 return null;
4229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230
4231 final long identity = Binder.clearCallingIdentity();
4232 try {
4233 if (appType != TelephonyManager.APPTYPE_USIM
4234 && appType != TelephonyManager.APPTYPE_SIM) {
4235 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4236 return null;
4237 }
4238 Object response = sendRequest(
4239 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4240 if (response instanceof String[]) {
4241 return (String[]) response;
4242 }
yincheng zhaod698b842019-09-06 17:06:54 -07004243 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004244 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004245 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004246 } finally {
4247 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004248 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004249 }
4250
yincheng zhaod698b842019-09-06 17:06:54 -07004251 /**
4252 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4253 * subscription.
4254 *
4255 * @param subId the id of the subscription.
4256 * @param appType the uicc app type, must be USIM or SIM.
4257 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4258 * @param callingPackage the op Package name.
4259 * @return number of fplmns that is successfully written to the SIM.
4260 */
4261 public int setForbiddenPlmns(
4262 int subId, int appType, List<String> fplmns, String callingPackage) {
4263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4264 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4265 if (DBG) logv("no permissions for setForbiddenplmns");
4266 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4267 }
4268 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4269 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4270 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4271 }
4272 if (fplmns == null) {
4273 throw new IllegalArgumentException("Fplmn List provided is null");
4274 }
4275 for (String fplmn : fplmns) {
4276 if (!CellIdentity.isValidPlmn(fplmn)) {
4277 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4278 }
4279 }
4280 final long identity = Binder.clearCallingIdentity();
4281 try {
4282 Object response = sendRequest(
4283 CMD_SET_FORBIDDEN_PLMNS,
4284 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4285 subId);
4286 return (int) response;
4287 } finally {
4288 Binder.restoreCallingIdentity(identity);
4289 }
4290 }
4291
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004292 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004293 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4295 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004297 final long identity = Binder.clearCallingIdentity();
4298 try {
4299 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4300 if (response.payload == null) {
4301 return "";
4302 }
Evan Charltonc66da362014-05-16 14:06:40 -07004303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004304 // Append the returned status code to the end of the response payload.
4305 String s = Integer.toHexString(
4306 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4307 s = IccUtils.bytesToHexString(response.payload) + s;
4308 return s;
4309 } finally {
4310 Binder.restoreCallingIdentity(identity);
4311 }
Evan Charltonc66da362014-05-16 14:06:40 -07004312 }
4313
Jake Hambye994d462014-02-03 13:10:13 -08004314 /**
4315 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4316 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4317 *
4318 * @param itemID the ID of the item to read
4319 * @return the NV item as a String, or null on error.
4320 */
4321 @Override
4322 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004323 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4325 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004326
4327 final long identity = Binder.clearCallingIdentity();
4328 try {
4329 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004330 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004331 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4332 return value;
4333 } finally {
4334 Binder.restoreCallingIdentity(identity);
4335 }
Jake Hambye994d462014-02-03 13:10:13 -08004336 }
4337
4338 /**
4339 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4340 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4341 *
4342 * @param itemID the ID of the item to read
4343 * @param itemValue the value to write, as a String
4344 * @return true on success; false on any failure
4345 */
4346 @Override
4347 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004348 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4350 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004351
4352 final long identity = Binder.clearCallingIdentity();
4353 try {
4354 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4355 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004356 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4358 return success;
4359 } finally {
4360 Binder.restoreCallingIdentity(identity);
4361 }
Jake Hambye994d462014-02-03 13:10:13 -08004362 }
4363
4364 /**
4365 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4366 * Used for device configuration by some CDMA operators.
4367 *
4368 * @param preferredRoamingList byte array containing the new PRL
4369 * @return true on success; false on any failure
4370 */
4371 @Override
4372 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4374 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375
4376 final long identity = Binder.clearCallingIdentity();
4377 try {
4378 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4379 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4380 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4381 return success;
4382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
Jake Hambye994d462014-02-03 13:10:13 -08004385 }
4386
4387 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004388 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004389 * Used for device configuration by some CDMA operators.
4390 *
chen xu6dac5ab2018-10-26 17:39:23 -07004391 * @param slotIndex - device slot.
4392 *
Jake Hambye994d462014-02-03 13:10:13 -08004393 * @return true on success; false on any failure
4394 */
4395 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004396 public boolean resetModemConfig(int slotIndex) {
4397 Phone phone = PhoneFactory.getPhone(slotIndex);
4398 if (phone != null) {
4399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4400 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401
chen xu6dac5ab2018-10-26 17:39:23 -07004402 final long identity = Binder.clearCallingIdentity();
4403 try {
4404 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4405 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4406 return success;
4407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 }
chen xu6dac5ab2018-10-26 17:39:23 -07004411 return false;
4412 }
4413
4414 /**
4415 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4416 *
4417 * @param slotIndex - device slot.
4418 *
4419 * @return true on success; false on any failure
4420 */
4421 @Override
4422 public boolean rebootModem(int slotIndex) {
4423 Phone phone = PhoneFactory.getPhone(slotIndex);
4424 if (phone != null) {
4425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4426 mApp, phone.getSubId(), "rebootModem");
4427
4428 final long identity = Binder.clearCallingIdentity();
4429 try {
4430 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4431 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4432 return success;
4433 } finally {
4434 Binder.restoreCallingIdentity(identity);
4435 }
4436 }
4437 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004438 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004439
Svet Ganovb320e182015-04-16 12:30:10 -07004440 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004441 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004443 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004444 return new String[0];
4445 }
4446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 final long identity = Binder.clearCallingIdentity();
4448 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004449 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
Wink Saville36469e72014-06-11 15:17:00 -07004453 }
4454
Brad Ebinger51f743a2017-01-23 13:50:20 -08004455 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004456 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4457 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004458 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004459 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004460 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004461
4462 final long identity = Binder.clearCallingIdentity();
4463 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004464 ImsResolver resolver = PhoneFactory.getImsResolver();
4465 if (resolver == null) {
4466 // may happen if the device does not support IMS.
4467 return;
4468 }
4469 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004470 } finally {
4471 Binder.restoreCallingIdentity(identity);
4472 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004473 }
4474
4475 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004476 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4477 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004478 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004479 public void disableIms(int slotId) {
4480 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481
4482 final long identity = Binder.clearCallingIdentity();
4483 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004484 ImsResolver resolver = PhoneFactory.getImsResolver();
4485 if (resolver == null) {
4486 // may happen if the device does not support IMS.
4487 return;
4488 }
4489 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004490 } finally {
4491 Binder.restoreCallingIdentity(identity);
4492 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004493 }
4494
4495 /**
4496 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4497 * feature or {@link null} if the service is not available. If the feature is available, the
4498 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4499 */
4500 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004501 IImsServiceFeatureCallback callback) {
4502 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004503
4504 final long identity = Binder.clearCallingIdentity();
4505 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004506 ImsResolver resolver = PhoneFactory.getImsResolver();
4507 if (resolver == null) {
4508 // may happen if the device does not support IMS.
4509 return null;
4510 }
4511 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004512 } finally {
4513 Binder.restoreCallingIdentity(identity);
4514 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004515 }
4516
4517 /**
4518 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4519 * feature during emergency calling or {@link null} if the service is not available. If the
4520 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4521 * listener for feature updates.
4522 */
4523 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4524 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004525
4526 final long identity = Binder.clearCallingIdentity();
4527 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004528 ImsResolver resolver = PhoneFactory.getImsResolver();
4529 if (resolver == null) {
4530 // may happen if the device does not support IMS.
4531 return null;
4532 }
4533 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004534 } finally {
4535 Binder.restoreCallingIdentity(identity);
4536 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004537 }
4538
Brad Ebinger5f64b052017-12-14 14:26:15 -08004539 /**
4540 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004541 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004542 */
4543 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4544 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004545
4546 final long identity = Binder.clearCallingIdentity();
4547 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004548 ImsResolver resolver = PhoneFactory.getImsResolver();
4549 if (resolver == null) {
4550 // may happen if the device does not support IMS.
4551 return null;
4552 }
4553 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 } finally {
4555 Binder.restoreCallingIdentity(identity);
4556 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004557 }
4558
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004559 /**
4560 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004561 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004562 */
4563 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4564 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004565
4566 final long identity = Binder.clearCallingIdentity();
4567 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004568 ImsResolver resolver = PhoneFactory.getImsResolver();
4569 if (resolver == null) {
4570 // may happen if the device does not support IMS.
4571 return null;
4572 }
4573 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004574 } finally {
4575 Binder.restoreCallingIdentity(identity);
4576 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004577 }
4578
Brad Ebinger884c07b2018-02-15 16:17:40 -08004579 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004580 * Sets the ImsService Package Name that Telephony will bind to.
4581 *
4582 * @param slotId the slot ID that the ImsService should bind for.
4583 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4584 * ImsService is the device default ImsService.
4585 * @param packageName The package name of the application that contains the ImsService to bind
4586 * to.
4587 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4588 * @hide
4589 */
4590 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004591 int[] subIds = SubscriptionManager.getSubId(slotId);
4592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4593 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4594 "setImsService");
4595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004596 final long identity = Binder.clearCallingIdentity();
4597 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004598 ImsResolver resolver = PhoneFactory.getImsResolver();
4599 if (resolver == null) {
4600 // may happen if the device does not support IMS.
4601 return false;
4602 }
4603 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4604 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004605 } finally {
4606 Binder.restoreCallingIdentity(identity);
4607 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004608 }
4609
4610 /**
4611 * Return the ImsService configuration.
4612 *
4613 * @param slotId The slot that the ImsService is associated with.
4614 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4615 * the device default.
4616 * @return the package name of the ImsService configuration.
4617 */
4618 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004619 int[] subIds = SubscriptionManager.getSubId(slotId);
4620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4621 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4622 "getImsService");
4623
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 final long identity = Binder.clearCallingIdentity();
4625 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004626 ImsResolver resolver = PhoneFactory.getImsResolver();
4627 if (resolver == null) {
4628 // may happen if the device does not support IMS.
4629 return "";
4630 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004631 // TODO: change API to query RCS separately.
4632 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4633 ImsFeature.FEATURE_MMTEL);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004634 } finally {
4635 Binder.restoreCallingIdentity(identity);
4636 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004637 }
4638
Brad Ebinger77b832e2019-10-17 17:03:22 -07004639 /**
4640 * Get the MmTelFeature state associated with the requested subscription id.
4641 * @param subId The subscription that the MmTelFeature is associated with.
4642 * @param callback A callback with an integer containing the
4643 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4644 */
4645 @Override
4646 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4647 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4648 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4649 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4650 "IMS not available on device.");
4651 }
4652 final long token = Binder.clearCallingIdentity();
4653 try {
4654 int slotId = getSlotIndex(subId);
4655 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4656 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4657 + subId + "'");
4658 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4659 }
4660 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4661 try {
4662 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4663 } catch (RemoteException e) {
4664 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4665 + "Ignore");
4666 }
4667 });
4668 } finally {
4669 Binder.restoreCallingIdentity(token);
4670 }
4671 }
4672
Wink Saville36469e72014-06-11 15:17:00 -07004673 public void setImsRegistrationState(boolean registered) {
4674 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004675
4676 final long identity = Binder.clearCallingIdentity();
4677 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004678 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004679 } finally {
4680 Binder.restoreCallingIdentity(identity);
4681 }
Wink Saville36469e72014-06-11 15:17:00 -07004682 }
4683
4684 /**
Stuart Scott54788802015-03-30 13:18:01 -07004685 * Set the network selection mode to automatic.
4686 *
4687 */
4688 @Override
4689 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4691 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004692
Pengquan Menge92a50d2018-09-21 15:54:48 -07004693 if (!isActiveSubscription(subId)) {
4694 return;
4695 }
4696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004697 final long identity = Binder.clearCallingIdentity();
4698 try {
4699 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4700 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4701 } finally {
4702 Binder.restoreCallingIdentity(identity);
4703 }
Stuart Scott54788802015-03-30 13:18:01 -07004704 }
4705
Pengquan Mengea84e042018-09-20 14:57:26 -07004706 /**
4707 * Ask the radio to connect to the input network and change selection mode to manual.
4708 *
4709 * @param subId the id of the subscription.
4710 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4711 * the operator to attach to.
4712 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4713 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4714 * normal network selection next time.
4715 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004716 */
4717 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004718 public boolean setNetworkSelectionModeManual(
4719 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4721 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004722
4723 if (!isActiveSubscription(subId)) {
4724 return false;
4725 }
4726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 final long identity = Binder.clearCallingIdentity();
4728 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004729 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004730 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004731 if (DBG) {
4732 log("setNetworkSelectionModeManual: subId: " + subId
4733 + " operator: " + operatorInfo);
4734 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
4738 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004739 }
4740
4741 /**
4742 * Scans for available networks.
4743 */
4744 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004745 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4747 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004748 LocationAccessPolicy.LocationPermissionResult locationResult =
4749 LocationAccessPolicy.checkLocationPermission(mApp,
4750 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4751 .setCallingPackage(callingPackage)
4752 .setCallingPid(Binder.getCallingPid())
4753 .setCallingUid(Binder.getCallingUid())
4754 .setMethod("getCellNetworkScanResults")
4755 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4756 .build());
4757 switch (locationResult) {
4758 case DENIED_HARD:
4759 throw new SecurityException("Not allowed to access scan results -- location");
4760 case DENIED_SOFT:
4761 return null;
4762 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763
Pengquan Menga1bb6272018-09-06 09:59:22 -07004764 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765 try {
4766 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004767 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004768 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769 } finally {
4770 Binder.restoreCallingIdentity(identity);
4771 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004772 }
4773
4774 /**
yinxub1bed742017-04-17 11:45:04 -07004775 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004776 *
yinxub1bed742017-04-17 11:45:04 -07004777 * @param subId id of the subscription
4778 * @param request contains the radio access networks with bands/channels to scan
4779 * @param messenger callback messenger for scan results or errors
4780 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004781 * @return the id of the requested scan which can be used to stop the scan.
4782 */
4783 @Override
4784 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004785 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4787 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004788 LocationAccessPolicy.LocationPermissionResult locationResult =
4789 LocationAccessPolicy.checkLocationPermission(mApp,
4790 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4791 .setCallingPackage(callingPackage)
4792 .setCallingPid(Binder.getCallingPid())
4793 .setCallingUid(Binder.getCallingUid())
4794 .setMethod("requestNetworkScan")
4795 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4796 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004797 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004798 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004799 if (e != null) {
4800 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4801 throw e;
4802 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004803 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004804 return TelephonyScanManager.INVALID_SCAN_ID;
4805 }
4806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004807 }
Hall Liu912dfd32019-04-25 14:02:26 -07004808 int callingUid = Binder.getCallingUid();
4809 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004810 final long identity = Binder.clearCallingIdentity();
4811 try {
4812 return mNetworkScanRequestTracker.startNetworkScan(
4813 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004814 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004815 } finally {
4816 Binder.restoreCallingIdentity(identity);
4817 }
yinxu504e1392017-04-12 16:03:22 -07004818 }
4819
Hall Liub2ac8ef2019-02-28 15:56:23 -08004820 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004821 NetworkScanRequest request, int subId) {
4822 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4823 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4824 boolean hasNetworkScanPermission =
4825 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4826 == PERMISSION_GRANTED;
4827
4828 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4829 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4830 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004831 }
4832
4833 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4834 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004835 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4836 return new SecurityException("Specific channels must not be"
4837 + " scanned without location access.");
4838 }
4839 }
4840 }
4841
Hall Liub2ac8ef2019-02-28 15:56:23 -08004842 return null;
4843 }
4844
yinxu504e1392017-04-12 16:03:22 -07004845 /**
4846 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004847 *
4848 * @param subId id of the subscription
4849 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004850 */
4851 @Override
4852 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4854 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004855
Hall Liu912dfd32019-04-25 14:02:26 -07004856 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004857 final long identity = Binder.clearCallingIdentity();
4858 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004859 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860 } finally {
4861 Binder.restoreCallingIdentity(identity);
4862 }
yinxu504e1392017-04-12 16:03:22 -07004863 }
4864
4865 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004866 * Get the calculated preferred network type.
4867 * Used for debugging incorrect network type.
4868 *
4869 * @return the preferred network type, defined in RILConstants.java.
4870 */
4871 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004872 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004873 final Phone defaultPhone = getDefaultPhone();
4874 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4875 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004876 return RILConstants.PREFERRED_NETWORK_MODE;
4877 }
4878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004879 final long identity = Binder.clearCallingIdentity();
4880 try {
4881 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004882 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004883 } finally {
4884 Binder.restoreCallingIdentity(identity);
4885 }
Junda Liu84d15a22014-07-02 11:21:04 -07004886 }
4887
4888 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004889 * Get the preferred network type.
4890 * Used for device configuration by some CDMA operators.
4891 *
4892 * @return the preferred network type, defined in RILConstants.java.
4893 */
4894 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004895 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004896 TelephonyPermissions
4897 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4898 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004899
4900 final long identity = Binder.clearCallingIdentity();
4901 try {
4902 if (DBG) log("getPreferredNetworkType");
4903 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4904 int networkType = (result != null ? result[0] : -1);
4905 if (DBG) log("getPreferredNetworkType: " + networkType);
4906 return networkType;
4907 } finally {
4908 Binder.restoreCallingIdentity(identity);
4909 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004910 }
4911
4912 /**
4913 * Set the preferred network type.
4914 * Used for device configuration by some CDMA operators.
4915 *
4916 * @param networkType the preferred network type, defined in RILConstants.java.
4917 * @return true on success; false on any failure.
4918 */
4919 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004920 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4922 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923
4924 final long identity = Binder.clearCallingIdentity();
4925 try {
4926 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4927 Boolean success = (Boolean) sendRequest(
4928 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4929 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4930 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004931 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4933 }
4934 return success;
4935 } finally {
4936 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004937 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004938 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004939
4940 /**
Miaoa84611c2019-03-15 09:21:10 +08004941 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004942 *
Miaoa84611c2019-03-15 09:21:10 +08004943 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004944 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004945 * @hide
4946 */
4947 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004948 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004949 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004951 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 try {
Miaoa84611c2019-03-15 09:21:10 +08004953 if (phone != null) {
4954 return phone.hasMatchedTetherApnSetting();
4955 } else {
4956 return false;
4957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004958 } finally {
4959 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004960 }
Junda Liu475951f2014-11-07 16:45:03 -08004961 }
4962
4963 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004964 * Set mobile data enabled
4965 * Used by the user through settings etc to turn on/off mobile data
4966 *
4967 * @param enable {@code true} turn turn data on, else {@code false}
4968 */
4969 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004970 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4972 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973
4974 final long identity = Binder.clearCallingIdentity();
4975 try {
4976 int phoneId = mSubscriptionController.getPhoneId(subId);
4977 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4978 Phone phone = PhoneFactory.getPhone(phoneId);
4979 if (phone != null) {
4980 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004981 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004983 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984 }
4985 } finally {
4986 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004987 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004988 }
4989
4990 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004991 * Get the user enabled state of Mobile Data.
4992 *
4993 * TODO: remove and use isUserDataEnabled.
4994 * This can't be removed now because some vendor codes
4995 * calls through ITelephony directly while they should
4996 * use TelephonyManager.
4997 *
4998 * @return true on enabled
4999 */
5000 @Override
5001 public boolean getDataEnabled(int subId) {
5002 return isUserDataEnabled(subId);
5003 }
5004
5005 /**
5006 * Get whether mobile data is enabled per user setting.
5007 *
5008 * There are other factors deciding whether mobile data is actually enabled, but they are
5009 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005010 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005011 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005012 *
5013 * @return {@code true} if data is enabled else {@code false}
5014 */
5015 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005016 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005017 try {
5018 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5019 null);
5020 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5022 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005023 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024
5025 final long identity = Binder.clearCallingIdentity();
5026 try {
5027 int phoneId = mSubscriptionController.getPhoneId(subId);
5028 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5029 Phone phone = PhoneFactory.getPhone(phoneId);
5030 if (phone != null) {
5031 boolean retVal = phone.isUserDataEnabled();
5032 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5033 return retVal;
5034 } else {
5035 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5036 return false;
5037 }
5038 } finally {
5039 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005040 }
5041 }
5042
5043 /**
5044 * Get whether mobile data is enabled.
5045 *
5046 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5047 * whether mobile data is actually enabled.
5048 *
5049 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5050 *
5051 * @return {@code true} if data is enabled else {@code false}
5052 */
5053 @Override
5054 public boolean isDataEnabled(int subId) {
5055 try {
5056 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5057 null);
5058 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5060 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005062
5063 final long identity = Binder.clearCallingIdentity();
5064 try {
5065 int phoneId = mSubscriptionController.getPhoneId(subId);
5066 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5067 Phone phone = PhoneFactory.getPhone(phoneId);
5068 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005069 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5071 return retVal;
5072 } else {
5073 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5074 return false;
5075 }
5076 } finally {
5077 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005078 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005079 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005080
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005081 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5082 Phone phone) {
5083 //load access rules from carrier configs, and check those as well: b/139133814
5084 SubscriptionController subController = SubscriptionController.getInstance();
5085 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5086 || subController == null) return privilegeFromSim;
5087
5088 int uid = Binder.getCallingUid();
5089 PackageManager pkgMgr = phone.getContext().getPackageManager();
5090 String[] packages = pkgMgr.getPackagesForUid(uid);
5091
5092 final long identity = Binder.clearCallingIdentity();
5093 try {
5094 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5095 SubscriptionManager subManager = (SubscriptionManager)
5096 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5097 for (String pkg : packages) {
5098 if (subManager.canManageSubscription(subInfo, pkg)) {
5099 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5100 }
5101 }
5102 return privilegeFromSim;
5103 } finally {
5104 Binder.restoreCallingIdentity(identity);
5105 }
5106 }
5107
5108 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5109 String pkgName) {
5110 //load access rules from carrier configs, and check those as well: b/139133814
5111 SubscriptionController subController = SubscriptionController.getInstance();
5112 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5113 || subController == null) return privilegeFromSim;
5114
5115 final long identity = Binder.clearCallingIdentity();
5116 try {
5117 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5118 SubscriptionManager subManager = (SubscriptionManager)
5119 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5120 return subManager.canManageSubscription(subInfo, pkgName)
5121 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5122 } finally {
5123 Binder.restoreCallingIdentity(identity);
5124 }
5125 }
5126
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005127 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005128 public int getCarrierPrivilegeStatus(int subId) {
5129 final Phone phone = getPhone(subId);
5130 if (phone == null) {
5131 loge("getCarrierPrivilegeStatus: Invalid subId");
5132 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5133 }
5134 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005135 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005136 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005137 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5138 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005139
5140 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5141 card.getCarrierPrivilegeStatusForCurrentTransaction(
5142 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005143 }
Junda Liu29340342014-07-10 15:23:27 -07005144
5145 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005146 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5147 final Phone phone = getPhone(subId);
5148 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005149 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005150 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5151 }
5152 UiccProfile profile =
5153 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5154 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005155 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005156 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5157 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005158 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5159 profile.getCarrierPrivilegeStatusForUid(
5160 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005161 }
5162
5163 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005164 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5165 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005166 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005167 }
5168
5169 int phoneId = SubscriptionManager.getPhoneId(subId);
5170 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005171 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005172 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005173 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5174 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005175 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5176 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5177 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005178 }
5179
5180 @Override
5181 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005182 if (TextUtils.isEmpty(pkgName))
5183 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005184 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5185 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5186 UiccCard card = UiccController.getInstance().getUiccCard(i);
5187 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005188 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005189 continue;
5190 }
5191
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005192 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5193 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5194 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005195 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5196 break;
5197 }
5198 }
5199
5200 return result;
Junda Liu29340342014-07-10 15:23:27 -07005201 }
Derek Tan89e89d42014-07-08 17:00:10 -07005202
5203 @Override
Junda Liue64de782015-04-16 17:19:16 -07005204 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5205 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5206 loge("phoneId " + phoneId + " is not valid.");
5207 return null;
5208 }
5209 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005210 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005211 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005212 return null ;
5213 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005214 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005215 }
5216
Amith Yamasani6e118872016-02-19 12:53:51 -08005217 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005218 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005219 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005220 List<String> privilegedPackages = new ArrayList<>();
5221 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005222 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5223 // has UICC in that slot.
5224 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005225 if (card.hasCarrierPrivilegeRules()) {
5226 if (packages == null) {
5227 // Only check packages in user 0 for now
5228 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005229 PackageManager.MATCH_DISABLED_COMPONENTS
5230 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005231 | PackageManager.GET_SIGNING_CERTIFICATES,
5232 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005233 }
5234 for (int p = packages.size() - 1; p >= 0; p--) {
5235 PackageInfo pkgInfo = packages.get(p);
5236 if (pkgInfo != null && pkgInfo.packageName != null
5237 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005238 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005239 privilegedPackages.add(pkgInfo.packageName);
5240 }
5241 }
5242 }
5243 }
5244 return privilegedPackages;
5245 }
5246
chen xuf7e9fe82019-05-09 19:31:02 -07005247 @Override
5248 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005249 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5250
5251 final long identity = Binder.clearCallingIdentity();
5252
chen xuf7e9fe82019-05-09 19:31:02 -07005253 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005254 try {
5255 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5256 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5257 }
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005260 }
5261 return privilegedPackages;
5262 }
5263
Wink Savilleb564aae2014-10-23 10:18:09 -07005264 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005265 final Phone phone = getPhone(subId);
5266 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005267 if (card == null) {
5268 loge("getIccId: No UICC");
5269 return null;
5270 }
5271 String iccId = card.getIccId();
5272 if (TextUtils.isEmpty(iccId)) {
5273 loge("getIccId: ICC ID is null or empty.");
5274 return null;
5275 }
5276 return iccId;
5277 }
5278
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005279 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005280 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5281 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005282 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5283 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 final long identity = Binder.clearCallingIdentity();
5286 try {
5287 final String iccId = getIccId(subId);
5288 final Phone phone = getPhone(subId);
5289 if (phone == null) {
5290 return false;
5291 }
5292 final String subscriberId = phone.getSubscriberId();
5293
5294 if (DBG_MERGE) {
5295 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5296 + subscriberId + " to " + number);
5297 }
5298
5299 if (TextUtils.isEmpty(iccId)) {
5300 return false;
5301 }
5302
5303 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5304
5305 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5306 if (alphaTag == null) {
5307 editor.remove(alphaTagPrefKey);
5308 } else {
5309 editor.putString(alphaTagPrefKey, alphaTag);
5310 }
5311
5312 // Record both the line number and IMSI for this ICCID, since we need to
5313 // track all merged IMSIs based on line number
5314 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5315 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5316 if (number == null) {
5317 editor.remove(numberPrefKey);
5318 editor.remove(subscriberPrefKey);
5319 } else {
5320 editor.putString(numberPrefKey, number);
5321 editor.putString(subscriberPrefKey, subscriberId);
5322 }
5323
5324 editor.commit();
5325 return true;
5326 } finally {
5327 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005328 }
Derek Tan7226c842014-07-02 17:42:23 -07005329 }
5330
5331 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005332 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005333 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005334 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005335 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005336 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005337 return null;
5338 }
Derek Tan97ebb422014-09-05 16:55:38 -07005339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340 final long identity = Binder.clearCallingIdentity();
5341 try {
5342 String iccId = getIccId(subId);
5343 if (iccId != null) {
5344 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5345 if (DBG_MERGE) {
5346 log("getLine1NumberForDisplay returning "
5347 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5348 }
5349 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005350 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5352 return null;
5353 } finally {
5354 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005355 }
Derek Tan7226c842014-07-02 17:42:23 -07005356 }
5357
5358 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005359 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005360 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005361 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005362 return null;
5363 }
Derek Tan97ebb422014-09-05 16:55:38 -07005364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005365 final long identity = Binder.clearCallingIdentity();
5366 try {
5367 String iccId = getIccId(subId);
5368 if (iccId != null) {
5369 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5370 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5371 }
5372 return null;
5373 } finally {
5374 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005375 }
Derek Tan7226c842014-07-02 17:42:23 -07005376 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005377
5378 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005379 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005380 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5381 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005382 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005383 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5384 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005385 return null;
5386 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005387
Jordan Liub49b04b2019-05-06 14:45:15 -07005388 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5389 // the process, where TelephonyManager was instantiated.
5390 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005391 final long identity = Binder.clearCallingIdentity();
5392 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005393 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 final TelephonyManager tele = TelephonyManager.from(context);
5395 final SubscriptionManager sub = SubscriptionManager.from(context);
5396
5397 // Figure out what subscribers are currently active
5398 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399
Jordan Liub49b04b2019-05-06 14:45:15 -07005400 // Only consider subs which match the current subId
5401 // This logic can be simplified. See b/131189269 for progress.
5402 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005403 activeSubscriberIds.add(tele.getSubscriberId(subId));
5404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405
5406 // First pass, find a number override for an active subscriber
5407 String mergeNumber = null;
5408 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5409 for (String key : prefs.keySet()) {
5410 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5411 final String subscriberId = (String) prefs.get(key);
5412 if (activeSubscriberIds.contains(subscriberId)) {
5413 final String iccId = key.substring(
5414 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5415 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5416 mergeNumber = (String) prefs.get(numberKey);
5417 if (DBG_MERGE) {
5418 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5419 + " for active subscriber " + subscriberId);
5420 }
5421 if (!TextUtils.isEmpty(mergeNumber)) {
5422 break;
5423 }
5424 }
5425 }
5426 }
5427
5428 // Shortcut when no active merged subscribers
5429 if (TextUtils.isEmpty(mergeNumber)) {
5430 return null;
5431 }
5432
5433 // Second pass, find all subscribers under that line override
5434 final ArraySet<String> result = new ArraySet<>();
5435 for (String key : prefs.keySet()) {
5436 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5437 final String number = (String) prefs.get(key);
5438 if (mergeNumber.equals(number)) {
5439 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5440 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5441 final String subscriberId = (String) prefs.get(subscriberKey);
5442 if (!TextUtils.isEmpty(subscriberId)) {
5443 result.add(subscriberId);
5444 }
5445 }
5446 }
5447 }
5448
5449 final String[] resultArray = result.toArray(new String[result.size()]);
5450 Arrays.sort(resultArray);
5451 if (DBG_MERGE) {
5452 Slog.d(LOG_TAG,
5453 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5454 }
5455 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005456 } finally {
5457 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005458 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005459 }
5460
5461 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005462 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5463 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5464
5465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 final TelephonyManager telephonyManager = mApp.getSystemService(
5468 TelephonyManager.class);
5469 String subscriberId = telephonyManager.getSubscriberId(subId);
5470 if (subscriberId == null) {
5471 if (DBG) {
5472 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5473 + subId);
5474 }
5475 return null;
5476 }
5477
5478 final SubscriptionInfo info = SubscriptionController.getInstance()
5479 .getSubscriptionInfo(subId);
5480 final ParcelUuid groupUuid = info.getGroupUuid();
5481 // If it doesn't belong to any group, return just subscriberId of itself.
5482 if (groupUuid == null) {
5483 return new String[]{subscriberId};
5484 }
5485
5486 // Get all subscriberIds from the group.
5487 final List<String> mergedSubscriberIds = new ArrayList<>();
5488 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5489 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5490 for (SubscriptionInfo subInfo : groupInfos) {
5491 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5492 if (subscriberId != null) {
5493 mergedSubscriberIds.add(subscriberId);
5494 }
5495 }
5496
5497 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5498 } finally {
5499 Binder.restoreCallingIdentity(identity);
5500
5501 }
5502 }
5503
5504 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005505 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005506 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5507 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508
5509 final long identity = Binder.clearCallingIdentity();
5510 try {
5511 final Phone phone = getPhone(subId);
5512 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5513 } finally {
5514 Binder.restoreCallingIdentity(identity);
5515 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005516 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005517
5518 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005519 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005520 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5521 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005522 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523
5524 final long identity = Binder.clearCallingIdentity();
5525 try {
5526 final Phone phone = getPhone(subId);
5527 if (phone == null) {
5528 return false;
5529 }
5530 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5531 cdmaNonRoamingList);
5532 } finally {
5533 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005534 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005535 }
5536
5537 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005538 @Deprecated
5539 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5540 enforceModifyPermission();
5541
5542 int returnValue = 0;
5543 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005544 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005545 if(result.exception == null) {
5546 if (result.result != null) {
5547 byte[] responseData = (byte[])(result.result);
5548 if(responseData.length > oemResp.length) {
5549 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5550 responseData.length + "bytes. Buffer Size is " +
5551 oemResp.length + "bytes.");
5552 }
5553 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5554 returnValue = responseData.length;
5555 }
5556 } else {
5557 CommandException ex = (CommandException) result.exception;
5558 returnValue = ex.getCommandError().ordinal();
5559 if(returnValue > 0) returnValue *= -1;
5560 }
5561 } catch (RuntimeException e) {
5562 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5563 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5564 if(returnValue > 0) returnValue *= -1;
5565 }
5566
5567 return returnValue;
5568 }
5569
5570 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005571 public void setRadioCapability(RadioAccessFamily[] rafs) {
5572 try {
5573 ProxyController.getInstance().setRadioCapability(rafs);
5574 } catch (RuntimeException e) {
5575 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5576 }
5577 }
5578
5579 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005580 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005581 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005582 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005583 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005584 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005585 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586 final long identity = Binder.clearCallingIdentity();
5587 try {
chen xub97461a2018-10-26 14:17:57 -07005588 TelephonyPermissions
5589 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5590 mApp, phone.getSubId(), "getRadioAccessFamily");
5591 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 } finally {
5593 Binder.restoreCallingIdentity(identity);
5594 }
chen xub97461a2018-10-26 14:17:57 -07005595 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005596 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005597
5598 @Override
5599 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005600 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005601 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602
5603 final long identity = Binder.clearCallingIdentity();
5604 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005605 ImsManager.getInstance(defaultPhone.getContext(),
5606 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607 } finally {
5608 Binder.restoreCallingIdentity(identity);
5609 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005610 }
5611
5612 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005613 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005614 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005615 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005616 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005617 return false;
5618 }
Svet Ganovb320e182015-04-16 12:30:10 -07005619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 final long identity = Binder.clearCallingIdentity();
5621 try {
5622 // Check the user preference and the system-level IMS setting. Even if the user has
5623 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5624 // In the long run, we may instead need to check if there exists a connection service
5625 // which can support video calling.
5626 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005627 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628 return imsManager.isVtEnabledByPlatform()
5629 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5630 && imsManager.isVtEnabledByUser();
5631 } finally {
5632 Binder.restoreCallingIdentity(identity);
5633 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005634 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005635
Andrew Leea1239f22015-03-02 17:44:07 -08005636 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5638 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5639 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5640 return false;
5641 }
5642
5643 final long identity = Binder.clearCallingIdentity();
5644 try {
5645 CarrierConfigManager configManager =
5646 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005647 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5649 } finally {
5650 Binder.restoreCallingIdentity(identity);
5651 }
Andrew Leea1239f22015-03-02 17:44:07 -08005652 }
5653
5654 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655 public boolean isWorldPhone(int subId, String callingPackage) {
5656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5657 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5658 return false;
5659 }
5660
5661 final long identity = Binder.clearCallingIdentity();
5662 try {
5663 CarrierConfigManager configManager =
5664 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005665 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5667 } finally {
5668 Binder.restoreCallingIdentity(identity);
5669 }
Andrew Leea1239f22015-03-02 17:44:07 -08005670 }
5671
Andrew Lee9431b832015-03-09 18:46:45 -07005672 @Override
5673 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005674 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005675 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005676 }
5677
5678 @Override
5679 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 final long identity = Binder.clearCallingIdentity();
5681 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005682 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
Andrew Lee9431b832015-03-09 18:46:45 -07005686 }
5687
Hall Liuf6668912018-10-31 17:05:23 -07005688 /**
5689 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5690 * support for the feature and device firmware support.
5691 *
5692 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5693 */
5694 @Override
5695 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005697 final Phone phone = getPhone(subscriptionId);
5698 if (phone == null) {
5699 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5700 return false;
5701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005703 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5705 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005706 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707 return isCarrierSupported && isDeviceSupported;
5708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
Hall Liu98187582018-01-22 19:15:32 -08005711 }
5712
Hall Liuf6668912018-10-31 17:05:23 -07005713 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005714 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5715 * RTT setting, will return true if the device and carrier both support RTT.
5716 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005717 */
5718 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719 final long identity = Binder.clearCallingIdentity();
5720 try {
Hall Liu81eb08c2019-10-29 16:50:20 -07005721 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 } finally {
5723 Binder.restoreCallingIdentity(identity);
5724 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005725 }
5726
Sanket Padawe7310cc72015-01-14 09:53:20 -08005727 /**
5728 * Returns the unique device ID of phone, for example, the IMEI for
5729 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5730 *
5731 * <p>Requires Permission:
5732 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5733 */
5734 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005735 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005736 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005737 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005738 return null;
5739 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005740 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005741 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5742 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005743 return null;
5744 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745
5746 final long identity = Binder.clearCallingIdentity();
5747 try {
5748 return phone.getDeviceId();
5749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005752 }
5753
Ping Sunc67b7c22016-03-02 19:16:45 +08005754 /**
5755 * {@hide}
5756 * Returns the IMS Registration Status on a particular subid
5757 *
5758 * @param subId
5759 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005760 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005761 Phone phone = getPhone(subId);
5762 if (phone != null) {
5763 return phone.isImsRegistered();
5764 } else {
5765 return false;
5766 }
5767 }
5768
Santos Cordon7a1885b2015-02-03 11:15:19 -08005769 @Override
5770 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 final long identity = Binder.clearCallingIdentity();
5772 try {
5773 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5774 } finally {
5775 Binder.restoreCallingIdentity(identity);
5776 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005777 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005778
Tyler Gunnf70ed162019-04-03 15:28:53 -07005779 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005780 public int getSubIdForPhoneAccountHandle(
5781 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5782 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5783 callingPackage, "getSubIdForPhoneAccountHandle")) {
5784 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5785 }
5786 final long identity = Binder.clearCallingIdentity();
5787 try {
5788 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5789 } finally {
5790 Binder.restoreCallingIdentity(identity);
5791 }
5792 }
5793
5794 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005795 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5796 final long identity = Binder.clearCallingIdentity();
5797 try {
5798 Phone phone = getPhone(subscriptionId);
5799 if (phone == null) {
5800 return null;
5801 }
5802 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5803 } finally {
5804 Binder.restoreCallingIdentity(identity);
5805 }
5806 }
5807
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005808 /**
5809 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005810 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005811 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812 final long identity = Binder.clearCallingIdentity();
5813 try {
5814 Phone phone = getPhone(subId);
5815 if (phone != null) {
5816 return phone.isWifiCallingEnabled();
5817 } else {
5818 return false;
5819 }
5820 } finally {
5821 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005822 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005823 }
5824
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005825 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005826 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005827 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005828 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005829 final long identity = Binder.clearCallingIdentity();
5830 try {
5831 Phone phone = getPhone(subId);
5832 if (phone != null) {
5833 return phone.isVideoEnabled();
5834 } else {
5835 return false;
5836 }
5837 } finally {
5838 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005839 }
5840 }
5841
5842 /**
5843 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5844 * defined in {@link ImsRegistrationImplBase}.
5845 */
5846 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847 final long identity = Binder.clearCallingIdentity();
5848 try {
5849 Phone phone = getPhone(subId);
5850 if (phone != null) {
5851 return phone.getImsRegistrationTech();
5852 } else {
5853 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5854 }
5855 } finally {
5856 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005857 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005858 }
5859
Stuart Scott8eef64f2015-04-08 15:13:54 -07005860 @Override
5861 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08005862 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005863 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5864 return;
5865 }
5866
Svet Ganovcc087f82015-05-12 20:35:54 -07005867 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005868
Svet Ganovcc087f82015-05-12 20:35:54 -07005869 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005870 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5871 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005872 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005873 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005874 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005875 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5876 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005877 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005878 // There has been issues when Sms raw table somehow stores orphan
5879 // fragments. They lead to garbled message when new fragments come
5880 // in and combined with those stale ones. In case this happens again,
5881 // user can reset all network settings which will clean up this table.
5882 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005883 // Clean up IMS settings as well here.
5884 int slotId = getSlotIndex(subId);
5885 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5886 ImsManager.getInstance(mApp, slotId).factoryReset();
5887 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07005888
5889 // Erase modem config if erase modem on network setting is enabled.
5890 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5891 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5892 if (configValue != null && Boolean.parseBoolean(configValue)) {
5893 sendEraseModemConfig(getDefaultPhone());
5894 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005895 } finally {
5896 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005897 }
5898 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005899
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005900 private void cleanUpSmsRawTable(Context context) {
5901 ContentResolver resolver = context.getContentResolver();
5902 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5903 resolver.delete(uri, null, null);
5904 }
5905
Narayan Kamath1c496c22015-04-16 14:40:19 +01005906 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005907 public String getSimLocaleForSubscriber(int subId) {
5908 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5909 final Phone phone = getPhone(subId);
5910 if (phone == null) {
5911 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005912 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914 final long identity = Binder.clearCallingIdentity();
5915 try {
chen xu5d3637b2019-01-21 23:31:38 -08005916 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5917 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005918 if (info == null) {
5919 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5920 return null;
5921 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922 // Try and fetch the locale from the carrier properties or from the SIM language
5923 // preferences (EF-PL and EF-LI)...
5924 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005926 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5927 if (localeFromDefaultSim != null) {
5928 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5929 if (DBG) log("Using locale from subId: " + subId + " locale: "
5930 + localeFromDefaultSim);
5931 return localeFromDefaultSim.toLanguageTag();
5932 } else {
5933 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934 }
5935 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937 // The SIM language preferences only store a language (e.g. fr = French), not an
5938 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5939 // the SIM and carrier preferences does not include a country we add the country
5940 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005941 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005942 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005943 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944 return mccLocale.toLanguageTag();
5945 }
5946
5947 if (DBG) log("No locale found - returning null");
5948 return null;
5949 } finally {
5950 Binder.restoreCallingIdentity(identity);
5951 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005952 }
5953
5954 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005955 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005956 }
5957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 /**
5959 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5960 */
5961 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005962 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005963 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005964
Chenjie Yu1ba97252018-01-11 18:16:20 -08005965 private final ModemActivityInfo mLastModemActivityInfo =
5966 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5967
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005968 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005969 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5970 * representing the state of the modem.
5971 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005972 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5973 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005974 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005975 */
5976 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005977 public void requestModemActivityInfo(ResultReceiver result) {
5978 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005979 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980
5981 final long identity = Binder.clearCallingIdentity();
5982 try {
5983 ModemActivityInfo ret = null;
5984 synchronized (mLastModemActivityInfo) {
5985 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5986 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005987 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005988 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005989 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5990 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005991 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5992 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 }
5994 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005995 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5996 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 mLastModemActivityInfo.setIdleTimeMillis(
5998 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5999 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
6000 mLastModemActivityInfo.setRxTimeMillis(
6001 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
6002 mLastModemActivityInfo.setEnergyUsed(
6003 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6006 mLastModemActivityInfo.getSleepTimeMillis(),
6007 mLastModemActivityInfo.getIdleTimeMillis(),
6008 mLastModemActivityInfo.getTxTimeMillis(),
6009 mLastModemActivityInfo.getRxTimeMillis(),
6010 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 Bundle bundle = new Bundle();
6013 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6014 result.send(0, bundle);
6015 } finally {
6016 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006017 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006018 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006019
Siddharth Rayb8114062018-06-17 15:02:38 -07006020 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6021 // less than total activity duration.
6022 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6023 if (info == null) {
6024 return false;
6025 }
6026 int activityDurationMs =
6027 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6028 int totalTxTimeMs = 0;
6029 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
6030 totalTxTimeMs += info.getTxTimeMillis()[i];
6031 }
6032 return (info.isValid()
6033 && (info.getSleepTimeMillis() <= activityDurationMs)
6034 && (info.getIdleTimeMillis() <= activityDurationMs)
6035 && (info.getRxTimeMillis() <= activityDurationMs)
6036 && (totalTxTimeMs <= activityDurationMs));
6037 }
6038
Jack Yu85bd38a2015-11-09 11:34:32 -08006039 /**
6040 * {@hide}
6041 * Returns the service state information on specified subscription.
6042 */
6043 @Override
6044 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006046 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006047 return null;
6048 }
6049
Hall Liuf19c44f2018-11-27 14:38:17 -08006050 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6051 LocationAccessPolicy.checkLocationPermission(mApp,
6052 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6053 .setCallingPackage(callingPackage)
6054 .setCallingPid(Binder.getCallingPid())
6055 .setCallingUid(Binder.getCallingUid())
6056 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006057 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006058 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6059 .build());
6060
6061 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6062 LocationAccessPolicy.checkLocationPermission(mApp,
6063 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6064 .setCallingPackage(callingPackage)
6065 .setCallingPid(Binder.getCallingPid())
6066 .setCallingUid(Binder.getCallingUid())
6067 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006068 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006069 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6070 .build());
6071 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6072 boolean hasFinePermission =
6073 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6074 boolean hasCoarsePermission =
6075 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 final long identity = Binder.clearCallingIdentity();
6078 try {
6079 final Phone phone = getPhone(subId);
6080 if (phone == null) {
6081 return null;
6082 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006083
Hall Liuf19c44f2018-11-27 14:38:17 -08006084 ServiceState ss = phone.getServiceState();
6085
6086 // Scrub out the location info in ServiceState depending on what level of access
6087 // the caller has.
6088 if (hasFinePermission) return ss;
6089 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6090 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 } finally {
6092 Binder.restoreCallingIdentity(identity);
6093 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006094 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006095
6096 /**
6097 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6098 *
6099 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6100 * voicemail ringtone.
6101 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6102 * PhoneAccount.
6103 */
6104 @Override
6105 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106 final long identity = Binder.clearCallingIdentity();
6107 try {
6108 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6109 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006110 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6114 } finally {
6115 Binder.restoreCallingIdentity(identity);
6116 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006117 }
6118
6119 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006120 * Sets the per-account voicemail ringtone.
6121 *
6122 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6123 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6124 *
6125 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6126 * voicemail ringtone.
6127 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6128 * PhoneAccount.
6129 */
6130 @Override
6131 public void setVoicemailRingtoneUri(String callingPackage,
6132 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006133 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006134 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006135 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6136 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6138 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6139 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141
6142 final long identity = Binder.clearCallingIdentity();
6143 try {
6144 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6145 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006146 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006147 }
6148 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6149 } finally {
6150 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006151 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006152 }
6153
6154 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006155 * Returns whether vibration is set for voicemail notification in Phone settings.
6156 *
6157 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6158 * voicemail vibration setting.
6159 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6160 */
6161 @Override
6162 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 final long identity = Binder.clearCallingIdentity();
6164 try {
6165 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6166 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006167 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006170 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6171 } finally {
6172 Binder.restoreCallingIdentity(identity);
6173 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006174 }
6175
Youhan Wange64578a2016-05-02 15:32:42 -07006176 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006177 * Sets the per-account voicemail vibration.
6178 *
6179 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6180 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6181 *
6182 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6183 * voicemail vibration setting.
6184 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6185 * specific PhoneAccount.
6186 */
6187 @Override
6188 public void setVoicemailVibrationEnabled(String callingPackage,
6189 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006190 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006191 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006192 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6193 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006194 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6195 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6196 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006197 }
6198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006199 final long identity = Binder.clearCallingIdentity();
6200 try {
6201 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6202 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006203 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204 }
6205 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6206 } finally {
6207 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006208 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006209 }
6210
6211 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006212 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6213 *
6214 * @throws SecurityException if the caller does not have the required permission
6215 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006216 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006217 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006218 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006219 }
6220
6221 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006222 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6223 * permission.
6224 *
6225 * @throws SecurityException if the caller does not have the required permission
6226 */
6227 private void enforceSendSmsPermission() {
6228 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6229 }
6230
6231 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006232 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006233 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006234 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006235 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006236 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 final long identity = Binder.clearCallingIdentity();
6238 try {
6239 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006240 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 if (componentName == null) {
6242 throw new SecurityException(
6243 "Caller not current active visual voicemail package[null]");
6244 }
6245 String vvmPackage = componentName.getPackageName();
6246 if (!callingPackage.equals(vvmPackage)) {
6247 throw new SecurityException("Caller not current active visual voicemail package["
6248 + vvmPackage + "]");
6249 }
6250 } finally {
6251 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006252 }
6253 }
6254
6255 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006256 * Return the application ID for the app type.
6257 *
6258 * @param subId the subscription ID that this request applies to.
6259 * @param appType the uicc app type.
6260 * @return Application ID for specificied app type, or null if no uicc.
6261 */
6262 @Override
6263 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006264 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006265 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266
6267 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006268 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006269 if (phone == null) {
6270 return null;
6271 }
6272 String aid = null;
6273 try {
6274 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6275 .getApplicationByType(appType).getAid();
6276 } catch (Exception e) {
6277 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6278 }
6279 return aid;
6280 } finally {
6281 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006282 }
Youhan Wange64578a2016-05-02 15:32:42 -07006283 }
6284
Youhan Wang4001d252016-05-11 10:29:41 -07006285 /**
6286 * Return the Electronic Serial Number.
6287 *
6288 * @param subId the subscription ID that this request applies to.
6289 * @return ESN or null if error.
6290 */
6291 @Override
6292 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006293 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006294 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006295
6296 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006297 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 if (phone == null) {
6299 return null;
6300 }
6301 String esn = null;
6302 try {
6303 esn = phone.getEsn();
6304 } catch (Exception e) {
6305 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6306 }
6307 return esn;
6308 } finally {
6309 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006310 }
Youhan Wang4001d252016-05-11 10:29:41 -07006311 }
6312
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006313 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006314 * Return the Preferred Roaming List Version.
6315 *
6316 * @param subId the subscription ID that this request applies to.
6317 * @return PRLVersion or null if error.
6318 */
6319 @Override
6320 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006321 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006322 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006323
6324 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006325 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006326 if (phone == null) {
6327 return null;
6328 }
6329 String cdmaPrlVersion = null;
6330 try {
6331 cdmaPrlVersion = phone.getCdmaPrlVersion();
6332 } catch (Exception e) {
6333 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6334 }
6335 return cdmaPrlVersion;
6336 } finally {
6337 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006338 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006339 }
6340
6341 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006342 * Get snapshot of Telephony histograms
6343 * @return List of Telephony histograms
6344 * @hide
6345 */
6346 @Override
6347 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6349 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006350
6351 final long identity = Binder.clearCallingIdentity();
6352 try {
6353 return RIL.getTelephonyRILTimingHistograms();
6354 } finally {
6355 Binder.restoreCallingIdentity(identity);
6356 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006357 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006358
6359 /**
6360 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006361 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6362 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006363 * Require system privileges. In the future we may add this to carrier APIs.
6364 *
Michele Berionne482f8202018-11-27 18:57:59 -08006365 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006366 */
6367 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006368 @TelephonyManager.SetCarrierRestrictionResult
6369 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006370 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006371 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006372
Michele Berionne482f8202018-11-27 18:57:59 -08006373 if (carrierRestrictionRules == null) {
6374 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006375 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377 final long identity = Binder.clearCallingIdentity();
6378 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006379 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006380 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381 } finally {
6382 Binder.restoreCallingIdentity(identity);
6383 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006384 }
6385
6386 /**
6387 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006388 * Get the allowed carrier list and the excluded carrier list, including the priority between
6389 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006390 * Require system privileges. In the future we may add this to carrier APIs.
6391 *
Michele Berionne482f8202018-11-27 18:57:59 -08006392 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006393 */
6394 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006395 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006396 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006397 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006398
6399 final long identity = Binder.clearCallingIdentity();
6400 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006401 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6402 if (response instanceof CarrierRestrictionRules) {
6403 return (CarrierRestrictionRules) response;
6404 }
6405 // Response is an Exception of some kind,
6406 // which is signalled to the user as a NULL retval
6407 return null;
6408 } catch (Exception e) {
6409 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6410 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006414 }
6415
fionaxu59545b42016-05-25 15:53:37 -07006416 /**
6417 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6418 * @param subId the subscription ID that this action applies to.
6419 * @param enabled control enable or disable metered apns.
6420 * {@hide}
6421 */
6422 @Override
6423 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6424 enforceModifyPermission();
6425 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006426
6427 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006428 if (phone == null) {
6429 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6430 return;
6431 }
6432 try {
6433 phone.carrierActionSetMeteredApnsEnabled(enabled);
6434 } catch (Exception e) {
6435 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006436 } finally {
6437 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006438 }
6439 }
6440
6441 /**
6442 * Action set from carrier signalling broadcast receivers to enable/disable radio
6443 * @param subId the subscription ID that this action applies to.
6444 * @param enabled control enable or disable radio.
6445 * {@hide}
6446 */
6447 @Override
6448 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6449 enforceModifyPermission();
6450 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006451
6452 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006453 if (phone == null) {
6454 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6455 return;
6456 }
6457 try {
6458 phone.carrierActionSetRadioEnabled(enabled);
6459 } catch (Exception e) {
6460 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006461 } finally {
6462 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006463 }
6464 }
6465
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006466 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006467 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6468 * network status based on which carrier apps could apply actions accordingly,
6469 * enable/disable default url handler for example.
6470 *
6471 * @param subId the subscription ID that this action applies to.
6472 * @param report control start/stop reporting the default network status.
6473 * {@hide}
6474 */
6475 @Override
6476 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6477 enforceModifyPermission();
6478 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006479
6480 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006481 if (phone == null) {
6482 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6483 return;
6484 }
6485 try {
6486 phone.carrierActionReportDefaultNetworkStatus(report);
6487 } catch (Exception e) {
6488 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489 } finally {
6490 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006491 }
6492 }
6493
6494 /**
fionaxud9622282017-07-17 17:51:30 -07006495 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6496 * @param subId the subscription ID that this action applies to.
6497 * {@hide}
6498 */
6499 @Override
6500 public void carrierActionResetAll(int subId) {
6501 enforceModifyPermission();
6502 final Phone phone = getPhone(subId);
6503 if (phone == null) {
6504 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6505 return;
6506 }
6507 try {
6508 phone.carrierActionResetAll();
6509 } catch (Exception e) {
6510 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6511 }
6512 }
6513
6514 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006515 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6516 * bug report is being generated.
6517 */
6518 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006519 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006520 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6521 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006522 writer.println("Permission Denial: can't dump Phone from pid="
6523 + Binder.getCallingPid()
6524 + ", uid=" + Binder.getCallingUid()
6525 + "without permission "
6526 + android.Manifest.permission.DUMP);
6527 return;
6528 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006529 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006530 }
Jack Yueb89b242016-06-22 13:27:47 -07006531
Brad Ebingerdac2f002018-04-03 15:17:52 -07006532 @Override
6533 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6534 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6535 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006536 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6537 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006538 }
6539
Jack Yueb89b242016-06-22 13:27:47 -07006540 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006541 * Get aggregated video call data usage since boot.
6542 *
6543 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6544 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006545 * {@hide}
6546 */
6547 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006548 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006549 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6550 null);
6551
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552 final long identity = Binder.clearCallingIdentity();
6553 try {
6554 // NetworkStatsService keeps tracking the active network interface and identity. It
6555 // records the delta with the corresponding network identity.
6556 // We just return the total video call data usage snapshot since boot.
6557 Phone phone = getPhone(subId);
6558 if (phone != null) {
6559 return phone.getVtDataUsage(perUidStats);
6560 }
6561 return null;
6562 } finally {
6563 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006564 }
Jack Yueb89b242016-06-22 13:27:47 -07006565 }
Jack Yu75ab2952016-07-08 14:29:33 -07006566
6567 /**
6568 * Policy control of data connection. Usually used when data limit is passed.
6569 * @param enabled True if enabling the data, otherwise disabling.
6570 * @param subId Subscription index
6571 * {@hide}
6572 */
6573 @Override
6574 public void setPolicyDataEnabled(boolean enabled, int subId) {
6575 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006576
6577 final long identity = Binder.clearCallingIdentity();
6578 try {
6579 Phone phone = getPhone(subId);
6580 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006581 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 }
6583 } finally {
6584 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006585 }
6586 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006587
6588 /**
6589 * Get Client request stats
6590 * @return List of Client Request Stats
6591 * @hide
6592 */
6593 @Override
6594 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006596 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006597 return null;
6598 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006599 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601 final long identity = Binder.clearCallingIdentity();
6602 try {
6603 if (phone != null) {
6604 return phone.getClientRequestStats();
6605 }
6606
6607 return null;
6608 } finally {
6609 Binder.restoreCallingIdentity(identity);
6610 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006611 }
6612
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006613 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006614 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006615 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006616 }
Jack Yueb4124c2017-02-16 15:32:43 -08006617
6618 /**
Grace Chen70990072017-03-24 17:21:30 -07006619 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006620 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006621 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006622 * @param state State of SIM (power down, power up, pass through)
6623 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6624 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6625 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006626 *
6627 **/
6628 @Override
Grace Chen70990072017-03-24 17:21:30 -07006629 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006630 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006631 Phone phone = PhoneFactory.getPhone(slotIndex);
6632
vagdeviaf9a5b92018-08-15 16:01:53 -07006633 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006635 final long identity = Binder.clearCallingIdentity();
6636 try {
6637 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006638 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 }
6640 } finally {
6641 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006642 }
6643 }
Shuo Qiandd210312017-04-12 22:11:33 +00006644
Tyler Gunn65d45c22017-06-05 11:22:26 -07006645 private boolean isUssdApiAllowed(int subId) {
6646 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006647 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006648 if (configManager == null) {
6649 return false;
6650 }
6651 PersistableBundle pb = configManager.getConfigForSubId(subId);
6652 if (pb == null) {
6653 return false;
6654 }
6655 return pb.getBoolean(
6656 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6657 }
6658
Shuo Qiandd210312017-04-12 22:11:33 +00006659 /**
6660 * Check if phone is in emergency callback mode
6661 * @return true if phone is in emergency callback mode
6662 * @param subId sub id
6663 */
goneil9c5f4872017-12-05 14:07:56 -08006664 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006665 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006666 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006667 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668
6669 final long identity = Binder.clearCallingIdentity();
6670 try {
6671 if (phone != null) {
6672 return phone.isInEcm();
6673 } else {
6674 return false;
6675 }
6676 } finally {
6677 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006678 }
6679 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006680
6681 /**
6682 * Get the current signal strength information for the given subscription.
6683 * Because this information is not updated when the device is in a low power state
6684 * it should not be relied-upon to be current.
6685 * @param subId Subscription index
6686 * @return the most recent cached signal strength info from the modem
6687 */
6688 @Override
6689 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006690 final long identity = Binder.clearCallingIdentity();
6691 try {
6692 Phone p = getPhone(subId);
6693 if (p == null) {
6694 return null;
6695 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006697 return p.getSignalStrength();
6698 } finally {
6699 Binder.restoreCallingIdentity(identity);
6700 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006701 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006702
Pengquan Meng77b7f132018-08-22 14:49:57 -07006703 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006704 * Get the current modem radio state for the given slot.
6705 * @param slotIndex slot index.
6706 * @param callingPackage the name of the package making the call.
6707 * @return the current radio power state from the modem
6708 */
6709 @Override
6710 public int getRadioPowerState(int slotIndex, String callingPackage) {
6711 Phone phone = PhoneFactory.getPhone(slotIndex);
6712 if (phone != null) {
6713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6714 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6715 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6716 }
6717
6718 final long identity = Binder.clearCallingIdentity();
6719 try {
6720 return phone.getRadioPowerState();
6721 } finally {
6722 Binder.restoreCallingIdentity(identity);
6723 }
6724 }
6725 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6726 }
6727
6728 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006729 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6730 *
6731 * <p>Requires one of the following permissions:
6732 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6733 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6734 * privileges.
6735 *
6736 * @param subId subscription id
6737 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6738 * {@code false}.
6739 */
6740 @Override
6741 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006742 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6743 null /* message */);
6744
Pengquan Menga1bb6272018-09-06 09:59:22 -07006745 boolean isEnabled = false;
6746 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006747 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006748 Phone phone = getPhone(subId);
6749 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006750 } catch (Exception e) {
6751 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6752 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006753 } finally {
6754 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006755 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006756 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006757 }
6758
6759
6760 /**
6761 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6762 *
6763 * <p> Requires permission:
6764 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6765 * privileges.
6766 *
6767 * @param subId subscription id
6768 * @param isEnabled {@code true} means enable, {@code false} means disable.
6769 */
6770 @Override
6771 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6773 mApp, subId, "setDataRoamingEnabled");
6774
Pengquan Menga1bb6272018-09-06 09:59:22 -07006775 final long identity = Binder.clearCallingIdentity();
6776 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006777 Phone phone = getPhone(subId);
6778 if (phone != null) {
6779 phone.setDataRoamingEnabled(isEnabled);
6780 }
6781 } finally {
6782 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006783 }
6784 }
6785
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006786 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006787 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006788 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6789 mApp, subId, "isManualNetworkSelectionAllowed");
6790
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006791 boolean isAllowed = true;
6792 final long identity = Binder.clearCallingIdentity();
6793 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006794 Phone phone = getPhone(subId);
6795 if (phone != null) {
6796 isAllowed = phone.isCspPlmnEnabled();
6797 }
6798 } finally {
6799 Binder.restoreCallingIdentity(identity);
6800 }
6801 return isAllowed;
6802 }
6803
6804 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006805 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006806 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006807 try {
6808 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006809 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006810 } catch (SecurityException e) {
6811 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6812 // has carrier privileges on an active UICC
6813 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6814 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006815 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006816 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006817 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006818
6819 final long identity = Binder.clearCallingIdentity();
6820 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006821 UiccController uiccController = UiccController.getInstance();
6822 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006823 if (hasReadPermission) {
6824 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006825 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006826
6827 // Remove private info if the caller doesn't have access
6828 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6829 for (UiccCardInfo cardInfo : cardInfos) {
6830 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6831 // is available
6832 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6833 if (card == null || card.getUiccProfile() == null) {
6834 // assume no access if the card or profile is unavailable
6835 filteredInfos.add(cardInfo.getUnprivileged());
6836 continue;
6837 }
6838 UiccProfile profile = card.getUiccProfile();
6839 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6840 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6841 filteredInfos.add(cardInfo);
6842 } else {
6843 filteredInfos.add(cardInfo.getUnprivileged());
6844 }
6845 }
6846 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006847 } finally {
6848 Binder.restoreCallingIdentity(identity);
6849 }
6850 }
6851
6852 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006853 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006854 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006855
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006856 final long identity = Binder.clearCallingIdentity();
6857 try {
6858 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6859 if (slots == null) {
6860 Rlog.i(LOG_TAG, "slots is null.");
6861 return null;
6862 }
6863
6864 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6865 for (int i = 0; i < slots.length; i++) {
6866 UiccSlot slot = slots[i];
6867 if (slot == null) {
6868 continue;
6869 }
6870
Jordan Liu7be7e652019-05-06 18:55:02 +00006871 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006872 UiccCard card = slot.getUiccCard();
6873 if (card != null) {
6874 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006875 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006876 cardId = slot.getEid();
6877 if (TextUtils.isEmpty(cardId)) {
6878 cardId = slot.getIccId();
6879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006880 }
6881
Jordan Liu857451f2019-05-09 16:35:35 -07006882 if (cardId != null) {
6883 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6884 // if cardId is an EID, it's all digits so this is fine
6885 cardId = IccUtils.stripTrailingFs(cardId);
6886 }
6887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888 int cardState = 0;
6889 switch (slot.getCardState()) {
6890 case CARDSTATE_ABSENT:
6891 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6892 break;
6893 case CARDSTATE_PRESENT:
6894 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6895 break;
6896 case CARDSTATE_ERROR:
6897 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6898 break;
6899 case CARDSTATE_RESTRICTED:
6900 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6901 break;
6902 default:
6903 break;
6904
6905 }
6906
6907 infos[i] = new UiccSlotInfo(
6908 slot.isActive(),
6909 slot.isEuicc(),
6910 cardId,
6911 cardState,
6912 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006913 slot.isExtendedApduSupported(),
6914 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006915 }
6916 return infos;
6917 } finally {
6918 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006919 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006920 }
6921
6922 @Override
6923 public boolean switchSlots(int[] physicalSlots) {
6924 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006925
6926 final long identity = Binder.clearCallingIdentity();
6927 try {
6928 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6929 } finally {
6930 Binder.restoreCallingIdentity(identity);
6931 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006932 }
Jack Yu4c988042018-02-27 15:30:01 -08006933
6934 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006935 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006936 final long identity = Binder.clearCallingIdentity();
6937 try {
6938 return UiccController.getInstance().getCardIdForDefaultEuicc();
6939 } finally {
6940 Binder.restoreCallingIdentity(identity);
6941 }
6942 }
6943
6944 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006945 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6946 enforceModifyPermission();
6947 final Phone phone = getPhone(subId);
6948 if (phone == null) {
6949 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6950 return;
6951 }
6952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006953 final long identity = Binder.clearCallingIdentity();
6954 try {
6955 phone.setRadioIndicationUpdateMode(filters, mode);
6956 } finally {
6957 Binder.restoreCallingIdentity(identity);
6958 }
Jack Yu4c988042018-02-27 15:30:01 -08006959 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006960
6961 /**
goneil47ffb6e2018-04-06 15:40:58 -07006962 * A test API to reload the UICC profile.
6963 *
6964 * <p>Requires that the calling app has permission
6965 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6966 * @hide
6967 */
6968 @Override
6969 public void refreshUiccProfile(int subId) {
6970 enforceModifyPermission();
6971
6972 final long identity = Binder.clearCallingIdentity();
6973 try {
6974 Phone phone = getPhone(subId);
6975 if (phone == null) {
6976 return;
6977 }
6978 UiccCard uiccCard = phone.getUiccCard();
6979 if (uiccCard == null) {
6980 return;
6981 }
6982 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6983 if (uiccProfile == null) {
6984 return;
6985 }
6986 uiccProfile.refresh();
6987 } finally {
6988 Binder.restoreCallingIdentity(identity);
6989 }
6990 }
6991
6992 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006993 * Returns false if the mobile data is disabled by default, otherwise return true.
6994 */
6995 private boolean getDefaultDataEnabled() {
6996 return "true".equalsIgnoreCase(
6997 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6998 }
6999
7000 /**
7001 * Returns true if the data roaming is enabled by default, i.e the system property
7002 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7003 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7004 */
7005 private boolean getDefaultDataRoamingEnabled(int subId) {
7006 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007007 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007008 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
7009 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
7010 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7011 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7012 return isDataRoamingEnabled;
7013 }
7014
7015 /**
7016 * Returns the default network type for the given {@code subId}, if the default network type is
7017 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7018 */
7019 private int getDefaultNetworkType(int subId) {
7020 return Integer.parseInt(
7021 TelephonyManager.getTelephonyProperty(
7022 mSubscriptionController.getPhoneId(subId),
7023 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
7024 String.valueOf(Phone.PREFERRED_NT_MODE)));
7025 }
fionaxua13278b2018-03-21 00:08:13 -07007026
7027 @Override
7028 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007029 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007030 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031
7032 final long identity = Binder.clearCallingIdentity();
7033 try {
7034 final Phone phone = getPhone(subId);
7035 if (phone == null) {
7036 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7037 return;
7038 }
chen xueaba88a2019-03-15 13:15:10 -07007039 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7040 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041 } finally {
7042 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007043 }
fionaxua13278b2018-03-21 00:08:13 -07007044 }
7045
7046 @Override
7047 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007048 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049
7050 final long identity = Binder.clearCallingIdentity();
7051 try {
7052 final Phone phone = getPhone(subId);
7053 if (phone == null) {
7054 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7055 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7056 }
7057 return phone.getCarrierIdListVersion();
7058 } finally {
7059 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007060 }
fionaxua13278b2018-03-21 00:08:13 -07007061 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007062
7063 @Override
7064 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
7065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7066 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
7067 return -1;
7068 }
7069
7070 final long identity = Binder.clearCallingIdentity();
7071 try {
7072 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7073 } finally {
7074 Binder.restoreCallingIdentity(identity);
7075 }
7076 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007077
7078 @Override
7079 public int getCdmaRoamingMode(int subId) {
7080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7081 mApp, subId, "getCdmaRoamingMode");
7082
7083 final long identity = Binder.clearCallingIdentity();
7084 try {
7085 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7086 } finally {
7087 Binder.restoreCallingIdentity(identity);
7088 }
7089 }
7090
7091 @Override
7092 public boolean setCdmaRoamingMode(int subId, int mode) {
7093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7094 mApp, subId, "setCdmaRoamingMode");
7095
7096 final long identity = Binder.clearCallingIdentity();
7097 try {
7098 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7099 } finally {
7100 Binder.restoreCallingIdentity(identity);
7101 }
7102 }
7103
7104 @Override
7105 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7106 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7107 mApp, subId, "setCdmaSubscriptionMode");
7108
7109 final long identity = Binder.clearCallingIdentity();
7110 try {
7111 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7112 } finally {
7113 Binder.restoreCallingIdentity(identity);
7114 }
7115 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007116
sqianc5eccab2018-10-19 18:46:41 -07007117 @Override
sqian8c685422019-02-22 15:55:18 -08007118 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007119 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007120 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007121 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007122 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7123 }
7124 final long identity = Binder.clearCallingIdentity();
7125 try {
sqian854d44b2018-12-12 16:48:18 -08007126 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7127 for (Phone phone: PhoneFactory.getPhones()) {
7128 if (phone.getEmergencyNumberTracker() != null
7129 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7130 emergencyNumberListInternal.put(
7131 phone.getSubId(),
7132 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7133 }
sqian11b7a0e2018-12-05 18:48:28 -08007134 }
sqian854d44b2018-12-12 16:48:18 -08007135 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007136 } finally {
7137 Binder.restoreCallingIdentity(identity);
7138 }
sqianc5eccab2018-10-19 18:46:41 -07007139 }
7140
7141 @Override
sqian8c685422019-02-22 15:55:18 -08007142 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007143 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007144 if (!exactMatch) {
7145 TelephonyPermissions
7146 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007147 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007148 }
7149 final long identity = Binder.clearCallingIdentity();
7150 try {
sqian854d44b2018-12-12 16:48:18 -08007151 for (Phone phone: PhoneFactory.getPhones()) {
7152 if (phone.getEmergencyNumberTracker() != null
7153 && phone.getEmergencyNumberTracker() != null) {
7154 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7155 number, exactMatch)) {
7156 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007157 }
7158 }
sqian11b7a0e2018-12-05 18:48:28 -08007159 }
7160 return false;
7161 } finally {
7162 Binder.restoreCallingIdentity(identity);
7163 }
7164 }
7165
sqianf4ca7ed2019-01-15 18:32:07 -08007166 /**
7167 * Update emergency number list for test mode.
7168 */
7169 @Override
7170 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7171 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7172 "updateEmergencyNumberListTestMode");
7173
7174 final long identity = Binder.clearCallingIdentity();
7175 try {
7176 for (Phone phone: PhoneFactory.getPhones()) {
7177 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7178 if (tracker != null) {
7179 tracker.executeEmergencyNumberTestModeCommand(action, num);
7180 }
7181 }
7182 } finally {
7183 Binder.restoreCallingIdentity(identity);
7184 }
7185 }
7186
7187 /**
7188 * Get the full emergency number list for test mode.
7189 */
7190 @Override
7191 public List<String> getEmergencyNumberListTestMode() {
7192 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7193 "getEmergencyNumberListTestMode");
7194
7195 final long identity = Binder.clearCallingIdentity();
7196 try {
7197 Set<String> emergencyNumbers = new HashSet<>();
7198 for (Phone phone: PhoneFactory.getPhones()) {
7199 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7200 if (tracker != null) {
7201 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7202 emergencyNumbers.add(num.getNumber());
7203 }
7204 }
7205 }
7206 return new ArrayList<>(emergencyNumbers);
7207 } finally {
7208 Binder.restoreCallingIdentity(identity);
7209 }
7210 }
7211
chen xud6b45bd2018-10-30 22:27:10 -07007212 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007213 public int getEmergencyNumberDbVersion(int subId) {
7214 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7215
7216 final long identity = Binder.clearCallingIdentity();
7217 try {
7218 final Phone phone = getPhone(subId);
7219 if (phone == null) {
7220 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7221 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7222 }
7223 return phone.getEmergencyNumberDbVersion();
7224 } finally {
7225 Binder.restoreCallingIdentity(identity);
7226 }
7227 }
7228
7229 @Override
7230 public void notifyOtaEmergencyNumberDbInstalled() {
7231 enforceModifyPermission();
7232
7233 final long identity = Binder.clearCallingIdentity();
7234 try {
7235 for (Phone phone: PhoneFactory.getPhones()) {
7236 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7237 if (tracker != null) {
7238 tracker.updateOtaEmergencyNumberDatabase();
7239 }
7240 }
7241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243 }
7244 }
7245
7246 @Override
7247 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7248 enforceActiveEmergencySessionPermission();
7249
7250 final long identity = Binder.clearCallingIdentity();
7251 try {
7252 for (Phone phone: PhoneFactory.getPhones()) {
7253 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7254 if (tracker != null) {
7255 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7256 }
7257 }
7258 } finally {
7259 Binder.restoreCallingIdentity(identity);
7260 }
7261 }
7262
7263 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007264 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7265 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7266 Phone phone = getPhone(subId);
7267 if (phone == null) {
7268 return null;
7269 }
7270 final long identity = Binder.clearCallingIdentity();
7271 try {
7272 UiccProfile profile = UiccController.getInstance()
7273 .getUiccProfileForPhone(phone.getPhoneId());
7274 if (profile != null) {
7275 return profile.getCertsFromCarrierPrivilegeAccessRules();
7276 }
7277 } finally {
7278 Binder.restoreCallingIdentity(identity);
7279 }
7280 return null;
7281 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007282
7283 /**
7284 * Enable or disable a modem stack.
7285 */
7286 @Override
7287 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7288 enforceModifyPermission();
7289
7290 final long identity = Binder.clearCallingIdentity();
7291 try {
7292 Phone phone = PhoneFactory.getPhone(slotIndex);
7293 if (phone == null) {
7294 return false;
7295 } else {
7296 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7297 }
7298 } finally {
7299 Binder.restoreCallingIdentity(identity);
7300 }
7301 }
Michelecea4cf22018-12-21 15:00:11 -08007302
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007303 /**
7304 * Whether a modem stack is enabled or not.
7305 */
7306 @Override
7307 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7308 Phone phone = PhoneFactory.getPhone(slotIndex);
7309 if (phone == null) return false;
7310
7311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7312 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7313 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7314 }
7315
7316 final long identity = Binder.clearCallingIdentity();
7317 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007318 try {
7319 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7320 } catch (NoSuchElementException ex) {
7321 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7322 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007323 } finally {
7324 Binder.restoreCallingIdentity(identity);
7325 }
7326 }
7327
Michelecea4cf22018-12-21 15:00:11 -08007328 @Override
Michele0ea7d782019-03-19 14:58:42 -07007329 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007330 enforceModifyPermission();
7331
7332 final long identity = Binder.clearCallingIdentity();
7333 try {
7334 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007335 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007336 .commit();
7337 } finally {
7338 Binder.restoreCallingIdentity(identity);
7339 }
7340 }
7341
7342 @Override
Michele0ea7d782019-03-19 14:58:42 -07007343 @TelephonyManager.IsMultiSimSupportedResult
7344 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007346 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7347 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007348 }
Michelecea4cf22018-12-21 15:00:11 -08007349
7350 final long identity = Binder.clearCallingIdentity();
7351 try {
Michele0ea7d782019-03-19 14:58:42 -07007352 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007353 } finally {
7354 Binder.restoreCallingIdentity(identity);
7355 }
7356 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007357
Michele0ea7d782019-03-19 14:58:42 -07007358 @TelephonyManager.IsMultiSimSupportedResult
7359 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007360 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7361 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7362 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007363 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7364 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007365 }
7366 // Check if the hardware supports multisim functionality. If usage of multisim is not
7367 // supported by the modem, indicate that it is restricted.
7368 PhoneCapability staticCapability =
7369 mPhoneConfigurationManager.getStaticPhoneCapability();
7370 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007371 loge("isMultiSimSupportedInternal: no static configuration available");
7372 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007373 }
7374 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007375 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7376 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007377 }
7378 // Check if support of multiple SIMs is restricted by carrier
7379 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007380 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007381 }
7382
Michele0ea7d782019-03-19 14:58:42 -07007383 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007384 }
7385
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007386 /**
7387 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007388 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7389 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7390 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007391 * @param numOfSims number of active sims we want to switch to
7392 */
7393 @Override
7394 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007395 if (numOfSims == 1) {
7396 enforceModifyPermission();
7397 } else {
7398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7399 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7400 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007401 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007402
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007403 try {
Michele30b57b22019-03-01 12:01:14 -08007404 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007405 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007406 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7407 return;
7408 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007409 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7410 } finally {
7411 Binder.restoreCallingIdentity(identity);
7412 }
7413 }
7414
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007415 @Override
7416 public boolean isApplicationOnUicc(int subId, int appType) {
7417 enforceReadPrivilegedPermission("isApplicationOnUicc");
7418 Phone phone = getPhone(subId);
7419 if (phone == null) {
7420 return false;
7421 }
7422 final long identity = Binder.clearCallingIdentity();
7423 try {
7424 UiccCard uiccCard = phone.getUiccCard();
7425 if (uiccCard == null) {
7426 return false;
7427 }
7428 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7429 if (uiccProfile == null) {
7430 return false;
7431 }
7432 if (TelephonyManager.APPTYPE_SIM <= appType
7433 && appType <= TelephonyManager.APPTYPE_ISIM) {
7434 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7435 }
7436 return false;
7437 } finally {
7438 Binder.restoreCallingIdentity(identity);
7439 }
7440 }
7441
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007442 /**
chen xub4baa772019-04-03 10:23:41 -07007443 * Get whether making changes to modem configurations will trigger reboot.
7444 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007445 */
7446 @Override
chen xub4baa772019-04-03 10:23:41 -07007447 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7448 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7449 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7450 return false;
7451 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007452 final long identity = Binder.clearCallingIdentity();
7453 try {
7454 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7455 } finally {
7456 Binder.restoreCallingIdentity(identity);
7457 }
7458 }
7459
Nathan Harold29f5f052019-02-15 13:41:57 -08007460 private void updateModemStateMetrics() {
7461 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7462 // TODO: check the state for each modem if the api is ready.
7463 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7464 }
7465
Pengquan Meng3889a572019-01-23 11:16:29 -08007466 @Override
7467 public int[] getSlotsMapping() {
7468 enforceReadPrivilegedPermission("getSlotsMapping");
7469
7470 final long identity = Binder.clearCallingIdentity();
7471 try {
7472 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7473 // All logical slots should have a mapping to a physical slot.
7474 int[] logicalSlotsMapping = new int[phoneCount];
7475 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7476 for (int i = 0; i < slotInfos.length; i++) {
7477 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7478 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7479 }
7480 }
7481 return logicalSlotsMapping;
7482 } finally {
7483 Binder.restoreCallingIdentity(identity);
7484 }
7485 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007486
7487 /**
7488 * Get the IRadio HAL Version
7489 */
7490 @Override
7491 public int getRadioHalVersion() {
7492 Phone phone = getDefaultPhone();
7493 if (phone == null) return -1;
7494 HalVersion hv = phone.getHalVersion();
7495 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7496 return hv.major * 100 + hv.minor;
7497 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007498
7499 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007500 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7501 * corresponding network requests on a subId.
7502 *
7503 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007504 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007505 * 2) APN is un-metered for this subscription, or
7506 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7507 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7508 *
7509 * @return whether data is allowed for a apn type.
7510 *
7511 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007512 */
7513 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007514 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007515 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7516 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007517
7518 // Now that all security checks passes, perform the operation as ourselves.
7519 final long identity = Binder.clearCallingIdentity();
7520 try {
7521 Phone phone = getPhone(subId);
7522 if (phone == null) return false;
7523
Jack Yu41407ee2019-05-13 16:54:09 -07007524 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007525 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7526 } finally {
7527 Binder.restoreCallingIdentity(identity);
7528 }
7529 }
7530
7531 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007532 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007533 enforceReadPrivilegedPermission("isApnMetered");
7534
7535 // Now that all security checks passes, perform the operation as ourselves.
7536 final long identity = Binder.clearCallingIdentity();
7537 try {
7538 Phone phone = getPhone(subId);
7539 if (phone == null) return true; // By default return true.
7540
Jack Yu41407ee2019-05-13 16:54:09 -07007541 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007542 } finally {
7543 Binder.restoreCallingIdentity(identity);
7544 }
7545 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007546
7547 @Override
7548 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7549 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7550 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7551 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7552 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7553 }
7554 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7555 Intent intent = new Intent();
7556 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7557 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7558 // Bring up choose default SMS subscription dialog right now
7559 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7560 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7561 mApp.startActivity(intent);
7562 }
chen xud5ca2d52019-05-28 15:20:57 -07007563
7564 @Override
7565 public String getMmsUAProfUrl(int subId) {
7566 //TODO investigate if this API should require proper permission check in R b/133791609
7567 final long identity = Binder.clearCallingIdentity();
7568 try {
7569 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7570 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7571 } finally {
7572 Binder.restoreCallingIdentity(identity);
7573 }
7574 }
7575
7576 @Override
7577 public String getMmsUserAgent(int subId) {
7578 //TODO investigate if this API should require proper permission check in R b/133791609
7579 final long identity = Binder.clearCallingIdentity();
7580 try {
7581 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7582 .getString(com.android.internal.R.string.config_mms_user_agent);
7583 } finally {
7584 Binder.restoreCallingIdentity(identity);
7585 }
7586 }
Jack Yub07d4972019-05-28 16:12:25 -07007587
7588 @Override
7589 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7590 enforceModifyPermission();
7591
7592 // Now that all security checks passes, perform the operation as ourselves.
7593 final long identity = Binder.clearCallingIdentity();
7594 try {
7595 Phone phone = getPhone(subId);
7596 if (phone == null) return false;
7597
7598 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7599 } finally {
7600 Binder.restoreCallingIdentity(identity);
7601 }
7602 }
7603
7604 @Override
7605 public boolean isDataAllowedInVoiceCall(int subId) {
7606 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7607
7608 // Now that all security checks passes, perform the operation as ourselves.
7609 final long identity = Binder.clearCallingIdentity();
7610 try {
7611 Phone phone = getPhone(subId);
7612 if (phone == null) return false;
7613
7614 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7615 } finally {
7616 Binder.restoreCallingIdentity(identity);
7617 }
7618 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007619
7620 /**
7621 * Updates whether conference event pacakge handling is enabled.
7622 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7623 * otherwise.
7624 */
7625 @Override
7626 public void setCepEnabled(boolean isCepEnabled) {
7627 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7628
7629 final long identity = Binder.clearCallingIdentity();
7630 try {
7631 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7632 for (Phone phone : PhoneFactory.getPhones()) {
7633 Phone defaultPhone = phone.getImsPhone();
7634 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7635 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7636 ImsPhoneCallTracker imsPhoneCallTracker =
7637 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7638 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7639 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7640 + imsPhone.getMsisdn());
7641 }
7642 }
7643 } finally {
7644 Binder.restoreCallingIdentity(identity);
7645 }
7646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007647}