blob: 318e08646d748f9627bec9ea80d5e86032827f29 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070025import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070028import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070029import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.content.Context;
31import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070032import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070033import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070037import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080050import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070051import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070054import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070055import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070067import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080068import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070069import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070071import android.telephony.CellInfoGsm;
72import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070073import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070074import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070075import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070076import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080077import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070078import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080079import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070080import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080081import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080082import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070083import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080084import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070085import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080087import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080088import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080089import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070090import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080092import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080093import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000094import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070095import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070096import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070097import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.data.ApnSetting;
99import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -0700100import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
113import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800114import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800130import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700131import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800132import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800134import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700135import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100136import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700137import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700138import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700140import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800141import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700142import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700143import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700144import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700145import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700146import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700147import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700148import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700149import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800150import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800151import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700152import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800153import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700154import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800155import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700156import com.android.internal.telephony.imsphone.ImsPhone;
157import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800158import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900159import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.uicc.IccIoResult;
161import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800162import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700163import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000167import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700168import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800169import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700170import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700171import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800172import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700173import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700174import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800175
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700176import java.io.FileDescriptor;
177import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800179import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800180import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800181import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800182import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100183import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800184import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700185import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800186import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187
188/**
189 * Implementation of the ITelephony interface.
190 */
Santos Cordon117fee72014-05-16 17:56:12 -0700191public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 private static final String LOG_TAG = "PhoneInterfaceManager";
193 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
194 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800195 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197 // Message codes used with mMainThreadHandler
198 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700199 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
200 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201 private static final int CMD_OPEN_CHANNEL = 9;
202 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
203 private static final int CMD_CLOSE_CHANNEL = 11;
204 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800205 private static final int CMD_NV_READ_ITEM = 13;
206 private static final int EVENT_NV_READ_ITEM_DONE = 14;
207 private static final int CMD_NV_WRITE_ITEM = 15;
208 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
209 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
210 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700211 private static final int CMD_RESET_MODEM_CONFIG = 19;
212 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800213 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
214 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
215 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
216 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800217 private static final int CMD_SEND_ENVELOPE = 25;
218 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000219 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
220 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700221 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
222 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
223 private static final int CMD_EXCHANGE_SIM_IO = 31;
224 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800225 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
226 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700227 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
228 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700229 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
230 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700231 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
232 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
233 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
234 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700235 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
236 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
237 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
238 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700239 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
241 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000242 private static final int CMD_SWITCH_SLOTS = 50;
243 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700244 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
245 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
246 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
247 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
248 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
249 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
250 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
251 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700252 private static final int CMD_GET_ALL_CELL_INFO = 60;
253 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
254 private static final int CMD_GET_CELL_LOCATION = 62;
255 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700256 private static final int CMD_MODEM_REBOOT = 64;
257 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700258 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
259 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800260 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
261 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700262 private static final int CMD_GET_MODEM_STATUS = 70;
263 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700264 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
265 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700266 private static final int CMD_ERASE_MODEM_CONFIG = 74;
267 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800269 // Parameters of select command.
270 private static final int SELECT_COMMAND = 0xA4;
271 private static final int SELECT_P1 = 0x04;
272 private static final int SELECT_P2 = 0;
273 private static final int SELECT_P3 = 0x10;
274
Pengquan Meng85728fb2018-03-12 16:31:21 -0700275 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
276 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
277 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
278
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700279 /** The singleton instance. */
280 private static PhoneInterfaceManager sInstance;
281
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800283 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700284 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private AppOpsManager mAppOps;
286 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800287 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800288 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700289 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
Derek Tan97ebb422014-09-05 16:55:38 -0700291 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
292 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800293 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800294 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700295
Michelecea4cf22018-12-21 15:00:11 -0800296 // String to store multi SIM allowed
297 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
298
Derek Tan740e1672017-06-27 14:56:27 -0700299 // The AID of ISD-R.
300 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
301
yinxub1bed742017-04-17 11:45:04 -0700302 private NetworkScanRequestTracker mNetworkScanRequestTracker;
303
David Kelly5e06a7f2018-03-12 14:10:59 +0000304 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
305 private static final int MANUFACTURER_CODE_LENGTH = 8;
306
Derek Tan89e89d42014-07-08 17:00:10 -0700307 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700308 * Experiment flag to enable erase modem config on reset network, default value is false
309 */
310 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
311 "reset_network_erase_modem_config_enabled";
312
313 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700314 * A request object to use for transmitting data to an ICC.
315 */
316 private static final class IccAPDUArgument {
317 public int channel, cla, command, p1, p2, p3;
318 public String data;
319
320 public IccAPDUArgument(int channel, int cla, int command,
321 int p1, int p2, int p3, String data) {
322 this.channel = channel;
323 this.cla = cla;
324 this.command = command;
325 this.p1 = p1;
326 this.p2 = p2;
327 this.p3 = p3;
328 this.data = data;
329 }
330 }
331
332 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700333 * A request object to use for transmitting data to an ICC.
334 */
335 private static final class ManualNetworkSelectionArgument {
336 public OperatorInfo operatorInfo;
337 public boolean persistSelection;
338
339 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
340 this.operatorInfo = operatorInfo;
341 this.persistSelection = persistSelection;
342 }
343 }
344
345 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
347 * request after sending. The main thread will notify the request when it is complete.
348 */
349 private static final class MainThreadRequest {
350 /** The argument to use for the request */
351 public Object argument;
352 /** The result of the request that is run on the main thread */
353 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800354 // The subscriber id that this request applies to. Defaults to
355 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
356 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
Nathan Harold92bed182018-10-12 18:16:49 -0700358 // In cases where subId is unavailable, the caller needs to specify the phone.
359 public Phone phone;
360
vagdeviaf9a5b92018-08-15 16:01:53 -0700361 public WorkSource workSource;
362
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 public MainThreadRequest(Object argument) {
364 this.argument = argument;
365 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800366
Nathan Harold92bed182018-10-12 18:16:49 -0700367 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
368 this.argument = argument;
369 if (phone != null) {
370 this.phone = phone;
371 }
372 this.workSource = workSource;
373 }
374
vagdeviaf9a5b92018-08-15 16:01:53 -0700375 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800376 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800377 if (subId != null) {
378 this.subId = subId;
379 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700380 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 }
383
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800384 private static final class IncomingThirdPartyCallArgs {
385 public final ComponentName component;
386 public final String callId;
387 public final String callerDisplayName;
388
389 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
390 String callerDisplayName) {
391 this.component = component;
392 this.callId = callId;
393 this.callerDisplayName = callerDisplayName;
394 }
395 }
396
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 /**
398 * A handler that processes messages on the main thread in the phone process. Since many
399 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
400 * inbound binder threads to the main thread in the phone process. The Binder thread
401 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
402 * on, which will be notified when the operation completes and will contain the result of the
403 * request.
404 *
405 * <p>If a MainThreadRequest object is provided in the msg.obj field,
406 * note that request.result must be set to something non-null for the calling thread to
407 * unblock.
408 */
409 private final class MainThreadHandler extends Handler {
410 @Override
411 public void handleMessage(Message msg) {
412 MainThreadRequest request;
413 Message onCompleted;
414 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800415 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800417 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418
419 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700420 case CMD_HANDLE_USSD_REQUEST: {
421 request = (MainThreadRequest) msg.obj;
422 final Phone phone = getPhoneFromRequest(request);
423 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
424 String ussdRequest = ussdObject.first;
425 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700426
Pengquan Menga1bb6272018-09-06 09:59:22 -0700427 if (!isUssdApiAllowed(request.subId)) {
428 // Carrier does not support use of this API, return failure.
429 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
430 UssdResponse response = new UssdResponse(ussdRequest, null);
431 Bundle returnData = new Bundle();
432 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
433 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700434
Pengquan Menga1bb6272018-09-06 09:59:22 -0700435 request.result = true;
436 notifyRequester(request);
437 return;
438 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700439
Pengquan Menga1bb6272018-09-06 09:59:22 -0700440 try {
441 request.result = phone != null
442 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
443 } catch (CallStateException cse) {
444 request.result = false;
445 }
446 // Wake up the requesting thread
447 notifyRequester(request);
448 break;
pkanwar32d516d2016-10-14 19:37:38 -0700449 }
450
Yorke Lee716f67e2015-06-17 15:39:16 -0700451 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700453 final Phone phone = getPhoneFromRequest(request);
454 request.result = phone != null ?
455 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
456 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700458 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700461
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800465 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 if (uiccCard == null) {
467 loge("iccTransmitApduLogicalChannel: No UICC");
468 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700469 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700470 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
472 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700473 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700474 iccArgument.channel, iccArgument.cla, iccArgument.command,
475 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700477 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 break;
479
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 ar = (AsyncResult) msg.obj;
482 request = (MainThreadRequest) ar.userObj;
483 if (ar.exception == null && ar.result != null) {
484 request.result = ar.result;
485 } else {
486 request.result = new IccIoResult(0x6F, 0, (byte[])null);
487 if (ar.result == null) {
488 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800489 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800491 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700492 } else {
493 loge("iccTransmitApduLogicalChannel: Unknown exception");
494 }
495 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 break;
498
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
500 request = (MainThreadRequest) msg.obj;
501 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800502 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 if (uiccCard == null) {
504 loge("iccTransmitApduBasicChannel: No UICC");
505 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700506 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 } else {
508 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
509 request);
510 uiccCard.iccTransmitApduBasicChannel(
511 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
512 iccArgument.p3, iccArgument.data, onCompleted);
513 }
514 break;
515
516 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
517 ar = (AsyncResult) msg.obj;
518 request = (MainThreadRequest) ar.userObj;
519 if (ar.exception == null && ar.result != null) {
520 request.result = ar.result;
521 } else {
522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
523 if (ar.result == null) {
524 loge("iccTransmitApduBasicChannel: Empty response");
525 } else if (ar.exception instanceof CommandException) {
526 loge("iccTransmitApduBasicChannel: CommandException: " +
527 ar.exception);
528 } else {
529 loge("iccTransmitApduBasicChannel: Unknown exception");
530 }
531 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 break;
534
535 case CMD_EXCHANGE_SIM_IO:
536 request = (MainThreadRequest) msg.obj;
537 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800538 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 if (uiccCard == null) {
540 loge("iccExchangeSimIO: No UICC");
541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 } else {
544 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
545 request);
546 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
547 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
548 iccArgument.data, onCompleted);
549 }
550 break;
551
552 case EVENT_EXCHANGE_SIM_IO_DONE:
553 ar = (AsyncResult) msg.obj;
554 request = (MainThreadRequest) ar.userObj;
555 if (ar.exception == null && ar.result != null) {
556 request.result = ar.result;
557 } else {
558 request.result = new IccIoResult(0x6f, 0, (byte[])null);
559 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 break;
562
Derek Tan4d5e5c12014-02-04 11:54:58 -0800563 case CMD_SEND_ENVELOPE:
564 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 if (uiccCard == null) {
567 loge("sendEnvelopeWithStatus: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
572 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
573 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800574 break;
575
576 case EVENT_SEND_ENVELOPE_DONE:
577 ar = (AsyncResult) msg.obj;
578 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700579 if (ar.exception == null && ar.result != null) {
580 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800581 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700582 request.result = new IccIoResult(0x6F, 0, (byte[])null);
583 if (ar.result == null) {
584 loge("sendEnvelopeWithStatus: Empty response");
585 } else if (ar.exception instanceof CommandException) {
586 loge("sendEnvelopeWithStatus: CommandException: " +
587 ar.exception);
588 } else {
589 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
590 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800591 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800593 break;
594
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 case CMD_OPEN_CHANNEL:
596 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800597 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800598 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 if (uiccCard == null) {
600 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800601 request.result = new IccOpenLogicalChannelResponse(-1,
602 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700603 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 } else {
605 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800606 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
607 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700608 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 break;
610
611 case EVENT_OPEN_CHANNEL_DONE:
612 ar = (AsyncResult) msg.obj;
613 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 int[] result = (int[]) ar.result;
617 int channelId = result[0];
618 byte[] selectResponse = null;
619 if (result.length > 1) {
620 selectResponse = new byte[result.length - 1];
621 for (int i = 1; i < result.length; ++i) {
622 selectResponse[i - 1] = (byte) result[i];
623 }
624 }
625 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 if (ar.result == null) {
629 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 if (ar.exception != null) {
632 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
633 }
634
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700635 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700636 if (ar.exception instanceof CommandException) {
637 CommandException.Error error =
638 ((CommandException) (ar.exception)).getCommandError();
639 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700640 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700641 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700642 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 }
644 }
645 openChannelResp = new IccOpenLogicalChannelResponse(
646 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700648 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700649 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
652 case CMD_CLOSE_CHANNEL:
653 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800654 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 if (uiccCard == null) {
656 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900657 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 } else {
660 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
661 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
662 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 break;
664
665 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800666 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
667 break;
668
669 case CMD_NV_READ_ITEM:
670 request = (MainThreadRequest) msg.obj;
671 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800672 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
673 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800674 break;
675
676 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800682 request.result = "";
683 if (ar.result == null) {
684 loge("nvReadItem: Empty response");
685 } else if (ar.exception instanceof CommandException) {
686 loge("nvReadItem: CommandException: " +
687 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800689 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 }
691 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700692 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 break;
694
Jake Hambye994d462014-02-03 13:10:13 -0800695 case CMD_NV_WRITE_ITEM:
696 request = (MainThreadRequest) msg.obj;
697 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
698 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800699 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700700 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
703 case EVENT_NV_WRITE_ITEM_DONE:
704 handleNullReturnEvent(msg, "nvWriteItem");
705 break;
706
707 case CMD_NV_WRITE_CDMA_PRL:
708 request = (MainThreadRequest) msg.obj;
709 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800710 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800711 break;
712
713 case EVENT_NV_WRITE_CDMA_PRL_DONE:
714 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
715 break;
716
chen xu6dac5ab2018-10-26 17:39:23 -0700717 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800718 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700719 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800720 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800721 break;
722
chen xu6dac5ab2018-10-26 17:39:23 -0700723 case EVENT_RESET_MODEM_CONFIG_DONE:
724 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800725 break;
726
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 case CMD_GET_PREFERRED_NETWORK_TYPE:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700730 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 break;
732
733 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
734 ar = (AsyncResult) msg.obj;
735 request = (MainThreadRequest) ar.userObj;
736 if (ar.exception == null && ar.result != null) {
737 request.result = ar.result; // Integer
738 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800739 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800740 if (ar.result == null) {
741 loge("getPreferredNetworkType: Empty response");
742 } else if (ar.exception instanceof CommandException) {
743 loge("getPreferredNetworkType: CommandException: " +
744 ar.exception);
745 } else {
746 loge("getPreferredNetworkType: Unknown exception");
747 }
748 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800750 break;
751
752 case CMD_SET_PREFERRED_NETWORK_TYPE:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
755 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700756 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800757 break;
758
759 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
760 handleNullReturnEvent(msg, "setPreferredNetworkType");
761 break;
762
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000763 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
764 request = (MainThreadRequest)msg.obj;
765 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800766 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000767 break;
768
769 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
770 ar = (AsyncResult)msg.obj;
771 request = (MainThreadRequest)ar.userObj;
772 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000774 break;
775
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800776 case CMD_SET_VOICEMAIL_NUMBER:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
779 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800780 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
781 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800782 break;
783
784 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
785 handleNullReturnEvent(msg, "setVoicemailNumber");
786 break;
787
Stuart Scott54788802015-03-30 13:18:01 -0700788 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
789 request = (MainThreadRequest) msg.obj;
790 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
791 request);
792 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
793 break;
794
795 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
796 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
797 break;
798
Shishir Agrawal302c8692015-06-19 13:49:39 -0700799 case CMD_PERFORM_NETWORK_SCAN:
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
802 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
803 break;
804
805 case EVENT_PERFORM_NETWORK_SCAN_DONE:
806 ar = (AsyncResult) msg.obj;
807 request = (MainThreadRequest) ar.userObj;
808 CellNetworkScanResult cellScanResult;
809 if (ar.exception == null && ar.result != null) {
810 cellScanResult = new CellNetworkScanResult(
811 CellNetworkScanResult.STATUS_SUCCESS,
812 (List<OperatorInfo>) ar.result);
813 } else {
814 if (ar.result == null) {
815 loge("getCellNetworkScanResults: Empty response");
816 }
817 if (ar.exception != null) {
818 loge("getCellNetworkScanResults: Exception: " + ar.exception);
819 }
820 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
821 if (ar.exception instanceof CommandException) {
822 CommandException.Error error =
823 ((CommandException) (ar.exception)).getCommandError();
824 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
825 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
826 } else if (error == CommandException.Error.GENERIC_FAILURE) {
827 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
828 }
829 }
830 cellScanResult = new CellNetworkScanResult(errorCode, null);
831 }
832 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700833 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700834 break;
835
836 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
837 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700838 ManualNetworkSelectionArgument selArg =
839 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
841 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700842 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
843 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700844 break;
845
846 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
849 if (ar.exception == null) {
850 request.result = true;
851 } else {
852 request.result = false;
853 loge("setNetworkSelectionModeManual " + ar.exception);
854 }
855 notifyRequester(request);
856 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700857 break;
858
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700859 case CMD_GET_MODEM_ACTIVITY_INFO:
860 request = (MainThreadRequest) msg.obj;
861 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700862 if (defaultPhone != null) {
863 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
864 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700865 break;
866
867 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
868 ar = (AsyncResult) msg.obj;
869 request = (MainThreadRequest) ar.userObj;
870 if (ar.exception == null && ar.result != null) {
871 request.result = ar.result;
872 } else {
873 if (ar.result == null) {
874 loge("queryModemActivityInfo: Empty response");
875 } else if (ar.exception instanceof CommandException) {
876 loge("queryModemActivityInfo: CommandException: " +
877 ar.exception);
878 } else {
879 loge("queryModemActivityInfo: Unknown exception");
880 }
881 }
Amit Mahajand4766222016-01-28 15:28:28 -0800882 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
883 if (request.result == null) {
884 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
885 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700886 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700887 break;
888
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 case CMD_SET_ALLOWED_CARRIERS:
890 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800891 CarrierRestrictionRules argument =
892 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700893 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800894 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700895 break;
896
897 case EVENT_SET_ALLOWED_CARRIERS_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null && ar.result != null) {
901 request.result = ar.result;
902 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800903 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
904 if (ar.exception instanceof CommandException) {
905 loge("setAllowedCarriers: CommandException: " + ar.exception);
906 CommandException.Error error =
907 ((CommandException) (ar.exception)).getCommandError();
908 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
909 request.result =
910 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
911 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700912 } else {
913 loge("setAllowedCarriers: Unknown exception");
914 }
915 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700916 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700917 break;
918
919 case CMD_GET_ALLOWED_CARRIERS:
920 request = (MainThreadRequest) msg.obj;
921 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800922 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700923 break;
924
925 case EVENT_GET_ALLOWED_CARRIERS_DONE:
926 ar = (AsyncResult) msg.obj;
927 request = (MainThreadRequest) ar.userObj;
928 if (ar.exception == null && ar.result != null) {
929 request.result = ar.result;
930 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800931 request.result = new IllegalStateException(
932 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700933 if (ar.result == null) {
934 loge("getAllowedCarriers: Empty response");
935 } else if (ar.exception instanceof CommandException) {
936 loge("getAllowedCarriers: CommandException: " +
937 ar.exception);
938 } else {
939 loge("getAllowedCarriers: Unknown exception");
940 }
941 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700942 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700943 break;
944
Nathan Haroldb3014052017-01-25 15:57:32 -0800945 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
946 ar = (AsyncResult) msg.obj;
947 request = (MainThreadRequest) ar.userObj;
948 if (ar.exception == null && ar.result != null) {
949 request.result = ar.result;
950 } else {
951 request.result = new IllegalArgumentException(
952 "Failed to retrieve Forbidden Plmns");
953 if (ar.result == null) {
954 loge("getForbiddenPlmns: Empty response");
955 } else {
956 loge("getForbiddenPlmns: Unknown exception");
957 }
958 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700959 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800960 break;
961
962 case CMD_GET_FORBIDDEN_PLMNS:
963 request = (MainThreadRequest) msg.obj;
964 uiccCard = getUiccCardFromRequest(request);
965 if (uiccCard == null) {
966 loge("getForbiddenPlmns() UiccCard is null");
967 request.result = new IllegalArgumentException(
968 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700969 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800970 break;
971 }
972 Integer appType = (Integer) request.argument;
973 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
974 if (uiccApp == null) {
975 loge("getForbiddenPlmns() no app with specified type -- "
976 + appType);
977 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700978 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800979 break;
980 } else {
981 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
982 + " specified type -- " + appType);
983 }
984 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
985 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
986 onCompleted);
987 break;
988
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000989 case CMD_SWITCH_SLOTS:
990 request = (MainThreadRequest) msg.obj;
991 int[] physicalSlots = (int[]) request.argument;
992 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
993 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
994 break;
995
996 case EVENT_SWITCH_SLOTS_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001000 notifyRequester(request);
1001 break;
1002 case CMD_GET_NETWORK_SELECTION_MODE:
1003 request = (MainThreadRequest) msg.obj;
1004 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1005 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1006 break;
1007
1008 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
1011 if (ar.exception != null) {
1012 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1013 } else {
1014 int mode = ((int[]) ar.result)[0];
1015 if (mode == 0) {
1016 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1017 } else {
1018 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1019 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001020 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001021 notifyRequester(request);
1022 break;
1023 case CMD_GET_CDMA_ROAMING_MODE:
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1026 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1027 break;
1028 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 if (ar.exception != null) {
1032 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1033 } else {
1034 request.result = ((int[]) ar.result)[0];
1035 }
1036 notifyRequester(request);
1037 break;
1038 case CMD_SET_CDMA_ROAMING_MODE:
1039 request = (MainThreadRequest) msg.obj;
1040 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1041 int mode = (int) request.argument;
1042 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1043 break;
1044 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
1047 request.result = ar.exception == null;
1048 notifyRequester(request);
1049 break;
1050 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1053 int subscriptionMode = (int) request.argument;
1054 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1055 break;
1056 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1057 ar = (AsyncResult) msg.obj;
1058 request = (MainThreadRequest) ar.userObj;
1059 request.result = ar.exception == null;
1060 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001061 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 case CMD_GET_ALL_CELL_INFO:
1063 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001065 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001067 case EVENT_GET_ALL_CELL_INFO_DONE:
1068 ar = (AsyncResult) msg.obj;
1069 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001070 // If a timeout occurs, the response will be null
1071 request.result = (ar.exception == null && ar.result != null)
1072 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001073 synchronized (request) {
1074 request.notifyAll();
1075 }
1076 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001077 case CMD_REQUEST_CELL_INFO_UPDATE:
1078 request = (MainThreadRequest) msg.obj;
1079 request.phone.requestCellInfoUpdate(request.workSource,
1080 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1081 break;
1082 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1083 ar = (AsyncResult) msg.obj;
1084 request = (MainThreadRequest) ar.userObj;
1085 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1086 try {
1087 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001088 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001089 cb.onError(
1090 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1091 ar.exception.getClass().getName(),
1092 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001094 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001095 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001096 } else {
1097 // use the result as returned
1098 cb.onCellInfo((List<CellInfo>) ar.result);
1099 }
1100 } catch (RemoteException re) {
1101 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1102 }
1103 break;
1104 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001105 request = (MainThreadRequest) msg.obj;
1106 WorkSource ws = (WorkSource) request.argument;
1107 Phone phone = getPhoneFromRequest(request);
1108 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1109 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001110 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001111 ar = (AsyncResult) msg.obj;
1112 request = (MainThreadRequest) ar.userObj;
1113 if (ar.exception == null) {
1114 request.result = ar.result;
1115 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001116 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001117 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1118 ? new CdmaCellLocation() : new GsmCellLocation();
1119 }
1120
1121 synchronized (request) {
1122 request.notifyAll();
1123 }
1124 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001125 case CMD_MODEM_REBOOT:
1126 request = (MainThreadRequest) msg.obj;
1127 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001128 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001129 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001130 case EVENT_CMD_MODEM_REBOOT_DONE:
1131 handleNullReturnEvent(msg, "rebootModem");
1132 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001133 case CMD_REQUEST_ENABLE_MODEM:
1134 request = (MainThreadRequest) msg.obj;
1135 boolean enable = (boolean) request.argument;
1136 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001137 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001138 PhoneConfigurationManager.getInstance()
1139 .enablePhone(request.phone, enable, onCompleted);
1140 break;
1141 case EVENT_ENABLE_MODEM_DONE:
1142 ar = (AsyncResult) msg.obj;
1143 request = (MainThreadRequest) ar.userObj;
1144 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001145 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001146 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001147 if ((boolean) request.result) {
1148 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1149 updateModemStateMetrics();
1150 } else {
1151 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1152 + ar.exception);
1153 }
1154 notifyRequester(request);
1155 break;
1156 case CMD_GET_MODEM_STATUS:
1157 request = (MainThreadRequest) msg.obj;
1158 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1159 PhoneConfigurationManager.getInstance()
1160 .getPhoneStatusFromModem(request.phone, onCompleted);
1161 break;
1162 case EVENT_GET_MODEM_STATUS_DONE:
1163 ar = (AsyncResult) msg.obj;
1164 request = (MainThreadRequest) ar.userObj;
1165 int id = request.phone.getPhoneId();
1166 if (ar.exception == null && ar.result != null) {
1167 request.result = ar.result;
1168 //update the cache as modem status has changed
1169 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1170 (boolean) request.result);
1171 } else {
1172 // Return true if modem status cannot be retrieved. For most cases,
1173 // modem status is on. And for older version modems, GET_MODEM_STATUS
1174 // and disable modem are not supported. Modem is always on.
1175 // TODO: this should be fixed in R to support a third
1176 // status UNKNOWN b/131631629
1177 request.result = true;
1178 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1179 + ar.exception);
1180 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001181 notifyRequester(request);
1182 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001183 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1184 ar = (AsyncResult) msg.obj;
1185 request = (MainThreadRequest) ar.userObj;
1186 if (ar.exception == null && ar.result != null) {
1187 request.result = ar.result;
1188 } else {
1189 request.result = -1;
1190 loge("Failed to set Forbidden Plmns");
1191 if (ar.result == null) {
1192 loge("setForbidenPlmns: Empty response");
1193 } else if (ar.exception != null) {
1194 loge("setForbiddenPlmns: Exception: " + ar.exception);
1195 request.result = -1;
1196 } else {
1197 loge("setForbiddenPlmns: Unknown exception");
1198 }
1199 }
1200 notifyRequester(request);
1201 break;
1202 case CMD_SET_FORBIDDEN_PLMNS:
1203 request = (MainThreadRequest) msg.obj;
1204 uiccCard = getUiccCardFromRequest(request);
1205 if (uiccCard == null) {
1206 loge("setForbiddenPlmns: UiccCard is null");
1207 request.result = -1;
1208 notifyRequester(request);
1209 break;
1210 }
1211 Pair<Integer, List<String>> setFplmnsArgs =
1212 (Pair<Integer, List<String>>) request.argument;
1213 appType = setFplmnsArgs.first;
1214 List<String> fplmns = setFplmnsArgs.second;
1215 uiccApp = uiccCard.getApplicationByType(appType);
1216 if (uiccApp == null) {
1217 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1218 request.result = -1;
1219 loge("Failed to get UICC App");
1220 notifyRequester(request);
1221 } else {
1222 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1223 ((SIMRecords) uiccApp.getIccRecords())
1224 .setForbiddenPlmns(onCompleted, fplmns);
1225 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001226 case CMD_ERASE_MODEM_CONFIG:
1227 request = (MainThreadRequest) msg.obj;
1228 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1229 defaultPhone.eraseModemConfig(onCompleted);
1230 break;
1231 case EVENT_ERASE_MODEM_CONFIG_DONE:
1232 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001233 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 default:
1235 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1236 break;
1237 }
1238 }
Jake Hambye994d462014-02-03 13:10:13 -08001239
Pengquan Menga1bb6272018-09-06 09:59:22 -07001240 private void notifyRequester(MainThreadRequest request) {
1241 synchronized (request) {
1242 request.notifyAll();
1243 }
1244 }
1245
Jake Hambye994d462014-02-03 13:10:13 -08001246 private void handleNullReturnEvent(Message msg, String command) {
1247 AsyncResult ar = (AsyncResult) msg.obj;
1248 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1249 if (ar.exception == null) {
1250 request.result = true;
1251 } else {
1252 request.result = false;
1253 if (ar.exception instanceof CommandException) {
1254 loge(command + ": CommandException: " + ar.exception);
1255 } else {
1256 loge(command + ": Unknown exception");
1257 }
1258 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001259 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 }
1262
1263 /**
1264 * Posts the specified command to be executed on the main thread,
1265 * waits for the request to complete, and returns the result.
1266 * @see #sendRequestAsync
1267 */
1268 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001269 return sendRequest(
1270 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001271 }
1272
1273 /**
1274 * Posts the specified command to be executed on the main thread,
1275 * waits for the request to complete, and returns the result.
1276 * @see #sendRequestAsync
1277 */
1278 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1279 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001280 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001281 }
1282
1283 /**
1284 * Posts the specified command to be executed on the main thread,
1285 * waits for the request to complete, and returns the result.
1286 * @see #sendRequestAsync
1287 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001288 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001289 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001290 }
1291
1292 /**
1293 * Posts the specified command to be executed on the main thread,
1294 * waits for the request to complete, and returns the result.
1295 * @see #sendRequestAsync
1296 */
Nathan Harold92bed182018-10-12 18:16:49 -07001297 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1298 return sendRequest(command, argument, subId, null, workSource);
1299 }
1300
1301 /**
1302 * Posts the specified command to be executed on the main thread,
1303 * waits for the request to complete, and returns the result.
1304 * @see #sendRequestAsync
1305 */
1306 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1307 return sendRequest(
1308 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1309 }
1310
1311 /**
1312 * Posts the specified command to be executed on the main thread,
1313 * waits for the request to complete, and returns the result.
1314 * @see #sendRequestAsync
1315 */
1316 private Object sendRequest(
1317 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1319 throw new RuntimeException("This method will deadlock if called from the main thread.");
1320 }
1321
Nathan Harold92bed182018-10-12 18:16:49 -07001322 MainThreadRequest request = null;
1323 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1324 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1325 } else if (phone != null) {
1326 request = new MainThreadRequest(argument, phone, workSource);
1327 } else {
1328 request = new MainThreadRequest(argument, subId, workSource);
1329 }
1330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 Message msg = mMainThreadHandler.obtainMessage(command, request);
1332 msg.sendToTarget();
1333
1334 // Wait for the request to complete
1335 synchronized (request) {
1336 while (request.result == null) {
1337 try {
1338 request.wait();
1339 } catch (InterruptedException e) {
1340 // Do nothing, go back and wait until the request is complete
1341 }
1342 }
1343 }
1344 return request.result;
1345 }
1346
1347 /**
1348 * Asynchronous ("fire and forget") version of sendRequest():
1349 * Posts the specified command to be executed on the main thread, and
1350 * returns immediately.
1351 * @see #sendRequest
1352 */
1353 private void sendRequestAsync(int command) {
1354 mMainThreadHandler.sendEmptyMessage(command);
1355 }
1356
1357 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001358 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001360 */
1361 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001362 sendRequestAsync(command, argument, null, null);
1363 }
1364
1365 /**
1366 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1367 * @see {@link #sendRequest(int,Object)}
1368 */
1369 private void sendRequestAsync(
1370 int command, Object argument, Phone phone, WorkSource workSource) {
1371 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001372 Message msg = mMainThreadHandler.obtainMessage(command, request);
1373 msg.sendToTarget();
1374 }
1375
1376 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 * Initialize the singleton PhoneInterfaceManager instance.
1378 * This is only done once, at startup, from PhoneApp.onCreate().
1379 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001380 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 synchronized (PhoneInterfaceManager.class) {
1382 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001383 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 } else {
1385 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1386 }
1387 return sInstance;
1388 }
1389 }
1390
1391 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001392 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001395 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1397 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001398 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001399 mTelephonySharedPreferences =
1400 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001401 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001402 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001403
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 publish();
1405 }
1406
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001407 private Phone getDefaultPhone() {
1408 Phone thePhone = getPhone(getDefaultSubscription());
1409 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1410 }
1411
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 private void publish() {
1413 if (DBG) log("publish: " + this);
1414
1415 ServiceManager.addService("phone", this);
1416 }
1417
Stuart Scott584921c2015-01-15 17:10:34 -08001418 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001419 if (request.phone != null) {
1420 return request.phone;
1421 } else {
1422 return getPhoneFromSubId(request.subId);
1423 }
1424 }
1425
1426 private Phone getPhoneFromSubId(int subId) {
1427 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1428 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001429 }
1430
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001431 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1432 Phone phone = getPhoneFromRequest(request);
1433 return phone == null ? null :
1434 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1435 }
1436
Wink Saville36469e72014-06-11 15:17:00 -07001437 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001438 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001439 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001442 private void sendEraseModemConfig(Phone phone) {
1443 if (phone != null) {
1444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1445 mApp, phone.getSubId(), "eraseModemConfig");
1446 final long identity = Binder.clearCallingIdentity();
1447 try {
1448 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1449 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1450 } finally {
1451 Binder.restoreCallingIdentity(identity);
1452 }
1453 }
1454 }
1455
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001457 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001458 }
1459
Wink Savilleb564aae2014-10-23 10:18:09 -07001460 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 if (DBG) log("dial: " + number);
1462 // No permission check needed here: This is just a wrapper around the
1463 // ACTION_DIAL intent, which is available to any app since it puts up
1464 // the UI before it does anything.
1465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001466 final long identity = Binder.clearCallingIdentity();
1467 try {
1468 String url = createTelUrl(number);
1469 if (url == null) {
1470 return;
1471 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001473 // PENDING: should we just silently fail if phone is offhook or ringing?
1474 PhoneConstants.State state = mCM.getState(subId);
1475 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1476 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1477 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1478 mApp.startActivity(intent);
1479 }
1480 } finally {
1481 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 }
1483 }
1484
1485 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001486 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001487 }
1488
Wink Savilleb564aae2014-10-23 10:18:09 -07001489 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 if (DBG) log("call: " + number);
1491
1492 // This is just a wrapper around the ACTION_CALL intent, but we still
1493 // need to do a permission check since we're calling startActivity()
1494 // from the context of the phone app.
1495 enforceCallPermission();
1496
Jordan Liu1617b712019-07-10 15:06:26 -07001497 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 != AppOpsManager.MODE_ALLOWED) {
1499 return;
1500 }
1501
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001502 final long identity = Binder.clearCallingIdentity();
1503 try {
1504 String url = createTelUrl(number);
1505 if (url == null) {
1506 return;
1507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001509 boolean isValid = false;
1510 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1511 if (slist != null) {
1512 for (SubscriptionInfo subInfoRecord : slist) {
1513 if (subInfoRecord.getSubscriptionId() == subId) {
1514 isValid = true;
1515 break;
1516 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001517 }
Wink Saville08874612014-08-31 19:19:58 -07001518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001519 if (!isValid) {
1520 return;
1521 }
Wink Saville08874612014-08-31 19:19:58 -07001522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001523 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1524 intent.putExtra(SUBSCRIPTION_KEY, subId);
1525 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1526 mApp.startActivity(intent);
1527 } finally {
1528 Binder.restoreCallingIdentity(identity);
1529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 }
1531
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001533 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001534 }
1535
Wink Savilleb564aae2014-10-23 10:18:09 -07001536 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001537 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001538 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1539 }
1540
1541 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001542 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001543 }
1544
Wink Savilleb564aae2014-10-23 10:18:09 -07001545 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001546 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001547 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1548 }
1549
1550 /** {@hide} */
1551 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001552 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001553 }
1554
Wink Savilleb564aae2014-10-23 10:18:09 -07001555 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001557
1558 final long identity = Binder.clearCallingIdentity();
1559 try {
1560 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1561 checkSimPin.start();
1562 return checkSimPin.unlockSim(null, pin);
1563 } finally {
1564 Binder.restoreCallingIdentity(identity);
1565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 }
1567
Wink Saville9de0f752013-10-22 19:04:03 -07001568 /** {@hide} */
1569 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001570 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001571 }
1572
Wink Savilleb564aae2014-10-23 10:18:09 -07001573 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001575
1576 final long identity = Binder.clearCallingIdentity();
1577 try {
1578 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1579 checkSimPuk.start();
1580 return checkSimPuk.unlockSim(puk, pin);
1581 } finally {
1582 Binder.restoreCallingIdentity(identity);
1583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001584 }
1585
1586 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001587 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001588 * a synchronous one.
1589 */
1590 private static class UnlockSim extends Thread {
1591
1592 private final IccCard mSimCard;
1593
1594 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001595 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1596 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597
1598 // For replies from SimCard interface
1599 private Handler mHandler;
1600
1601 // For async handler to identify request type
1602 private static final int SUPPLY_PIN_COMPLETE = 100;
1603
1604 public UnlockSim(IccCard simCard) {
1605 mSimCard = simCard;
1606 }
1607
1608 @Override
1609 public void run() {
1610 Looper.prepare();
1611 synchronized (UnlockSim.this) {
1612 mHandler = new Handler() {
1613 @Override
1614 public void handleMessage(Message msg) {
1615 AsyncResult ar = (AsyncResult) msg.obj;
1616 switch (msg.what) {
1617 case SUPPLY_PIN_COMPLETE:
1618 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1619 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001620 mRetryCount = msg.arg1;
1621 if (ar.exception != null) {
1622 if (ar.exception instanceof CommandException &&
1623 ((CommandException)(ar.exception)).getCommandError()
1624 == CommandException.Error.PASSWORD_INCORRECT) {
1625 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1626 } else {
1627 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1628 }
1629 } else {
1630 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001632 mDone = true;
1633 UnlockSim.this.notifyAll();
1634 }
1635 break;
1636 }
1637 }
1638 };
1639 UnlockSim.this.notifyAll();
1640 }
1641 Looper.loop();
1642 }
1643
1644 /*
1645 * Use PIN or PUK to unlock SIM card
1646 *
1647 * If PUK is null, unlock SIM card with PIN
1648 *
1649 * If PUK is not null, unlock SIM card with PUK and set PIN code
1650 */
Wink Saville9de0f752013-10-22 19:04:03 -07001651 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652
1653 while (mHandler == null) {
1654 try {
1655 wait();
1656 } catch (InterruptedException e) {
1657 Thread.currentThread().interrupt();
1658 }
1659 }
1660 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1661
1662 if (puk == null) {
1663 mSimCard.supplyPin(pin, callback);
1664 } else {
1665 mSimCard.supplyPuk(puk, pin, callback);
1666 }
1667
1668 while (!mDone) {
1669 try {
1670 Log.d(LOG_TAG, "wait for done");
1671 wait();
1672 } catch (InterruptedException e) {
1673 // Restore the interrupted status
1674 Thread.currentThread().interrupt();
1675 }
1676 }
1677 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001678 int[] resultArray = new int[2];
1679 resultArray[0] = mResult;
1680 resultArray[1] = mRetryCount;
1681 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 }
1683 }
1684
1685 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001686 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001687
1688 }
1689
Wink Savilleb564aae2014-10-23 10:18:09 -07001690 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 // No permission check needed here: this call is harmless, and it's
1692 // needed for the ServiceState.requestStateUpdate() call (which is
1693 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001694 final long identity = Binder.clearCallingIdentity();
1695 try {
1696 final Phone phone = getPhone(subId);
1697 if (phone != null) {
1698 phone.updateServiceLocation();
1699 }
1700 } finally {
1701 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 }
1704
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001705 @Override
1706 public boolean isRadioOn(String callingPackage) {
1707 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001708 }
1709
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001710 @Override
1711 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001713 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001714 return false;
1715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001716
1717 final long identity = Binder.clearCallingIdentity();
1718 try {
1719 return isRadioOnForSubscriber(subId);
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
1722 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001723 }
1724
1725 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001726 final long identity = Binder.clearCallingIdentity();
1727 try {
1728 final Phone phone = getPhone(subId);
1729 if (phone != null) {
1730 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1731 } else {
1732 return false;
1733 }
1734 } finally {
1735 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 }
1738
1739 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001740 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 }
Wink Saville36469e72014-06-11 15:17:00 -07001742
Wink Savilleb564aae2014-10-23 10:18:09 -07001743 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001745
1746 final long identity = Binder.clearCallingIdentity();
1747 try {
1748 final Phone phone = getPhone(subId);
1749 if (phone != null) {
1750 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1751 }
1752 } finally {
1753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001754 }
Wink Saville36469e72014-06-11 15:17:00 -07001755 }
1756
1757 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001758 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001759 }
1760
Wink Savilleb564aae2014-10-23 10:18:09 -07001761 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001763
1764 final long identity = Binder.clearCallingIdentity();
1765 try {
1766 final Phone phone = getPhone(subId);
1767 if (phone == null) {
1768 return false;
1769 }
1770 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1771 toggleRadioOnOffForSubscriber(subId);
1772 }
1773 return true;
1774 } finally {
1775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 }
Wink Saville36469e72014-06-11 15:17:00 -07001778
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001779 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001780 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001781 /*
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
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002035 public String getNetworkCountryIsoForPhone(int phoneId) {
2036 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2037 // registered cell info, so return a NULL country instead.
2038 final long identity = Binder.clearCallingIdentity();
2039 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002040 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2041 // Get default phone in this case.
2042 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2043 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002044 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002045 // Todo: fix this when we can get the actual cellular network info when the device
2046 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002047 if (TelephonyManager.NETWORK_TYPE_IWLAN
2048 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2049 return "";
2050 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002051 Phone phone = PhoneFactory.getPhone(phoneId);
2052 if (phone != null) {
2053 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002054 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002055 if (sst != null) {
2056 LocaleTracker lt = sst.getLocaleTracker();
2057 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002058 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2059 return lt.getCurrentCountry();
2060 } else if (emergencyNumberTracker != null) {
2061 return emergencyNumberTracker.getEmergencyCountryIso();
2062 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002063 }
2064 }
2065 }
2066 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002067 } finally {
2068 Binder.restoreCallingIdentity(identity);
2069 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002070 }
2071
2072 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002074 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002075 }
2076
Sanket Padawe356d7632015-06-22 14:03:32 -07002077 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002078 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 mApp.enforceCallingOrSelfPermission(
2080 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002081
2082 final long identity = Binder.clearCallingIdentity();
2083 try {
2084 final Phone phone = getPhone(subId);
2085 if (phone != null) {
2086 phone.enableLocationUpdates();
2087 }
2088 } finally {
2089 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 }
2092
2093 @Override
2094 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002095 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002096 }
2097
Sanket Padawe356d7632015-06-22 14:03:32 -07002098 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002099 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 mApp.enforceCallingOrSelfPermission(
2101 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002102
2103 final long identity = Binder.clearCallingIdentity();
2104 try {
2105 final Phone phone = getPhone(subId);
2106 if (phone != null) {
2107 phone.disableLocationUpdates();
2108 }
2109 } finally {
2110 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
2113
Nathan Harold31d7ff32018-10-15 20:20:30 -07002114 /**
2115 * Returns the target SDK version number for a given package name.
2116 *
Nathan Haroldec184742019-07-10 17:04:16 -07002117 * This call MUST be invoked before clearing the calling UID.
2118 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002119 * @return target SDK if the package is found or INT_MAX.
2120 */
2121 private int getTargetSdk(String packageName) {
2122 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002123 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002124 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002125 if (ai != null) return ai.targetSdkVersion;
2126 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002127 loge("Failed to get package info for pkg="
2128 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002129 }
2130 return Integer.MAX_VALUE;
2131 }
2132
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 @Override
2134 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002135 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2136 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002137 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2138 throw new SecurityException(
2139 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2140 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002141
Jordan Liu1617b712019-07-10 15:06:26 -07002142 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2144 return null;
2145 }
Svetoslav64fad262015-04-14 14:35:21 -07002146
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002147 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002148
Nathan Haroldf180aac2018-06-01 18:43:55 -07002149 List<CellInfo> info = getAllCellInfo(callingPackage);
2150 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151
Nathan Haroldf180aac2018-06-01 18:43:55 -07002152 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2153 for (CellInfo ci : info) {
2154 if (ci instanceof CellInfoGsm) {
2155 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2156 } else if (ci instanceof CellInfoWcdma) {
2157 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002160 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 }
2162
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002163 private List<CellInfo> getCachedCellInfo() {
2164 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2165 for (Phone phone : PhoneFactory.getPhones()) {
2166 List<CellInfo> info = phone.getAllCellInfo();
2167 if (info != null) cellInfos.addAll(info);
2168 }
2169 return cellInfos;
2170 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171
2172 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002173 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002174 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002175 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002176
2177 LocationAccessPolicy.LocationPermissionResult locationResult =
2178 LocationAccessPolicy.checkLocationPermission(mApp,
2179 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2180 .setCallingPackage(callingPackage)
2181 .setCallingPid(Binder.getCallingPid())
2182 .setCallingUid(Binder.getCallingUid())
2183 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002184 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002185 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2186 .build());
2187 switch (locationResult) {
2188 case DENIED_HARD:
2189 throw new SecurityException("Not allowed to access cell info");
2190 case DENIED_SOFT:
2191 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 }
2193
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002194 final int targetSdk = getTargetSdk(callingPackage);
2195 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2196 return getCachedCellInfo();
2197 }
2198
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002199 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002200 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002201 final long identity = Binder.clearCallingIdentity();
2202 try {
2203 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2204 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002205 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002206 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002207 if (info != null) cellInfos.addAll(info);
2208 }
2209 return cellInfos;
2210 } finally {
2211 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002212 }
2213 }
2214
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002215 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002216 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2217 requestCellInfoUpdateInternal(
2218 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2219 }
2220
2221 @Override
2222 public void requestCellInfoUpdateWithWorkSource(
2223 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2224 enforceModifyPermission();
2225 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2226 }
2227
2228 private void requestCellInfoUpdateInternal(
2229 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002230 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002231 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002232
2233 LocationAccessPolicy.LocationPermissionResult locationResult =
2234 LocationAccessPolicy.checkLocationPermission(mApp,
2235 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2236 .setCallingPackage(callingPackage)
2237 .setCallingPid(Binder.getCallingPid())
2238 .setCallingUid(Binder.getCallingUid())
2239 .setMethod("requestCellInfoUpdate")
2240 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2241 .build());
2242 switch (locationResult) {
2243 case DENIED_HARD:
2244 throw new SecurityException("Not allowed to access cell info");
2245 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002246 try {
2247 cb.onCellInfo(new ArrayList<CellInfo>());
2248 } catch (RemoteException re) {
2249 // Drop without consequences
2250 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002251 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002252 }
2253
Nathan Harolda939a962019-05-09 10:13:47 -07002254
2255 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002256 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2257
2258 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2259 }
2260
2261 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002263 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002264 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002265
2266 final long identity = Binder.clearCallingIdentity();
2267 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002268 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002269 } finally {
2270 Binder.restoreCallingIdentity(identity);
2271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 }
2273
Shishir Agrawala9f32182016-04-12 12:00:16 -07002274 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002275 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002276 Phone phone = PhoneFactory.getPhone(slotIndex);
2277 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002278 return null;
2279 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002280 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002281 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2282 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002283 return null;
2284 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002285
2286 final long identity = Binder.clearCallingIdentity();
2287 try {
2288 return phone.getImei();
2289 } finally {
2290 Binder.restoreCallingIdentity(identity);
2291 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002292 }
2293
2294 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002295 public String getTypeAllocationCodeForSlot(int slotIndex) {
2296 Phone phone = PhoneFactory.getPhone(slotIndex);
2297 String tac = null;
2298 if (phone != null) {
2299 String imei = phone.getImei();
2300 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2301 }
2302 return tac;
2303 }
2304
2305 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002306 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002307 Phone phone = PhoneFactory.getPhone(slotIndex);
2308 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002309 return null;
2310 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002311
Jeff Davidson913390f2018-02-23 17:11:49 -08002312 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002313 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2314 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002315 return null;
2316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002317
2318 final long identity = Binder.clearCallingIdentity();
2319 try {
2320 return phone.getMeid();
2321 } finally {
2322 Binder.restoreCallingIdentity(identity);
2323 }
Jack Yu2af8d712017-03-15 17:14:14 -07002324 }
2325
2326 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002327 public String getManufacturerCodeForSlot(int slotIndex) {
2328 Phone phone = PhoneFactory.getPhone(slotIndex);
2329 String manufacturerCode = null;
2330 if (phone != null) {
2331 String meid = phone.getMeid();
2332 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2333 }
2334 return manufacturerCode;
2335 }
2336
2337 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002338 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002339 Phone phone = PhoneFactory.getPhone(slotIndex);
2340 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002341 return null;
2342 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002343 int subId = phone.getSubId();
2344 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2345 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2346 return null;
2347 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002348
2349 final long identity = Binder.clearCallingIdentity();
2350 try {
2351 return phone.getDeviceSvn();
2352 } finally {
2353 Binder.restoreCallingIdentity(identity);
2354 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002355 }
2356
fionaxu43304da2017-11-27 22:51:16 -08002357 @Override
2358 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002359 final long identity = Binder.clearCallingIdentity();
2360 try {
2361 final Phone phone = getPhone(subId);
2362 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2363 } finally {
2364 Binder.restoreCallingIdentity(identity);
2365 }
fionaxu43304da2017-11-27 22:51:16 -08002366 }
2367
2368 @Override
2369 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002370 final long identity = Binder.clearCallingIdentity();
2371 try {
2372 final Phone phone = getPhone(subId);
2373 return phone == null ? null : phone.getCarrierName();
2374 } finally {
2375 Binder.restoreCallingIdentity(identity);
2376 }
fionaxu43304da2017-11-27 22:51:16 -08002377 }
2378
calvinpanffe225e2018-11-01 19:43:06 +08002379 @Override
chen xu0026ca62019-03-06 15:28:50 -08002380 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002381 final long identity = Binder.clearCallingIdentity();
2382 try {
2383 final Phone phone = getPhone(subId);
2384 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002385 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002386 } finally {
2387 Binder.restoreCallingIdentity(identity);
2388 }
2389 }
2390
2391 @Override
chen xu0026ca62019-03-06 15:28:50 -08002392 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002393 final long identity = Binder.clearCallingIdentity();
2394 try {
2395 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002396 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002397 } finally {
2398 Binder.restoreCallingIdentity(identity);
2399 }
2400 }
2401
chen xu651eec72018-11-11 19:03:44 -08002402 @Override
chen xu864e11c2018-12-06 22:10:03 -08002403 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2404 if (!isSubscriptionMccMnc) {
2405 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2406 }
chen xu651eec72018-11-11 19:03:44 -08002407 final Phone phone = PhoneFactory.getPhone(slotIndex);
2408 if (phone == null) {
2409 return TelephonyManager.UNKNOWN_CARRIER_ID;
2410 }
2411 final long identity = Binder.clearCallingIdentity();
2412 try {
2413 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2414 } finally {
2415 Binder.restoreCallingIdentity(identity);
2416 }
2417 }
2418
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 //
2420 // Internal helper methods.
2421 //
2422
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002423 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2425 *
2426 * @throws SecurityException if the caller does not have the required permission
2427 */
2428 private void enforceModifyPermission() {
2429 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2430 }
2431
Shuo Qianf2b2df42019-11-13 17:43:31 -08002432 private void enforceActiveEmergencySessionPermission() {
2433 mApp.enforceCallingOrSelfPermission(
2434 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2435 }
2436
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 /**
2438 * Make sure the caller has the CALL_PHONE permission.
2439 *
2440 * @throws SecurityException if the caller does not have the required permission
2441 */
2442 private void enforceCallPermission() {
2443 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2444 }
2445
paulhu423b5f22019-08-23 19:17:33 +08002446 private void enforceSettingsPermission() {
2447 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002448 }
2449
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 private String createTelUrl(String number) {
2451 if (TextUtils.isEmpty(number)) {
2452 return null;
2453 }
2454
Jake Hambye994d462014-02-03 13:10:13 -08002455 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 }
2457
Ihab Awadf9e92732013-12-05 18:02:52 -08002458 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2460 }
2461
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002462 private static void logv(String msg) {
2463 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2464 }
2465
Ihab Awadf9e92732013-12-05 18:02:52 -08002466 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2468 }
2469
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002470 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002472 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002473 }
2474
Sanket Padawe356d7632015-06-22 14:03:32 -07002475 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002476 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477 final long identity = Binder.clearCallingIdentity();
2478 try {
2479 final Phone phone = PhoneFactory.getPhone(slotIndex);
2480 if (phone == null) {
2481 return PhoneConstants.PHONE_TYPE_NONE;
2482 } else {
2483 return phone.getPhoneType();
2484 }
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 }
2489
2490 /**
2491 * Returns the CDMA ERI icon index to display
2492 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002493 @Override
2494 public int getCdmaEriIconIndex(String callingPackage) {
2495 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002496 }
2497
Sanket Padawe356d7632015-06-22 14:03:32 -07002498 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002499 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002500 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002501 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002502 return -1;
2503 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504
2505 final long identity = Binder.clearCallingIdentity();
2506 try {
2507 final Phone phone = getPhone(subId);
2508 if (phone != null) {
2509 return phone.getCdmaEriIconIndex();
2510 } else {
2511 return -1;
2512 }
2513 } finally {
2514 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002515 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 }
2517
2518 /**
2519 * Returns the CDMA ERI icon mode,
2520 * 0 - ON
2521 * 1 - FLASHING
2522 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002523 @Override
2524 public int getCdmaEriIconMode(String callingPackage) {
2525 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002526 }
2527
Sanket Padawe356d7632015-06-22 14:03:32 -07002528 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002529 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002531 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002532 return -1;
2533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002534
2535 final long identity = Binder.clearCallingIdentity();
2536 try {
2537 final Phone phone = getPhone(subId);
2538 if (phone != null) {
2539 return phone.getCdmaEriIconMode();
2540 } else {
2541 return -1;
2542 }
2543 } finally {
2544 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 }
2547
2548 /**
2549 * Returns the CDMA ERI text,
2550 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002551 @Override
2552 public String getCdmaEriText(String callingPackage) {
2553 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002554 }
2555
Sanket Padawe356d7632015-06-22 14:03:32 -07002556 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002557 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002558 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002559 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002560 return null;
2561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562
2563 final long identity = Binder.clearCallingIdentity();
2564 try {
2565 final Phone phone = getPhone(subId);
2566 if (phone != null) {
2567 return phone.getCdmaEriText();
2568 } else {
2569 return null;
2570 }
2571 } finally {
2572 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 }
2575
2576 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002577 * Returns the CDMA MDN.
2578 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002579 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002580 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2582 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002587 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588 return phone.getLine1Number();
2589 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002590 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002591 return null;
2592 }
2593 } finally {
2594 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002595 }
2596 }
2597
2598 /**
2599 * Returns the CDMA MIN.
2600 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002601 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002602 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2604 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605
2606 final long identity = Binder.clearCallingIdentity();
2607 try {
2608 final Phone phone = getPhone(subId);
2609 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2610 return phone.getCdmaMin();
2611 } else {
2612 return null;
2613 }
2614 } finally {
2615 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002616 }
2617 }
2618
Hall Liud892bec2018-11-30 14:51:45 -08002619 @Override
2620 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2621 INumberVerificationCallback callback, String callingPackage) {
2622 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2623 != PERMISSION_GRANTED) {
2624 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2625 }
2626 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2627
2628 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2629 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2630 throw new SecurityException("Calling package must be configured in the device config");
2631 }
2632
2633 if (range == null) {
2634 throw new NullPointerException("Range must be non-null");
2635 }
2636
2637 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002638 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002639
2640 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2641 }
2642
Junda Liuca05d5d2014-08-14 22:36:34 -07002643 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002644 * Returns true if CDMA provisioning needs to run.
2645 */
2646 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647 final long identity = Binder.clearCallingIdentity();
2648 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002649 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650 } finally {
2651 Binder.restoreCallingIdentity(identity);
2652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 }
2654
2655 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002656 * Sets the voice mail number of a given subId.
2657 */
2658 @Override
2659 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002660 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661
2662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2665 new Pair<String, String>(alphaTag, number), new Integer(subId));
2666 return success;
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
2669 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002670 }
2671
Ta-wei Yen87c49842016-05-13 21:19:52 -07002672 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002673 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2674 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002675 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2676 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002677 if (!TextUtils.equals(callingPackage, systemDialer)) {
2678 throw new SecurityException("caller must be system dialer");
2679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680
2681 final long identity = Binder.clearCallingIdentity();
2682 try {
2683 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2684 if (phoneAccountHandle == null) {
2685 return null;
2686 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002687 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 } finally {
2689 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002690 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002691 }
2692
2693 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002694 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002695 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002696 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002697 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002698 return null;
2699 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002701 final long identity = Binder.clearCallingIdentity();
2702 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002703 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002704 } finally {
2705 Binder.restoreCallingIdentity(identity);
2706 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002707 }
2708
2709 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002710 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2711 VisualVoicemailSmsFilterSettings settings) {
2712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713
2714 final long identity = Binder.clearCallingIdentity();
2715 try {
2716 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002717 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 } finally {
2719 Binder.restoreCallingIdentity(identity);
2720 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002721 }
2722
2723 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002724 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2725 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726
2727 final long identity = Binder.clearCallingIdentity();
2728 try {
2729 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002730 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731 } finally {
2732 Binder.restoreCallingIdentity(identity);
2733 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002734 }
2735
2736 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002737 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2738 String callingPackage, int subId) {
2739 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740
2741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002744 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002745 } finally {
2746 Binder.restoreCallingIdentity(identity);
2747 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002748 }
2749
2750 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002751 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002752 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753
2754 final long identity = Binder.clearCallingIdentity();
2755 try {
2756 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002757 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758 } finally {
2759 Binder.restoreCallingIdentity(identity);
2760 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002761 }
2762
2763 @Override
2764 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2765 String number, int port, String text, PendingIntent sentIntent) {
2766 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002767 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002768 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002769 SmsController smsController = PhoneFactory.getSmsController();
2770 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2771 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002772 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002773
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002774 /**
fionaxu0152e512016-11-14 13:36:14 -08002775 * Sets the voice activation state of a given subId.
2776 */
2777 @Override
2778 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2780 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 final Phone phone = getPhone(subId);
2785 if (phone != null) {
2786 phone.setVoiceActivationState(activationState);
2787 } else {
2788 loge("setVoiceActivationState fails with invalid subId: " + subId);
2789 }
2790 } finally {
2791 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002792 }
2793 }
2794
2795 /**
2796 * Sets the data activation state of a given subId.
2797 */
2798 @Override
2799 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2801 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 final Phone phone = getPhone(subId);
2806 if (phone != null) {
2807 phone.setDataActivationState(activationState);
2808 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002809 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002813 }
2814 }
2815
2816 /**
2817 * Returns the voice activation state of a given subId.
2818 */
2819 @Override
2820 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002821 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822
fionaxu0152e512016-11-14 13:36:14 -08002823 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 if (phone != null) {
2827 return phone.getVoiceActivationState();
2828 } else {
2829 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2830 }
2831 } finally {
2832 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002833 }
2834 }
2835
2836 /**
2837 * Returns the data activation state of a given subId.
2838 */
2839 @Override
2840 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002841 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002842
fionaxu0152e512016-11-14 13:36:14 -08002843 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 if (phone != null) {
2847 return phone.getDataActivationState();
2848 } else {
2849 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2850 }
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002853 }
2854 }
2855
2856 /**
Wink Saville36469e72014-06-11 15:17:00 -07002857 * Returns the unread count of voicemails for a subId
2858 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002859 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002860 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2862 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2863 return 0;
2864 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 final Phone phone = getPhone(subId);
2868 if (phone != null) {
2869 return phone.getVoiceMessageCount();
2870 } else {
2871 return 0;
2872 }
2873 } finally {
2874 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 }
2877
2878 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002879 * returns true, if the device is in a state where both voice and data
2880 * are supported simultaneously. This can change based on location or network condition.
2881 */
2882 @Override
2883 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884 final long identity = Binder.clearCallingIdentity();
2885 try {
2886 final Phone phone = getPhone(subId);
2887 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2888 } finally {
2889 Binder.restoreCallingIdentity(identity);
2890 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002891 }
2892
2893 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002894 * Send the dialer code if called from the current default dialer or the caller has
2895 * carrier privilege.
2896 * @param inputCode The dialer code to send
2897 */
2898 @Override
2899 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002900 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002901 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002902 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2903 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002904 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002905 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2906 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908
2909 final long identity = Binder.clearCallingIdentity();
2910 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002911 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002912 } finally {
2913 Binder.restoreCallingIdentity(identity);
2914 }
fionaxu235cc5e2017-03-06 22:25:57 -08002915 }
2916
Pengquan Menga1bb6272018-09-06 09:59:22 -07002917 @Override
2918 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002919 if (!isActiveSubscription(subId)) {
2920 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2921 }
2922
Pengquan Menga1bb6272018-09-06 09:59:22 -07002923 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2924 }
2925
Brad Ebinger35c841c2018-10-01 10:40:55 -07002926 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002927 public boolean isInEmergencySmsMode() {
2928 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2929 final long identity = Binder.clearCallingIdentity();
2930 try {
2931 for (Phone phone : PhoneFactory.getPhones()) {
2932 if (phone.isInEmergencySmsMode()) {
2933 return true;
2934 }
2935 }
2936 } finally {
2937 Binder.restoreCallingIdentity(identity);
2938 }
2939 return false;
2940 }
2941
2942 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002943 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2944 throws RemoteException {
2945 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002946 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2947 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2948 "IMS not available on device.");
2949 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002950 final long token = Binder.clearCallingIdentity();
2951 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002952 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002953 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002954 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002955 } catch (ImsException e) {
2956 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002957 } finally {
2958 Binder.restoreCallingIdentity(token);
2959 }
2960 }
2961
2962 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002963 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2964 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002965 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2966 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2967 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002968 final long token = Binder.clearCallingIdentity();
2969 try {
2970 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2971 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2972 .removeRegistrationCallbackForSubscription(c, subId);
2973 } catch (ImsException e) {
2974 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2975 + "is inactive, ignoring unregister.");
2976 // If the subscription is no longer active, just return, since the callback
2977 // will already have been removed internally.
2978 } finally {
2979 Binder.restoreCallingIdentity(token);
2980 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002981 }
2982
Brad Ebinger774ba362019-10-22 17:36:18 -07002983 /**
2984 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2985 */
2986 @Override
2987 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2988 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2989 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2990 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2991 "IMS not available on device.");
2992 }
2993 final long token = Binder.clearCallingIdentity();
2994 try {
2995 Phone phone = getPhone(subId);
2996 if (phone == null) {
2997 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2998 + subId + "'");
2999 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3000 }
3001 phone.getImsRegistrationState(regState -> {
3002 try {
3003 consumer.accept((regState == null)
3004 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3005 } catch (RemoteException e) {
3006 // Ignore if the remote process is no longer available to call back.
3007 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3008 }
3009 });
3010 } finally {
3011 Binder.restoreCallingIdentity(token);
3012 }
3013 }
3014
3015 /**
3016 * Get the transport type for the IMS service registration state.
3017 */
3018 @Override
3019 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3020 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3021 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3022 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3023 "IMS not available on device.");
3024 }
3025 final long token = Binder.clearCallingIdentity();
3026 try {
3027 Phone phone = getPhone(subId);
3028 if (phone == null) {
3029 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3030 + subId + "'");
3031 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3032 }
3033 phone.getImsRegistrationTech(regTech -> {
3034 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3035 int regTechConverted = (regTech == null)
3036 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3037 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3038 regTechConverted);
3039 try {
3040 consumer.accept(regTechConverted);
3041 } catch (RemoteException e) {
3042 // Ignore if the remote process is no longer available to call back.
3043 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3044 }
3045 });
3046 } finally {
3047 Binder.restoreCallingIdentity(token);
3048 }
3049 }
3050
Brad Ebinger35c841c2018-10-01 10:40:55 -07003051 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003052 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3053 throws RemoteException {
3054 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003055 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3056 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3057 "IMS not available on device.");
3058 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003059 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3060 final long token = Binder.clearCallingIdentity();
3061 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003062 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003063 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003064 } catch (ImsException e) {
3065 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003066 } finally {
3067 Binder.restoreCallingIdentity(token);
3068 }
3069 }
3070
3071 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003072 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3073 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003074 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3075 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3076 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003077
3078 final long token = Binder.clearCallingIdentity();
3079 try {
3080 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3081 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003082 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003083 } catch (ImsException e) {
3084 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3085 + "is inactive, ignoring unregister.");
3086 // If the subscription is no longer active, just return, since the callback
3087 // will already have been removed internally.
3088 } finally {
3089 Binder.restoreCallingIdentity(token);
3090 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003091 }
3092
3093 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003094 public boolean isCapable(int subId, int capability, int regTech) {
3095 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003096 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3097 final long token = Binder.clearCallingIdentity();
3098 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003099 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003100 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003101 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003102 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3103 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003104 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003105 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3106 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003107 } finally {
3108 Binder.restoreCallingIdentity(token);
3109 }
3110 }
3111
3112 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003113 public boolean isAvailable(int subId, int capability, int regTech) {
3114 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003115 final long token = Binder.clearCallingIdentity();
3116 try {
3117 Phone phone = getPhone(subId);
3118 if (phone == null) return false;
3119 return phone.isImsCapabilityAvailable(capability, regTech);
3120 } finally {
3121 Binder.restoreCallingIdentity(token);
3122 }
3123 }
3124
Brad Ebinger77b832e2019-10-17 17:03:22 -07003125 /**
3126 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3127 * subscription.
3128 * @param subId The subscription to use to check the configuration.
3129 * @param callback The callback that will be used to send the result.
3130 * @param capability The MmTelFeature capability that will be used to send the result.
3131 * @param transportType The transport type of the MmTelFeature capability.
3132 */
3133 @Override
3134 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3135 int transportType) {
3136 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3137 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3138 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3139 "IMS not available on device.");
3140 }
3141 final long token = Binder.clearCallingIdentity();
3142 try {
3143 int slotId = getSlotIndex(subId);
3144 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3145 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3146 + subId + "'");
3147 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3148 }
3149 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3150 transportType, aBoolean -> {
3151 try {
3152 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3153 } catch (RemoteException e) {
3154 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3155 + "running. Ignore");
3156 }
3157 });
3158 } finally {
3159 Binder.restoreCallingIdentity(token);
3160 }
3161 }
3162
Brad Ebinger35c841c2018-10-01 10:40:55 -07003163 @Override
3164 public boolean isAdvancedCallingSettingEnabled(int subId) {
3165 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3166 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3167 final long token = Binder.clearCallingIdentity();
3168 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003169 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003170 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003171 } catch (ImsException e) {
3172 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003173 } finally {
3174 Binder.restoreCallingIdentity(token);
3175 }
3176 }
3177
3178 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003179 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003181 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003185 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003186 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003187 } catch (ImsException e) {
3188 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003189 } finally {
3190 Binder.restoreCallingIdentity(identity);
3191 }
3192 }
3193
3194 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003195 public boolean isVtSettingEnabled(int subId) {
3196 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003197 final long identity = Binder.clearCallingIdentity();
3198 try {
3199 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003200 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3201 } catch (ImsException e) {
3202 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003203 } finally {
3204 Binder.restoreCallingIdentity(identity);
3205 }
3206 }
3207
3208 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003209 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003211 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003215 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003216 } catch (ImsException e) {
3217 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003218 } finally {
3219 Binder.restoreCallingIdentity(identity);
3220 }
3221 }
3222
3223 @Override
3224 public boolean isVoWiFiSettingEnabled(int subId) {
3225 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3226 final long identity = Binder.clearCallingIdentity();
3227 try {
3228 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003229 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003230 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003231 } catch (ImsException e) {
3232 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003233 } finally {
3234 Binder.restoreCallingIdentity(identity);
3235 }
3236 }
3237
3238 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003239 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003241 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003245 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003246 } catch (ImsException e) {
3247 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 } finally {
3249 Binder.restoreCallingIdentity(identity);
3250 }
3251 }
3252
3253 @Override
3254 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3255 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3256 final long identity = Binder.clearCallingIdentity();
3257 try {
3258 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003259 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003260 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003261 } catch (ImsException e) {
3262 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003263 } finally {
3264 Binder.restoreCallingIdentity(identity);
3265 }
3266 }
3267
3268 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003269 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003271 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003272 final long identity = Binder.clearCallingIdentity();
3273 try {
3274 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003275 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003276 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003277 } catch (ImsException e) {
3278 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003279 } finally {
3280 Binder.restoreCallingIdentity(identity);
3281 }
3282 }
3283
3284 @Override
3285 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3287 "setVoWiFiNonPersistent");
3288 final long identity = Binder.clearCallingIdentity();
3289 try {
3290 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003291 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003292 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003293 } catch (ImsException e) {
3294 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003295 } finally {
3296 Binder.restoreCallingIdentity(identity);
3297 }
3298 }
3299
3300 @Override
3301 public int getVoWiFiModeSetting(int subId) {
3302 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3303 final long identity = Binder.clearCallingIdentity();
3304 try {
3305 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003306 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003307 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003308 } catch (ImsException e) {
3309 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003310 } finally {
3311 Binder.restoreCallingIdentity(identity);
3312 }
3313 }
3314
3315 @Override
3316 public void setVoWiFiModeSetting(int subId, int mode) {
3317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3318 "setVoWiFiModeSetting");
3319 final long identity = Binder.clearCallingIdentity();
3320 try {
3321 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003322 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003323 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003324 } catch (ImsException e) {
3325 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003326 } finally {
3327 Binder.restoreCallingIdentity(identity);
3328 }
3329 }
3330
3331 @Override
3332 public int getVoWiFiRoamingModeSetting(int subId) {
3333 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003337 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003338 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003339 } catch (ImsException e) {
3340 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003341 } finally {
3342 Binder.restoreCallingIdentity(identity);
3343 }
3344 }
3345
3346 @Override
3347 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3349 "setVoWiFiRoamingModeSetting");
3350 final long identity = Binder.clearCallingIdentity();
3351 try {
3352 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003353 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003354 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003355 } catch (ImsException e) {
3356 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003357 } finally {
3358 Binder.restoreCallingIdentity(identity);
3359 }
3360 }
3361
3362 @Override
3363 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3365 "setRttCapabilityEnabled");
3366 final long identity = Binder.clearCallingIdentity();
3367 try {
3368 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003369 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3370 } catch (ImsException e) {
3371 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003372 } finally {
3373 Binder.restoreCallingIdentity(identity);
3374 }
3375 }
3376
3377 @Override
3378 public boolean isTtyOverVolteEnabled(int subId) {
3379 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3380 final long identity = Binder.clearCallingIdentity();
3381 try {
3382 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003383 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003384 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003385 } catch (ImsException e) {
3386 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003387 } finally {
3388 Binder.restoreCallingIdentity(identity);
3389 }
3390 }
3391
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003392 @Override
3393 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3394 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3395 final long identity = Binder.clearCallingIdentity();
3396 try {
3397 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003398 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003399 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003400 } catch (ImsException e) {
3401 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003402 } finally {
3403 Binder.restoreCallingIdentity(identity);
3404 }
3405 }
3406
3407 @Override
3408 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3409 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3410 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003411 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3412 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3413 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003414 try {
3415 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003416 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003417 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003418 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003419 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3420 + "is inactive, ignoring unregister.");
3421 // If the subscription is no longer active, just return, since the callback will already
3422 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003423 } finally {
3424 Binder.restoreCallingIdentity(identity);
3425 }
3426 }
3427
3428 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003429 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3430 boolean isProvisioned) {
3431 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3432 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3433 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3434 }
3435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3436 "setProvisioningStatusForCapability");
3437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3440 Phone phone = getPhone(subId);
3441 if (phone == null) {
3442 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3443 + subId);
3444 return;
3445 }
3446 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3447 return;
3448 }
3449
3450 // this capability requires provisioning, route to the correct API.
3451 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3452 switch (capability) {
3453 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3454 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3455 ims.setVolteProvisioned(isProvisioned);
3456 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3457 ims.setWfcProvisioned(isProvisioned);
3458 }
3459 break;
3460 }
3461 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3462 // There is currently no difference in VT provisioning type.
3463 ims.setVtProvisioned(isProvisioned);
3464 break;
3465 }
3466 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3467 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3468 // change the capability of the feature instead if needed.
3469 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3470 == isProvisioned) {
3471 // No change in provisioning.
3472 return;
3473 }
3474 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3475 try {
3476 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003477 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003478 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3479 + ", Exception" + e.getMessage());
3480 }
3481 break;
3482 }
3483 default: {
3484 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3485 + capability + "', which does not require provisioning.");
3486 }
3487 }
3488
3489 } finally {
3490 Binder.restoreCallingIdentity(identity);
3491 }
3492 }
3493
3494 @Override
3495 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3496 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3497 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3498 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3499 }
3500 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3501 final long identity = Binder.clearCallingIdentity();
3502 try {
3503 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3504 Phone phone = getPhone(subId);
3505 if (phone == null) {
3506 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3507 + subId);
3508 // We will fail with "true" as the provisioning status because this is the default
3509 // if we do not require provisioning.
3510 return true;
3511 }
3512
3513 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3514 return true;
3515 }
3516
3517 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3518 switch (capability) {
3519 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3520 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3521 return ims.isVolteProvisionedOnDevice();
3522 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3523 return ims.isWfcProvisionedOnDevice();
3524 }
3525 // This should never happen, since we are checking tech above to make sure it
3526 // is either LTE or IWLAN.
3527 throw new IllegalArgumentException("Invalid radio technology for voice "
3528 + "capability.");
3529 }
3530 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3531 // There is currently no difference in VT provisioning type.
3532 return ims.isVtProvisionedOnDevice();
3533 }
3534 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3535 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3536 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3537 }
3538 default: {
3539 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3540 + capability + "', which does not require provisioning.");
3541 }
3542 }
3543
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
3546 }
3547 }
3548
3549 @Override
3550 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3551 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3552 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3553 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3554 }
3555 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3556 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3557 return (provisionedBits & capability) > 0;
3558 }
3559
3560 @Override
3561 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3562 boolean isProvisioned) {
3563 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3564 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3565 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3566 }
3567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3568 "setProvisioningStatusForCapability");
3569 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3570 // If the current provisioning status for capability already matches isProvisioned,
3571 // do nothing.
3572 if (((provisionedBits & capability) > 0) == isProvisioned) {
3573 return;
3574 }
3575 if (isProvisioned) {
3576 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3577 } else {
3578 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3579 }
3580 }
3581
3582 /**
3583 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3584 * technology. The bitfield should mirror the bitfield defined by
3585 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3586 */
3587 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3588 String key = getMmTelProvisioningKey(subId, tech);
3589 // Default is no capabilities are provisioned.
3590 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3591 }
3592
3593 /**
3594 * Sets the MmTel capability provisioning bitfield (defined by
3595 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3596 * technology specified.
3597 *
3598 * Note: This is a synchronous command and should not be called on UI thread.
3599 */
3600 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3601 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3602 String key = getMmTelProvisioningKey(subId, tech);
3603 editor.putInt(key, newField);
3604 editor.commit();
3605 }
3606
3607 private static String getMmTelProvisioningKey(int subId, int tech) {
3608 // resulting key is provision_ims_mmtel_{subId}_{tech}
3609 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3610 }
3611
3612 /**
3613 * Query CarrierConfig to see if the specified capability requires provisioning for the
3614 * carrier associated with the subscription id.
3615 */
3616 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3617 int capability) {
3618 CarrierConfigManager configManager = new CarrierConfigManager(context);
3619 PersistableBundle c = configManager.getConfigForSubId(subId);
3620 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003621 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003622 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3623 false);
3624 boolean requireVoiceVtProvisioning = c.getBoolean(
3625 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3626
3627 // First check to make sure that the capability requires provisioning.
3628 switch (capability) {
3629 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3630 // intentional fallthrough
3631 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3632 if (requireVoiceVtProvisioning) {
3633 // Voice and Video requires provisioning
3634 return true;
3635 }
3636 break;
3637 }
3638 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3639 if (requireUtProvisioning) {
3640 // UT requires provisioning
3641 return true;
3642 }
3643 break;
3644 }
3645 }
3646 return false;
3647 }
3648
3649 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003650 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003651 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3652 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3653 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003654 enforceReadPrivilegedPermission("getImsProvisioningInt");
3655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003658 int slotId = getSlotIndex(subId);
3659 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3660 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3661 + subId + "' for key:" + key);
3662 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3663 }
3664 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003665 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003666 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3667 + subId + "' for key:" + key);
3668 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003669 } finally {
3670 Binder.restoreCallingIdentity(identity);
3671 }
3672 }
3673
3674 @Override
3675 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003676 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3677 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3678 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003679 enforceReadPrivilegedPermission("getImsProvisioningString");
3680 final long identity = Binder.clearCallingIdentity();
3681 try {
3682 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003683 int slotId = getSlotIndex(subId);
3684 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3685 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3686 + subId + "' for key:" + key);
3687 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3688 }
3689 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003690 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003691 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3692 + subId + "' for key:" + key);
3693 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003694 } finally {
3695 Binder.restoreCallingIdentity(identity);
3696 }
3697 }
3698
3699 @Override
3700 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003701 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3702 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3703 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3705 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003709 int slotId = getSlotIndex(subId);
3710 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3711 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3712 + subId + "' for key:" + key);
3713 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3714 }
3715 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003716 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003717 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3718 + "' for key:" + key);
3719 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
3723 }
3724
3725 @Override
3726 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003727 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3728 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3729 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3731 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003732 final long identity = Binder.clearCallingIdentity();
3733 try {
3734 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003735 int slotId = getSlotIndex(subId);
3736 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3737 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3738 + subId + "' for key:" + key);
3739 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3740 }
3741 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003742 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003743 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3744 + "' for key:" + key);
3745 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003746 } finally {
3747 Binder.restoreCallingIdentity(identity);
3748 }
3749 }
3750
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003751 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003752 int slotId = SubscriptionManager.getSlotIndex(subId);
3753 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003754 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3755 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 }
3757 return slotId;
3758 }
3759
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003760 private int getSlotIndex(int subId) {
3761 int slotId = SubscriptionManager.getSlotIndex(subId);
3762 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3763 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3764 }
3765 return slotId;
3766 }
3767
Wink Saville36469e72014-06-11 15:17:00 -07003768 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003769 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003770 */
3771 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003772 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003773 final int targetSdk = getTargetSdk(callingPackage);
3774 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3775 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3776 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003777 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3778 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003779 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3780 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003782 final long identity = Binder.clearCallingIdentity();
3783 try {
3784 final Phone phone = getPhone(subId);
3785 if (phone != null) {
3786 return phone.getServiceState().getDataNetworkType();
3787 } else {
3788 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3789 }
3790 } finally {
3791 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003793 }
3794
3795 /**
3796 * Returns the data network type
3797 */
3798 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003799 public int getDataNetworkType(String callingPackage) {
3800 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003801 }
3802
3803 /**
3804 * Returns the data network type for a subId
3805 */
3806 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003807 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003808 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003809 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003810 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3811 }
3812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 final Phone phone = getPhone(subId);
3816 if (phone != null) {
3817 return phone.getServiceState().getDataNetworkType();
3818 } else {
3819 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3820 }
3821 } finally {
3822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003824 }
3825
3826 /**
Wink Saville36469e72014-06-11 15:17:00 -07003827 * Returns the Voice network type for a subId
3828 */
3829 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003830 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003831 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003832 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003833 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3834 }
3835
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003836 final long identity = Binder.clearCallingIdentity();
3837 try {
3838 final Phone phone = getPhone(subId);
3839 if (phone != null) {
3840 return phone.getServiceState().getVoiceNetworkType();
3841 } else {
3842 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3843 }
3844 } finally {
3845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003847 }
3848
3849 /**
3850 * @return true if a ICC card is present
3851 */
3852 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003853 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003854 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3855 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003856 }
3857
3858 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003859 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003860 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003861 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003862 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003863 final long identity = Binder.clearCallingIdentity();
3864 try {
3865 final Phone phone = PhoneFactory.getPhone(slotIndex);
3866 if (phone != null) {
3867 return phone.getIccCard().hasIccCard();
3868 } else {
3869 return false;
3870 }
3871 } finally {
3872 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003874 }
3875
3876 /**
3877 * Return if the current radio is LTE on CDMA. This
3878 * is a tri-state return value as for a period of time
3879 * the mode may be unknown.
3880 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003881 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003882 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003883 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003884 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003885 @Override
3886 public int getLteOnCdmaMode(String callingPackage) {
3887 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003888 }
3889
Sanket Padawe356d7632015-06-22 14:03:32 -07003890 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003891 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003893 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003894 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3895 }
3896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 final Phone phone = getPhone(subId);
3900 if (phone == null) {
3901 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3902 } else {
3903 return phone.getLteOnCdmaMode();
3904 }
3905 } finally {
3906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003907 }
Wink Saville36469e72014-06-11 15:17:00 -07003908 }
3909
Wink Saville36469e72014-06-11 15:17:00 -07003910 /**
3911 * {@hide}
3912 * Returns Default subId, 0 in the case of single standby.
3913 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003914 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003915 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003916 }
3917
Shishir Agrawala9f32182016-04-12 12:00:16 -07003918 private int getSlotForDefaultSubscription() {
3919 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3920 }
3921
Wink Savilleb564aae2014-10-23 10:18:09 -07003922 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003923 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003924 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003925
Pengquan Menge92a50d2018-09-21 15:54:48 -07003926 private boolean isActiveSubscription(int subId) {
3927 return mSubscriptionController.isActiveSubId(subId);
3928 }
3929
Ihab Awadf2177b72013-11-25 13:33:23 -08003930 /**
3931 * @see android.telephony.TelephonyManager.WifiCallingChoices
3932 */
3933 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003934 final long identity = Binder.clearCallingIdentity();
3935 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003936 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003937 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3938 getWhenToMakeWifiCallsDefaultPreference());
3939 } finally {
3940 Binder.restoreCallingIdentity(identity);
3941 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003942 }
3943
3944 /**
3945 * @see android.telephony.TelephonyManager.WifiCallingChoices
3946 */
3947 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003948 final long identity = Binder.clearCallingIdentity();
3949 try {
3950 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003951 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3953 } finally {
3954 Binder.restoreCallingIdentity(identity);
3955 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003956 }
3957
Sailesh Nepald1e68152013-12-12 19:08:02 -08003958 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003959 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003960 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003961 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003962
Jordan Liu4c733742019-02-28 12:03:40 -08003963 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3964 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3965 if (phoneId == -1) {
3966 throw new IllegalArgumentException("Given slot index: " + slotIndex
3967 + " does not correspond to an active phone");
3968 }
3969 return PhoneFactory.getPhone(phoneId);
3970 }
3971
Shishir Agrawal566b7612013-10-28 14:41:00 -07003972 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003973 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3974 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3976 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003977 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003978 if (DBG) {
3979 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3980 }
3981 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3982 p2);
3983 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003984
Jordan Liu4c733742019-02-28 12:03:40 -08003985
3986 @Override
3987 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3988 int slotIndex, String callingPackage, String aid, int p2) {
3989 enforceModifyPermission();
3990 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3991 if (DBG) {
3992 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3993 }
3994 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3995 callingPackage, aid, p2);
3996 }
3997
3998 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3999 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004000 final long identity = Binder.clearCallingIdentity();
4001 try {
4002 if (TextUtils.equals(ISDR_AID, aid)) {
4003 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004004 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4005 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004006 if (bestComponent == null
4007 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4008 loge("The calling package is not allowed to access ISD-R.");
4009 throw new SecurityException(
4010 "The calling package is not allowed to access ISD-R.");
4011 }
Derek Tan740e1672017-06-27 14:56:27 -07004012 }
Derek Tan740e1672017-06-27 14:56:27 -07004013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004015 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4016 null /* workSource */);
4017 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004018 return response;
4019 } finally {
4020 Binder.restoreCallingIdentity(identity);
4021 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004022 }
4023
4024 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004025 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4027 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004028 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4029 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4030 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004031
Jordan Liu4c733742019-02-28 12:03:40 -08004032 @Override
4033 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4034 enforceModifyPermission();
4035 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4036 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4037 channel);
4038 }
4039
4040 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004041 final long identity = Binder.clearCallingIdentity();
4042 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004043 if (channel < 0) {
4044 return false;
4045 }
Jordan Liu4c733742019-02-28 12:03:40 -08004046 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4047 null /* workSource */);
4048 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049 return success;
4050 } finally {
4051 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004052 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004053 }
4054
4055 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004056 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004057 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4059 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004060 if (DBG) {
4061 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4062 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4063 + p3 + " data=" + data);
4064 }
4065 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4066 command, p1, p2, p3, data);
4067 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004068
Jordan Liu4c733742019-02-28 12:03:40 -08004069 @Override
4070 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4071 int command, int p1, int p2, int p3, String data) {
4072 enforceModifyPermission();
4073 if (DBG) {
4074 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4075 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4076 + p3 + " data=" + data);
4077 }
4078 return iccTransmitApduLogicalChannelWithPermission(
4079 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4080 data);
4081 }
4082
4083 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4084 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085 final long identity = Binder.clearCallingIdentity();
4086 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004087 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004088 return "";
4089 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004091 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004092 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4093 null /* workSource */);
4094 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096 // Append the returned status code to the end of the response payload.
4097 String s = Integer.toHexString(
4098 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4099 if (response.payload != null) {
4100 s = IccUtils.bytesToHexString(response.payload) + s;
4101 }
4102 return s;
4103 } finally {
4104 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004105 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004106 }
Jake Hambye994d462014-02-03 13:10:13 -08004107
Evan Charltonc66da362014-05-16 14:06:40 -07004108 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004109 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4110 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4112 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004113 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004114 if (DBG) {
4115 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4116 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4117 }
4118 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4119 cla, command, p1, p2, p3, data);
4120 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004121
Jordan Liu4c733742019-02-28 12:03:40 -08004122 @Override
4123 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4124 int command, int p1, int p2, int p3, String data) {
4125 enforceModifyPermission();
4126 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4127 if (DBG) {
4128 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4129 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4130 + " data=" + data);
4131 }
4132
4133 return iccTransmitApduBasicChannelWithPermission(
4134 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4135 p2, p3, data);
4136 }
4137
4138 // open APDU basic channel assuming the caller has sufficient permissions
4139 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4140 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004141 final long identity = Binder.clearCallingIdentity();
4142 try {
4143 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4144 && TextUtils.equals(ISDR_AID, data)) {
4145 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004146 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4147 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148 if (bestComponent == null
4149 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4150 loge("The calling package is not allowed to select ISD-R.");
4151 throw new SecurityException(
4152 "The calling package is not allowed to select ISD-R.");
4153 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004154 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004156 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004157 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4158 null /* workSource */);
4159 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004161 // Append the returned status code to the end of the response payload.
4162 String s = Integer.toHexString(
4163 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4164 if (response.payload != null) {
4165 s = IccUtils.bytesToHexString(response.payload) + s;
4166 }
4167 return s;
4168 } finally {
4169 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004170 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004171 }
4172
4173 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004174 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004175 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4177 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004179 final long identity = Binder.clearCallingIdentity();
4180 try {
4181 if (DBG) {
4182 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4183 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4184 }
4185
4186 IccIoResult response =
4187 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4188 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4189 subId);
4190
4191 if (DBG) {
4192 log("Exchange SIM_IO [R]" + response);
4193 }
4194
4195 byte[] result = null;
4196 int length = 2;
4197 if (response.payload != null) {
4198 length = 2 + response.payload.length;
4199 result = new byte[length];
4200 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4201 } else {
4202 result = new byte[length];
4203 }
4204
4205 result[length - 1] = (byte) response.sw2;
4206 result[length - 2] = (byte) response.sw1;
4207 return result;
4208 } finally {
4209 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004210 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004211 }
4212
Nathan Haroldb3014052017-01-25 15:57:32 -08004213 /**
4214 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4215 * on a particular subscription
4216 */
sqianb6e41952018-03-12 14:54:01 -07004217 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4219 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4220 return null;
4221 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004222
4223 final long identity = Binder.clearCallingIdentity();
4224 try {
4225 if (appType != TelephonyManager.APPTYPE_USIM
4226 && appType != TelephonyManager.APPTYPE_SIM) {
4227 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4228 return null;
4229 }
4230 Object response = sendRequest(
4231 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4232 if (response instanceof String[]) {
4233 return (String[]) response;
4234 }
yincheng zhaod698b842019-09-06 17:06:54 -07004235 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004236 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004237 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238 } finally {
4239 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004240 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004241 }
4242
yincheng zhaod698b842019-09-06 17:06:54 -07004243 /**
4244 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4245 * subscription.
4246 *
4247 * @param subId the id of the subscription.
4248 * @param appType the uicc app type, must be USIM or SIM.
4249 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4250 * @param callingPackage the op Package name.
4251 * @return number of fplmns that is successfully written to the SIM.
4252 */
4253 public int setForbiddenPlmns(
4254 int subId, int appType, List<String> fplmns, String callingPackage) {
4255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4256 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4257 if (DBG) logv("no permissions for setForbiddenplmns");
4258 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4259 }
4260 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4261 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4262 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4263 }
4264 if (fplmns == null) {
4265 throw new IllegalArgumentException("Fplmn List provided is null");
4266 }
4267 for (String fplmn : fplmns) {
4268 if (!CellIdentity.isValidPlmn(fplmn)) {
4269 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4270 }
4271 }
4272 final long identity = Binder.clearCallingIdentity();
4273 try {
4274 Object response = sendRequest(
4275 CMD_SET_FORBIDDEN_PLMNS,
4276 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4277 subId);
4278 return (int) response;
4279 } finally {
4280 Binder.restoreCallingIdentity(identity);
4281 }
4282 }
4283
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004284 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004285 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4287 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 final long identity = Binder.clearCallingIdentity();
4290 try {
4291 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4292 if (response.payload == null) {
4293 return "";
4294 }
Evan Charltonc66da362014-05-16 14:06:40 -07004295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296 // Append the returned status code to the end of the response payload.
4297 String s = Integer.toHexString(
4298 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4299 s = IccUtils.bytesToHexString(response.payload) + s;
4300 return s;
4301 } finally {
4302 Binder.restoreCallingIdentity(identity);
4303 }
Evan Charltonc66da362014-05-16 14:06:40 -07004304 }
4305
Jake Hambye994d462014-02-03 13:10:13 -08004306 /**
4307 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4308 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4309 *
4310 * @param itemID the ID of the item to read
4311 * @return the NV item as a String, or null on error.
4312 */
4313 @Override
4314 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004315 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4317 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004318
4319 final long identity = Binder.clearCallingIdentity();
4320 try {
4321 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004322 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004323 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4324 return value;
4325 } finally {
4326 Binder.restoreCallingIdentity(identity);
4327 }
Jake Hambye994d462014-02-03 13:10:13 -08004328 }
4329
4330 /**
4331 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4332 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4333 *
4334 * @param itemID the ID of the item to read
4335 * @param itemValue the value to write, as a String
4336 * @return true on success; false on any failure
4337 */
4338 @Override
4339 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004340 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4342 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343
4344 final long identity = Binder.clearCallingIdentity();
4345 try {
4346 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4347 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004348 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004349 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4350 return success;
4351 } finally {
4352 Binder.restoreCallingIdentity(identity);
4353 }
Jake Hambye994d462014-02-03 13:10:13 -08004354 }
4355
4356 /**
4357 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4358 * Used for device configuration by some CDMA operators.
4359 *
4360 * @param preferredRoamingList byte array containing the new PRL
4361 * @return true on success; false on any failure
4362 */
4363 @Override
4364 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4366 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367
4368 final long identity = Binder.clearCallingIdentity();
4369 try {
4370 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4371 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4372 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4373 return success;
4374 } finally {
4375 Binder.restoreCallingIdentity(identity);
4376 }
Jake Hambye994d462014-02-03 13:10:13 -08004377 }
4378
4379 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004380 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004381 * Used for device configuration by some CDMA operators.
4382 *
chen xu6dac5ab2018-10-26 17:39:23 -07004383 * @param slotIndex - device slot.
4384 *
Jake Hambye994d462014-02-03 13:10:13 -08004385 * @return true on success; false on any failure
4386 */
4387 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004388 public boolean resetModemConfig(int slotIndex) {
4389 Phone phone = PhoneFactory.getPhone(slotIndex);
4390 if (phone != null) {
4391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4392 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393
chen xu6dac5ab2018-10-26 17:39:23 -07004394 final long identity = Binder.clearCallingIdentity();
4395 try {
4396 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4397 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4398 return success;
4399 } finally {
4400 Binder.restoreCallingIdentity(identity);
4401 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 }
chen xu6dac5ab2018-10-26 17:39:23 -07004403 return false;
4404 }
4405
4406 /**
4407 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4408 *
4409 * @param slotIndex - device slot.
4410 *
4411 * @return true on success; false on any failure
4412 */
4413 @Override
4414 public boolean rebootModem(int slotIndex) {
4415 Phone phone = PhoneFactory.getPhone(slotIndex);
4416 if (phone != null) {
4417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4418 mApp, phone.getSubId(), "rebootModem");
4419
4420 final long identity = Binder.clearCallingIdentity();
4421 try {
4422 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4423 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4424 return success;
4425 } finally {
4426 Binder.restoreCallingIdentity(identity);
4427 }
4428 }
4429 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004430 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004431
Svet Ganovb320e182015-04-16 12:30:10 -07004432 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004433 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004434 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004435 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004436 return new String[0];
4437 }
4438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004439 final long identity = Binder.clearCallingIdentity();
4440 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004441 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 } finally {
4443 Binder.restoreCallingIdentity(identity);
4444 }
Wink Saville36469e72014-06-11 15:17:00 -07004445 }
4446
Brad Ebinger51f743a2017-01-23 13:50:20 -08004447 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004448 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4449 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004450 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004451 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004452 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004453
4454 final long identity = Binder.clearCallingIdentity();
4455 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004456 ImsResolver resolver = PhoneFactory.getImsResolver();
4457 if (resolver == null) {
4458 // may happen if the device does not support IMS.
4459 return;
4460 }
4461 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004462 } finally {
4463 Binder.restoreCallingIdentity(identity);
4464 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004465 }
4466
4467 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004468 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4469 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004470 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004471 public void disableIms(int slotId) {
4472 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004473
4474 final long identity = Binder.clearCallingIdentity();
4475 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004476 ImsResolver resolver = PhoneFactory.getImsResolver();
4477 if (resolver == null) {
4478 // may happen if the device does not support IMS.
4479 return;
4480 }
4481 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004485 }
4486
4487 /**
4488 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4489 * feature or {@link null} if the service is not available. If the feature is available, the
4490 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4491 */
4492 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004493 IImsServiceFeatureCallback callback) {
4494 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495
4496 final long identity = Binder.clearCallingIdentity();
4497 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004498 ImsResolver resolver = PhoneFactory.getImsResolver();
4499 if (resolver == null) {
4500 // may happen if the device does not support IMS.
4501 return null;
4502 }
4503 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004504 } finally {
4505 Binder.restoreCallingIdentity(identity);
4506 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004507 }
4508
4509 /**
4510 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4511 * feature during emergency calling or {@link null} if the service is not available. If the
4512 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4513 * listener for feature updates.
4514 */
4515 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4516 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517
4518 final long identity = Binder.clearCallingIdentity();
4519 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004520 ImsResolver resolver = PhoneFactory.getImsResolver();
4521 if (resolver == null) {
4522 // may happen if the device does not support IMS.
4523 return null;
4524 }
4525 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004526 } finally {
4527 Binder.restoreCallingIdentity(identity);
4528 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004529 }
4530
Brad Ebinger5f64b052017-12-14 14:26:15 -08004531 /**
4532 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004533 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004534 */
4535 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4536 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004537
4538 final long identity = Binder.clearCallingIdentity();
4539 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004540 ImsResolver resolver = PhoneFactory.getImsResolver();
4541 if (resolver == null) {
4542 // may happen if the device does not support IMS.
4543 return null;
4544 }
4545 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004546 } finally {
4547 Binder.restoreCallingIdentity(identity);
4548 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004549 }
4550
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004551 /**
4552 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004553 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004554 */
4555 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4556 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004557
4558 final long identity = Binder.clearCallingIdentity();
4559 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004560 ImsResolver resolver = PhoneFactory.getImsResolver();
4561 if (resolver == null) {
4562 // may happen if the device does not support IMS.
4563 return null;
4564 }
4565 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004566 } finally {
4567 Binder.restoreCallingIdentity(identity);
4568 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004569 }
4570
Brad Ebinger884c07b2018-02-15 16:17:40 -08004571 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004572 * Sets the ImsService Package Name that Telephony will bind to.
4573 *
4574 * @param slotId the slot ID that the ImsService should bind for.
4575 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4576 * ImsService is the device default ImsService.
4577 * @param packageName The package name of the application that contains the ImsService to bind
4578 * to.
4579 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4580 * @hide
4581 */
4582 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004583 int[] subIds = SubscriptionManager.getSubId(slotId);
4584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4585 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4586 "setImsService");
4587
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004588 final long identity = Binder.clearCallingIdentity();
4589 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004590 ImsResolver resolver = PhoneFactory.getImsResolver();
4591 if (resolver == null) {
4592 // may happen if the device does not support IMS.
4593 return false;
4594 }
4595 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4596 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004600 }
4601
4602 /**
4603 * Return the ImsService configuration.
4604 *
4605 * @param slotId The slot that the ImsService is associated with.
4606 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4607 * the device default.
4608 * @return the package name of the ImsService configuration.
4609 */
4610 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004611 int[] subIds = SubscriptionManager.getSubId(slotId);
4612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4613 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4614 "getImsService");
4615
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616 final long identity = Binder.clearCallingIdentity();
4617 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004618 ImsResolver resolver = PhoneFactory.getImsResolver();
4619 if (resolver == null) {
4620 // may happen if the device does not support IMS.
4621 return "";
4622 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004623 // TODO: change API to query RCS separately.
4624 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4625 ImsFeature.FEATURE_MMTEL);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004626 } finally {
4627 Binder.restoreCallingIdentity(identity);
4628 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004629 }
4630
Brad Ebinger77b832e2019-10-17 17:03:22 -07004631 /**
4632 * Get the MmTelFeature state associated with the requested subscription id.
4633 * @param subId The subscription that the MmTelFeature is associated with.
4634 * @param callback A callback with an integer containing the
4635 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4636 */
4637 @Override
4638 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4639 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4640 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4641 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4642 "IMS not available on device.");
4643 }
4644 final long token = Binder.clearCallingIdentity();
4645 try {
4646 int slotId = getSlotIndex(subId);
4647 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4648 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4649 + subId + "'");
4650 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4651 }
4652 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4653 try {
4654 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4655 } catch (RemoteException e) {
4656 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4657 + "Ignore");
4658 }
4659 });
4660 } finally {
4661 Binder.restoreCallingIdentity(token);
4662 }
4663 }
4664
Wink Saville36469e72014-06-11 15:17:00 -07004665 public void setImsRegistrationState(boolean registered) {
4666 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004667
4668 final long identity = Binder.clearCallingIdentity();
4669 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004670 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004671 } finally {
4672 Binder.restoreCallingIdentity(identity);
4673 }
Wink Saville36469e72014-06-11 15:17:00 -07004674 }
4675
4676 /**
Stuart Scott54788802015-03-30 13:18:01 -07004677 * Set the network selection mode to automatic.
4678 *
4679 */
4680 @Override
4681 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4683 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004684
Pengquan Menge92a50d2018-09-21 15:54:48 -07004685 if (!isActiveSubscription(subId)) {
4686 return;
4687 }
4688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689 final long identity = Binder.clearCallingIdentity();
4690 try {
4691 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4692 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
Stuart Scott54788802015-03-30 13:18:01 -07004696 }
4697
Pengquan Mengea84e042018-09-20 14:57:26 -07004698 /**
4699 * Ask the radio to connect to the input network and change selection mode to manual.
4700 *
4701 * @param subId the id of the subscription.
4702 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4703 * the operator to attach to.
4704 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4705 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4706 * normal network selection next time.
4707 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004708 */
4709 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004710 public boolean setNetworkSelectionModeManual(
4711 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4713 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004714
4715 if (!isActiveSubscription(subId)) {
4716 return false;
4717 }
4718
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719 final long identity = Binder.clearCallingIdentity();
4720 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004721 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004722 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004723 if (DBG) {
4724 log("setNetworkSelectionModeManual: subId: " + subId
4725 + " operator: " + operatorInfo);
4726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4728 } finally {
4729 Binder.restoreCallingIdentity(identity);
4730 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004731 }
4732
4733 /**
4734 * Scans for available networks.
4735 */
4736 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004737 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4739 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004740 LocationAccessPolicy.LocationPermissionResult locationResult =
4741 LocationAccessPolicy.checkLocationPermission(mApp,
4742 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4743 .setCallingPackage(callingPackage)
4744 .setCallingPid(Binder.getCallingPid())
4745 .setCallingUid(Binder.getCallingUid())
4746 .setMethod("getCellNetworkScanResults")
4747 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4748 .build());
4749 switch (locationResult) {
4750 case DENIED_HARD:
4751 throw new SecurityException("Not allowed to access scan results -- location");
4752 case DENIED_SOFT:
4753 return null;
4754 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004755
Pengquan Menga1bb6272018-09-06 09:59:22 -07004756 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004757 try {
4758 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004759 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004760 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761 } finally {
4762 Binder.restoreCallingIdentity(identity);
4763 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004764 }
4765
4766 /**
yinxub1bed742017-04-17 11:45:04 -07004767 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004768 *
yinxub1bed742017-04-17 11:45:04 -07004769 * @param subId id of the subscription
4770 * @param request contains the radio access networks with bands/channels to scan
4771 * @param messenger callback messenger for scan results or errors
4772 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004773 * @return the id of the requested scan which can be used to stop the scan.
4774 */
4775 @Override
4776 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004777 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4779 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004780 LocationAccessPolicy.LocationPermissionResult locationResult =
4781 LocationAccessPolicy.checkLocationPermission(mApp,
4782 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4783 .setCallingPackage(callingPackage)
4784 .setCallingPid(Binder.getCallingPid())
4785 .setCallingUid(Binder.getCallingUid())
4786 .setMethod("requestNetworkScan")
4787 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4788 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004789 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004790 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004791 if (e != null) {
4792 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4793 throw e;
4794 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004795 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004796 return TelephonyScanManager.INVALID_SCAN_ID;
4797 }
4798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799 }
Hall Liu912dfd32019-04-25 14:02:26 -07004800 int callingUid = Binder.getCallingUid();
4801 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004802 final long identity = Binder.clearCallingIdentity();
4803 try {
4804 return mNetworkScanRequestTracker.startNetworkScan(
4805 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004806 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004807 } finally {
4808 Binder.restoreCallingIdentity(identity);
4809 }
yinxu504e1392017-04-12 16:03:22 -07004810 }
4811
Hall Liub2ac8ef2019-02-28 15:56:23 -08004812 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004813 NetworkScanRequest request, int subId) {
4814 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4815 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4816 boolean hasNetworkScanPermission =
4817 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4818 == PERMISSION_GRANTED;
4819
4820 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4821 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4822 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004823 }
4824
4825 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4826 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004827 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4828 return new SecurityException("Specific channels must not be"
4829 + " scanned without location access.");
4830 }
4831 }
4832 }
4833
Hall Liub2ac8ef2019-02-28 15:56:23 -08004834 return null;
4835 }
4836
yinxu504e1392017-04-12 16:03:22 -07004837 /**
4838 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004839 *
4840 * @param subId id of the subscription
4841 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004842 */
4843 @Override
4844 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4846 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004847
Hall Liu912dfd32019-04-25 14:02:26 -07004848 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004849 final long identity = Binder.clearCallingIdentity();
4850 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004851 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004852 } finally {
4853 Binder.restoreCallingIdentity(identity);
4854 }
yinxu504e1392017-04-12 16:03:22 -07004855 }
4856
4857 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004858 * Get the calculated preferred network type.
4859 * Used for debugging incorrect network type.
4860 *
4861 * @return the preferred network type, defined in RILConstants.java.
4862 */
4863 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004864 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004865 final Phone defaultPhone = getDefaultPhone();
4866 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4867 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004868 return RILConstants.PREFERRED_NETWORK_MODE;
4869 }
4870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871 final long identity = Binder.clearCallingIdentity();
4872 try {
4873 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004874 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004875 } finally {
4876 Binder.restoreCallingIdentity(identity);
4877 }
Junda Liu84d15a22014-07-02 11:21:04 -07004878 }
4879
4880 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004881 * Get the preferred network type.
4882 * Used for device configuration by some CDMA operators.
4883 *
4884 * @return the preferred network type, defined in RILConstants.java.
4885 */
4886 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004887 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004888 TelephonyPermissions
4889 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4890 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891
4892 final long identity = Binder.clearCallingIdentity();
4893 try {
4894 if (DBG) log("getPreferredNetworkType");
4895 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4896 int networkType = (result != null ? result[0] : -1);
4897 if (DBG) log("getPreferredNetworkType: " + networkType);
4898 return networkType;
4899 } finally {
4900 Binder.restoreCallingIdentity(identity);
4901 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004902 }
4903
4904 /**
4905 * Set the preferred network type.
4906 * Used for device configuration by some CDMA operators.
4907 *
4908 * @param networkType the preferred network type, defined in RILConstants.java.
4909 * @return true on success; false on any failure.
4910 */
4911 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004912 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4914 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004915
4916 final long identity = Binder.clearCallingIdentity();
4917 try {
4918 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4919 Boolean success = (Boolean) sendRequest(
4920 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4921 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4922 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004923 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4925 }
4926 return success;
4927 } finally {
4928 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004929 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004930 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004931
4932 /**
Miaoa84611c2019-03-15 09:21:10 +08004933 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004934 *
Miaoa84611c2019-03-15 09:21:10 +08004935 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004936 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004937 * @hide
4938 */
4939 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004940 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004941 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004942 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004943 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 try {
Miaoa84611c2019-03-15 09:21:10 +08004945 if (phone != null) {
4946 return phone.hasMatchedTetherApnSetting();
4947 } else {
4948 return false;
4949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950 } finally {
4951 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004952 }
Junda Liu475951f2014-11-07 16:45:03 -08004953 }
4954
4955 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004956 * Set mobile data enabled
4957 * Used by the user through settings etc to turn on/off mobile data
4958 *
4959 * @param enable {@code true} turn turn data on, else {@code false}
4960 */
4961 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004962 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4964 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965
4966 final long identity = Binder.clearCallingIdentity();
4967 try {
4968 int phoneId = mSubscriptionController.getPhoneId(subId);
4969 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4970 Phone phone = PhoneFactory.getPhone(phoneId);
4971 if (phone != null) {
4972 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004973 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004975 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004976 }
4977 } finally {
4978 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004979 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004980 }
4981
4982 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004983 * Get the user enabled state of Mobile Data.
4984 *
4985 * TODO: remove and use isUserDataEnabled.
4986 * This can't be removed now because some vendor codes
4987 * calls through ITelephony directly while they should
4988 * use TelephonyManager.
4989 *
4990 * @return true on enabled
4991 */
4992 @Override
4993 public boolean getDataEnabled(int subId) {
4994 return isUserDataEnabled(subId);
4995 }
4996
4997 /**
4998 * Get whether mobile data is enabled per user setting.
4999 *
5000 * There are other factors deciding whether mobile data is actually enabled, but they are
5001 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005002 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005003 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005004 *
5005 * @return {@code true} if data is enabled else {@code false}
5006 */
5007 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005008 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005009 try {
5010 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5011 null);
5012 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5014 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005015 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016
5017 final long identity = Binder.clearCallingIdentity();
5018 try {
5019 int phoneId = mSubscriptionController.getPhoneId(subId);
5020 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5021 Phone phone = PhoneFactory.getPhone(phoneId);
5022 if (phone != null) {
5023 boolean retVal = phone.isUserDataEnabled();
5024 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5025 return retVal;
5026 } else {
5027 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5028 return false;
5029 }
5030 } finally {
5031 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005032 }
5033 }
5034
5035 /**
5036 * Get whether mobile data is enabled.
5037 *
5038 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5039 * whether mobile data is actually enabled.
5040 *
5041 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5042 *
5043 * @return {@code true} if data is enabled else {@code false}
5044 */
5045 @Override
5046 public boolean isDataEnabled(int subId) {
5047 try {
5048 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5049 null);
5050 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5052 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005053 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054
5055 final long identity = Binder.clearCallingIdentity();
5056 try {
5057 int phoneId = mSubscriptionController.getPhoneId(subId);
5058 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5059 Phone phone = PhoneFactory.getPhone(phoneId);
5060 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005061 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005062 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5063 return retVal;
5064 } else {
5065 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5066 return false;
5067 }
5068 } finally {
5069 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005070 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005071 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005072
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005073 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5074 Phone phone) {
5075 //load access rules from carrier configs, and check those as well: b/139133814
5076 SubscriptionController subController = SubscriptionController.getInstance();
5077 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5078 || subController == null) return privilegeFromSim;
5079
5080 int uid = Binder.getCallingUid();
5081 PackageManager pkgMgr = phone.getContext().getPackageManager();
5082 String[] packages = pkgMgr.getPackagesForUid(uid);
5083
5084 final long identity = Binder.clearCallingIdentity();
5085 try {
5086 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5087 SubscriptionManager subManager = (SubscriptionManager)
5088 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5089 for (String pkg : packages) {
5090 if (subManager.canManageSubscription(subInfo, pkg)) {
5091 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5092 }
5093 }
5094 return privilegeFromSim;
5095 } finally {
5096 Binder.restoreCallingIdentity(identity);
5097 }
5098 }
5099
5100 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5101 String pkgName) {
5102 //load access rules from carrier configs, and check those as well: b/139133814
5103 SubscriptionController subController = SubscriptionController.getInstance();
5104 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5105 || subController == null) return privilegeFromSim;
5106
5107 final long identity = Binder.clearCallingIdentity();
5108 try {
5109 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5110 SubscriptionManager subManager = (SubscriptionManager)
5111 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5112 return subManager.canManageSubscription(subInfo, pkgName)
5113 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5114 } finally {
5115 Binder.restoreCallingIdentity(identity);
5116 }
5117 }
5118
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005119 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005120 public int getCarrierPrivilegeStatus(int subId) {
5121 final Phone phone = getPhone(subId);
5122 if (phone == null) {
5123 loge("getCarrierPrivilegeStatus: Invalid subId");
5124 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5125 }
5126 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005127 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005128 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005129 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5130 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005131
5132 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5133 card.getCarrierPrivilegeStatusForCurrentTransaction(
5134 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005135 }
Junda Liu29340342014-07-10 15:23:27 -07005136
5137 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005138 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5139 final Phone phone = getPhone(subId);
5140 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005141 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005142 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5143 }
5144 UiccProfile profile =
5145 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5146 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005147 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005148 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5149 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005150 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5151 profile.getCarrierPrivilegeStatusForUid(
5152 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005153 }
5154
5155 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005156 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5157 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005158 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005159 }
5160
5161 int phoneId = SubscriptionManager.getPhoneId(subId);
5162 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005163 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005164 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005165 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5166 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005167 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5168 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5169 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005170 }
5171
5172 @Override
5173 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005174 if (TextUtils.isEmpty(pkgName))
5175 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005176 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5177 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5178 UiccCard card = UiccController.getInstance().getUiccCard(i);
5179 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005180 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005181 continue;
5182 }
5183
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005184 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5185 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5186 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005187 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5188 break;
5189 }
5190 }
5191
5192 return result;
Junda Liu29340342014-07-10 15:23:27 -07005193 }
Derek Tan89e89d42014-07-08 17:00:10 -07005194
5195 @Override
Junda Liue64de782015-04-16 17:19:16 -07005196 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5197 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5198 loge("phoneId " + phoneId + " is not valid.");
5199 return null;
5200 }
5201 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005202 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005203 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005204 return null ;
5205 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005206 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005207 }
5208
Amith Yamasani6e118872016-02-19 12:53:51 -08005209 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005210 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005211 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005212 List<String> privilegedPackages = new ArrayList<>();
5213 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005214 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5215 // has UICC in that slot.
5216 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005217 if (card.hasCarrierPrivilegeRules()) {
5218 if (packages == null) {
5219 // Only check packages in user 0 for now
5220 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005221 PackageManager.MATCH_DISABLED_COMPONENTS
5222 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005223 | PackageManager.GET_SIGNING_CERTIFICATES,
5224 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005225 }
5226 for (int p = packages.size() - 1; p >= 0; p--) {
5227 PackageInfo pkgInfo = packages.get(p);
5228 if (pkgInfo != null && pkgInfo.packageName != null
5229 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005230 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005231 privilegedPackages.add(pkgInfo.packageName);
5232 }
5233 }
5234 }
5235 }
5236 return privilegedPackages;
5237 }
5238
chen xuf7e9fe82019-05-09 19:31:02 -07005239 @Override
5240 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005241 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5242
5243 final long identity = Binder.clearCallingIdentity();
5244
chen xuf7e9fe82019-05-09 19:31:02 -07005245 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005246 try {
5247 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5248 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5249 }
5250 } finally {
5251 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005252 }
5253 return privilegedPackages;
5254 }
5255
Wink Savilleb564aae2014-10-23 10:18:09 -07005256 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005257 final Phone phone = getPhone(subId);
5258 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005259 if (card == null) {
5260 loge("getIccId: No UICC");
5261 return null;
5262 }
5263 String iccId = card.getIccId();
5264 if (TextUtils.isEmpty(iccId)) {
5265 loge("getIccId: ICC ID is null or empty.");
5266 return null;
5267 }
5268 return iccId;
5269 }
5270
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005271 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005272 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5273 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005274 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5275 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005277 final long identity = Binder.clearCallingIdentity();
5278 try {
5279 final String iccId = getIccId(subId);
5280 final Phone phone = getPhone(subId);
5281 if (phone == null) {
5282 return false;
5283 }
5284 final String subscriberId = phone.getSubscriberId();
5285
5286 if (DBG_MERGE) {
5287 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5288 + subscriberId + " to " + number);
5289 }
5290
5291 if (TextUtils.isEmpty(iccId)) {
5292 return false;
5293 }
5294
5295 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5296
5297 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5298 if (alphaTag == null) {
5299 editor.remove(alphaTagPrefKey);
5300 } else {
5301 editor.putString(alphaTagPrefKey, alphaTag);
5302 }
5303
5304 // Record both the line number and IMSI for this ICCID, since we need to
5305 // track all merged IMSIs based on line number
5306 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5307 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5308 if (number == null) {
5309 editor.remove(numberPrefKey);
5310 editor.remove(subscriberPrefKey);
5311 } else {
5312 editor.putString(numberPrefKey, number);
5313 editor.putString(subscriberPrefKey, subscriberId);
5314 }
5315
5316 editor.commit();
5317 return true;
5318 } finally {
5319 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005320 }
Derek Tan7226c842014-07-02 17:42:23 -07005321 }
5322
5323 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005324 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005325 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005327 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005328 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005329 return null;
5330 }
Derek Tan97ebb422014-09-05 16:55:38 -07005331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 final long identity = Binder.clearCallingIdentity();
5333 try {
5334 String iccId = getIccId(subId);
5335 if (iccId != null) {
5336 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5337 if (DBG_MERGE) {
5338 log("getLine1NumberForDisplay returning "
5339 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5340 }
5341 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5344 return null;
5345 } finally {
5346 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005347 }
Derek Tan7226c842014-07-02 17:42:23 -07005348 }
5349
5350 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005351 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005353 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005354 return null;
5355 }
Derek Tan97ebb422014-09-05 16:55:38 -07005356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 final long identity = Binder.clearCallingIdentity();
5358 try {
5359 String iccId = getIccId(subId);
5360 if (iccId != null) {
5361 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5362 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5363 }
5364 return null;
5365 } finally {
5366 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005367 }
Derek Tan7226c842014-07-02 17:42:23 -07005368 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005369
5370 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005371 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005372 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5373 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005375 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5376 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005377 return null;
5378 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005379
Jordan Liub49b04b2019-05-06 14:45:15 -07005380 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5381 // the process, where TelephonyManager was instantiated.
5382 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005383 final long identity = Binder.clearCallingIdentity();
5384 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005385 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 final TelephonyManager tele = TelephonyManager.from(context);
5387 final SubscriptionManager sub = SubscriptionManager.from(context);
5388
5389 // Figure out what subscribers are currently active
5390 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391
Jordan Liub49b04b2019-05-06 14:45:15 -07005392 // Only consider subs which match the current subId
5393 // This logic can be simplified. See b/131189269 for progress.
5394 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005395 activeSubscriberIds.add(tele.getSubscriberId(subId));
5396 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397
5398 // First pass, find a number override for an active subscriber
5399 String mergeNumber = null;
5400 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5401 for (String key : prefs.keySet()) {
5402 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5403 final String subscriberId = (String) prefs.get(key);
5404 if (activeSubscriberIds.contains(subscriberId)) {
5405 final String iccId = key.substring(
5406 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5407 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5408 mergeNumber = (String) prefs.get(numberKey);
5409 if (DBG_MERGE) {
5410 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5411 + " for active subscriber " + subscriberId);
5412 }
5413 if (!TextUtils.isEmpty(mergeNumber)) {
5414 break;
5415 }
5416 }
5417 }
5418 }
5419
5420 // Shortcut when no active merged subscribers
5421 if (TextUtils.isEmpty(mergeNumber)) {
5422 return null;
5423 }
5424
5425 // Second pass, find all subscribers under that line override
5426 final ArraySet<String> result = new ArraySet<>();
5427 for (String key : prefs.keySet()) {
5428 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5429 final String number = (String) prefs.get(key);
5430 if (mergeNumber.equals(number)) {
5431 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5432 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5433 final String subscriberId = (String) prefs.get(subscriberKey);
5434 if (!TextUtils.isEmpty(subscriberId)) {
5435 result.add(subscriberId);
5436 }
5437 }
5438 }
5439 }
5440
5441 final String[] resultArray = result.toArray(new String[result.size()]);
5442 Arrays.sort(resultArray);
5443 if (DBG_MERGE) {
5444 Slog.d(LOG_TAG,
5445 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5446 }
5447 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005448 } finally {
5449 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005450 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005451 }
5452
5453 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005454 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5455 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5456
5457 final long identity = Binder.clearCallingIdentity();
5458 try {
5459 final TelephonyManager telephonyManager = mApp.getSystemService(
5460 TelephonyManager.class);
5461 String subscriberId = telephonyManager.getSubscriberId(subId);
5462 if (subscriberId == null) {
5463 if (DBG) {
5464 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5465 + subId);
5466 }
5467 return null;
5468 }
5469
5470 final SubscriptionInfo info = SubscriptionController.getInstance()
5471 .getSubscriptionInfo(subId);
5472 final ParcelUuid groupUuid = info.getGroupUuid();
5473 // If it doesn't belong to any group, return just subscriberId of itself.
5474 if (groupUuid == null) {
5475 return new String[]{subscriberId};
5476 }
5477
5478 // Get all subscriberIds from the group.
5479 final List<String> mergedSubscriberIds = new ArrayList<>();
5480 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5481 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5482 for (SubscriptionInfo subInfo : groupInfos) {
5483 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5484 if (subscriberId != null) {
5485 mergedSubscriberIds.add(subscriberId);
5486 }
5487 }
5488
5489 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5490 } finally {
5491 Binder.restoreCallingIdentity(identity);
5492
5493 }
5494 }
5495
5496 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005497 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005498 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5499 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500
5501 final long identity = Binder.clearCallingIdentity();
5502 try {
5503 final Phone phone = getPhone(subId);
5504 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5505 } finally {
5506 Binder.restoreCallingIdentity(identity);
5507 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005508 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005509
5510 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005511 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005512 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5513 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005514 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515
5516 final long identity = Binder.clearCallingIdentity();
5517 try {
5518 final Phone phone = getPhone(subId);
5519 if (phone == null) {
5520 return false;
5521 }
5522 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5523 cdmaNonRoamingList);
5524 } finally {
5525 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005526 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005527 }
5528
5529 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005530 @Deprecated
5531 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5532 enforceModifyPermission();
5533
5534 int returnValue = 0;
5535 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005536 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005537 if(result.exception == null) {
5538 if (result.result != null) {
5539 byte[] responseData = (byte[])(result.result);
5540 if(responseData.length > oemResp.length) {
5541 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5542 responseData.length + "bytes. Buffer Size is " +
5543 oemResp.length + "bytes.");
5544 }
5545 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5546 returnValue = responseData.length;
5547 }
5548 } else {
5549 CommandException ex = (CommandException) result.exception;
5550 returnValue = ex.getCommandError().ordinal();
5551 if(returnValue > 0) returnValue *= -1;
5552 }
5553 } catch (RuntimeException e) {
5554 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5555 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5556 if(returnValue > 0) returnValue *= -1;
5557 }
5558
5559 return returnValue;
5560 }
5561
5562 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005563 public void setRadioCapability(RadioAccessFamily[] rafs) {
5564 try {
5565 ProxyController.getInstance().setRadioCapability(rafs);
5566 } catch (RuntimeException e) {
5567 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5568 }
5569 }
5570
5571 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005572 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005573 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005574 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005575 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005576 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005577 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 final long identity = Binder.clearCallingIdentity();
5579 try {
chen xub97461a2018-10-26 14:17:57 -07005580 TelephonyPermissions
5581 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5582 mApp, phone.getSubId(), "getRadioAccessFamily");
5583 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 } finally {
5585 Binder.restoreCallingIdentity(identity);
5586 }
chen xub97461a2018-10-26 14:17:57 -07005587 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005588 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005589
5590 @Override
5591 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005592 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005593 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594
5595 final long identity = Binder.clearCallingIdentity();
5596 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005597 ImsManager.getInstance(defaultPhone.getContext(),
5598 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 } finally {
5600 Binder.restoreCallingIdentity(identity);
5601 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005602 }
5603
5604 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005605 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005606 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005608 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005609 return false;
5610 }
Svet Ganovb320e182015-04-16 12:30:10 -07005611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612 final long identity = Binder.clearCallingIdentity();
5613 try {
5614 // Check the user preference and the system-level IMS setting. Even if the user has
5615 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5616 // In the long run, we may instead need to check if there exists a connection service
5617 // which can support video calling.
5618 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005619 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 return imsManager.isVtEnabledByPlatform()
5621 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5622 && imsManager.isVtEnabledByUser();
5623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005626 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005627
Andrew Leea1239f22015-03-02 17:44:07 -08005628 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5631 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5632 return false;
5633 }
5634
5635 final long identity = Binder.clearCallingIdentity();
5636 try {
5637 CarrierConfigManager configManager =
5638 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005639 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5641 } finally {
5642 Binder.restoreCallingIdentity(identity);
5643 }
Andrew Leea1239f22015-03-02 17:44:07 -08005644 }
5645
5646 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005647 public boolean isWorldPhone(int subId, String callingPackage) {
5648 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5649 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5650 return false;
5651 }
5652
5653 final long identity = Binder.clearCallingIdentity();
5654 try {
5655 CarrierConfigManager configManager =
5656 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005657 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
Andrew Leea1239f22015-03-02 17:44:07 -08005662 }
5663
Andrew Lee9431b832015-03-09 18:46:45 -07005664 @Override
5665 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005666 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005667 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005668 }
5669
5670 @Override
5671 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672 final long identity = Binder.clearCallingIdentity();
5673 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005674 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675 } finally {
5676 Binder.restoreCallingIdentity(identity);
5677 }
Andrew Lee9431b832015-03-09 18:46:45 -07005678 }
5679
Hall Liuf6668912018-10-31 17:05:23 -07005680 /**
5681 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5682 * support for the feature and device firmware support.
5683 *
5684 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5685 */
5686 @Override
5687 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005689 final Phone phone = getPhone(subscriptionId);
5690 if (phone == null) {
5691 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5692 return false;
5693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005695 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5697 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005698 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 return isCarrierSupported && isDeviceSupported;
5700 } finally {
5701 Binder.restoreCallingIdentity(identity);
5702 }
Hall Liu98187582018-01-22 19:15:32 -08005703 }
5704
Hall Liuf6668912018-10-31 17:05:23 -07005705 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005706 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5707 * RTT setting, will return true if the device and carrier both support RTT.
5708 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005709 */
5710 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711 final long identity = Binder.clearCallingIdentity();
5712 try {
Hall Liu81eb08c2019-10-29 16:50:20 -07005713 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714 } finally {
5715 Binder.restoreCallingIdentity(identity);
5716 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005717 }
5718
Sanket Padawe7310cc72015-01-14 09:53:20 -08005719 /**
5720 * Returns the unique device ID of phone, for example, the IMEI for
5721 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5722 *
5723 * <p>Requires Permission:
5724 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5725 */
5726 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005727 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005728 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005729 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005730 return null;
5731 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005732 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005733 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5734 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005735 return null;
5736 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737
5738 final long identity = Binder.clearCallingIdentity();
5739 try {
5740 return phone.getDeviceId();
5741 } finally {
5742 Binder.restoreCallingIdentity(identity);
5743 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005744 }
5745
Ping Sunc67b7c22016-03-02 19:16:45 +08005746 /**
5747 * {@hide}
5748 * Returns the IMS Registration Status on a particular subid
5749 *
5750 * @param subId
5751 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005752 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005753 Phone phone = getPhone(subId);
5754 if (phone != null) {
5755 return phone.isImsRegistered();
5756 } else {
5757 return false;
5758 }
5759 }
5760
Santos Cordon7a1885b2015-02-03 11:15:19 -08005761 @Override
5762 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763 final long identity = Binder.clearCallingIdentity();
5764 try {
5765 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005769 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005770
Tyler Gunnf70ed162019-04-03 15:28:53 -07005771 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005772 public int getSubIdForPhoneAccountHandle(
5773 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5774 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5775 callingPackage, "getSubIdForPhoneAccountHandle")) {
5776 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5777 }
5778 final long identity = Binder.clearCallingIdentity();
5779 try {
5780 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5781 } finally {
5782 Binder.restoreCallingIdentity(identity);
5783 }
5784 }
5785
5786 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005787 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5788 final long identity = Binder.clearCallingIdentity();
5789 try {
5790 Phone phone = getPhone(subscriptionId);
5791 if (phone == null) {
5792 return null;
5793 }
5794 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5795 } finally {
5796 Binder.restoreCallingIdentity(identity);
5797 }
5798 }
5799
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005800 /**
5801 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005802 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005803 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 final long identity = Binder.clearCallingIdentity();
5805 try {
5806 Phone phone = getPhone(subId);
5807 if (phone != null) {
5808 return phone.isWifiCallingEnabled();
5809 } else {
5810 return false;
5811 }
5812 } finally {
5813 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005814 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005815 }
5816
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005817 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005818 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005819 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005820 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005821 final long identity = Binder.clearCallingIdentity();
5822 try {
5823 Phone phone = getPhone(subId);
5824 if (phone != null) {
5825 return phone.isVideoEnabled();
5826 } else {
5827 return false;
5828 }
5829 } finally {
5830 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005831 }
5832 }
5833
5834 /**
5835 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5836 * defined in {@link ImsRegistrationImplBase}.
5837 */
5838 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839 final long identity = Binder.clearCallingIdentity();
5840 try {
5841 Phone phone = getPhone(subId);
5842 if (phone != null) {
5843 return phone.getImsRegistrationTech();
5844 } else {
5845 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5846 }
5847 } finally {
5848 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005849 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005850 }
5851
Stuart Scott8eef64f2015-04-08 15:13:54 -07005852 @Override
5853 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08005854 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005855 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5856 return;
5857 }
5858
Svet Ganovcc087f82015-05-12 20:35:54 -07005859 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005860
Svet Ganovcc087f82015-05-12 20:35:54 -07005861 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005862 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5863 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005864 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005865 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005866 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005867 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5868 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005869 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005870 // There has been issues when Sms raw table somehow stores orphan
5871 // fragments. They lead to garbled message when new fragments come
5872 // in and combined with those stale ones. In case this happens again,
5873 // user can reset all network settings which will clean up this table.
5874 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005875 // Clean up IMS settings as well here.
5876 int slotId = getSlotIndex(subId);
5877 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5878 ImsManager.getInstance(mApp, slotId).factoryReset();
5879 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07005880
5881 // Erase modem config if erase modem on network setting is enabled.
5882 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5883 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5884 if (configValue != null && Boolean.parseBoolean(configValue)) {
5885 sendEraseModemConfig(getDefaultPhone());
5886 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005887 } finally {
5888 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005889 }
5890 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005891
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005892 private void cleanUpSmsRawTable(Context context) {
5893 ContentResolver resolver = context.getContentResolver();
5894 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5895 resolver.delete(uri, null, null);
5896 }
5897
Narayan Kamath1c496c22015-04-16 14:40:19 +01005898 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005899 public String getSimLocaleForSubscriber(int subId) {
5900 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5901 final Phone phone = getPhone(subId);
5902 if (phone == null) {
5903 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005904 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005905 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906 final long identity = Binder.clearCallingIdentity();
5907 try {
chen xu5d3637b2019-01-21 23:31:38 -08005908 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5909 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005910 if (info == null) {
5911 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5912 return null;
5913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914 // Try and fetch the locale from the carrier properties or from the SIM language
5915 // preferences (EF-PL and EF-LI)...
5916 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005918 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5919 if (localeFromDefaultSim != null) {
5920 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5921 if (DBG) log("Using locale from subId: " + subId + " locale: "
5922 + localeFromDefaultSim);
5923 return localeFromDefaultSim.toLanguageTag();
5924 } else {
5925 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926 }
5927 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 // The SIM language preferences only store a language (e.g. fr = French), not an
5930 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5931 // the SIM and carrier preferences does not include a country we add the country
5932 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005933 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005935 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936 return mccLocale.toLanguageTag();
5937 }
5938
5939 if (DBG) log("No locale found - returning null");
5940 return null;
5941 } finally {
5942 Binder.restoreCallingIdentity(identity);
5943 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005944 }
5945
5946 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005947 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005948 }
5949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950 /**
5951 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5952 */
5953 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005954 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005955 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005956
Chenjie Yu1ba97252018-01-11 18:16:20 -08005957 private final ModemActivityInfo mLastModemActivityInfo =
5958 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5959
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005960 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005961 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5962 * representing the state of the modem.
5963 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005964 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5965 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005966 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005967 */
5968 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005969 public void requestModemActivityInfo(ResultReceiver result) {
5970 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005971 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972
5973 final long identity = Binder.clearCallingIdentity();
5974 try {
5975 ModemActivityInfo ret = null;
5976 synchronized (mLastModemActivityInfo) {
5977 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5978 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005979 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005980 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5982 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005983 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5984 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 }
5986 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005987 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5988 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005989 mLastModemActivityInfo.setIdleTimeMillis(
5990 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5991 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5992 mLastModemActivityInfo.setRxTimeMillis(
5993 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5994 mLastModemActivityInfo.setEnergyUsed(
5995 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5998 mLastModemActivityInfo.getSleepTimeMillis(),
5999 mLastModemActivityInfo.getIdleTimeMillis(),
6000 mLastModemActivityInfo.getTxTimeMillis(),
6001 mLastModemActivityInfo.getRxTimeMillis(),
6002 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 Bundle bundle = new Bundle();
6005 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6006 result.send(0, bundle);
6007 } finally {
6008 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006009 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006010 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006011
Siddharth Rayb8114062018-06-17 15:02:38 -07006012 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6013 // less than total activity duration.
6014 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6015 if (info == null) {
6016 return false;
6017 }
6018 int activityDurationMs =
6019 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6020 int totalTxTimeMs = 0;
6021 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
6022 totalTxTimeMs += info.getTxTimeMillis()[i];
6023 }
6024 return (info.isValid()
6025 && (info.getSleepTimeMillis() <= activityDurationMs)
6026 && (info.getIdleTimeMillis() <= activityDurationMs)
6027 && (info.getRxTimeMillis() <= activityDurationMs)
6028 && (totalTxTimeMs <= activityDurationMs));
6029 }
6030
Jack Yu85bd38a2015-11-09 11:34:32 -08006031 /**
6032 * {@hide}
6033 * Returns the service state information on specified subscription.
6034 */
6035 @Override
6036 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006038 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006039 return null;
6040 }
6041
Hall Liuf19c44f2018-11-27 14:38:17 -08006042 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6043 LocationAccessPolicy.checkLocationPermission(mApp,
6044 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6045 .setCallingPackage(callingPackage)
6046 .setCallingPid(Binder.getCallingPid())
6047 .setCallingUid(Binder.getCallingUid())
6048 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006049 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006050 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6051 .build());
6052
6053 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6054 LocationAccessPolicy.checkLocationPermission(mApp,
6055 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6056 .setCallingPackage(callingPackage)
6057 .setCallingPid(Binder.getCallingPid())
6058 .setCallingUid(Binder.getCallingUid())
6059 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006060 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006061 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6062 .build());
6063 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6064 boolean hasFinePermission =
6065 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6066 boolean hasCoarsePermission =
6067 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6068
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069 final long identity = Binder.clearCallingIdentity();
6070 try {
6071 final Phone phone = getPhone(subId);
6072 if (phone == null) {
6073 return null;
6074 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006075
Hall Liuf19c44f2018-11-27 14:38:17 -08006076 ServiceState ss = phone.getServiceState();
6077
6078 // Scrub out the location info in ServiceState depending on what level of access
6079 // the caller has.
6080 if (hasFinePermission) return ss;
6081 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6082 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083 } finally {
6084 Binder.restoreCallingIdentity(identity);
6085 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006086 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006087
6088 /**
6089 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6090 *
6091 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6092 * voicemail ringtone.
6093 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6094 * PhoneAccount.
6095 */
6096 @Override
6097 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006098 final long identity = Binder.clearCallingIdentity();
6099 try {
6100 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6101 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006102 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006103 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006104
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006105 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6106 } finally {
6107 Binder.restoreCallingIdentity(identity);
6108 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006109 }
6110
6111 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006112 * Sets the per-account voicemail ringtone.
6113 *
6114 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6115 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6116 *
6117 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6118 * voicemail ringtone.
6119 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6120 * PhoneAccount.
6121 */
6122 @Override
6123 public void setVoicemailRingtoneUri(String callingPackage,
6124 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006125 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006126 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006127 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6128 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6130 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6131 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006132 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133
6134 final long identity = Binder.clearCallingIdentity();
6135 try {
6136 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6137 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006138 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006139 }
6140 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6141 } finally {
6142 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006143 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006144 }
6145
6146 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006147 * Returns whether vibration is set for voicemail notification in Phone settings.
6148 *
6149 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6150 * voicemail vibration setting.
6151 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6152 */
6153 @Override
6154 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155 final long identity = Binder.clearCallingIdentity();
6156 try {
6157 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6158 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006159 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6163 } finally {
6164 Binder.restoreCallingIdentity(identity);
6165 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006166 }
6167
Youhan Wange64578a2016-05-02 15:32:42 -07006168 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006169 * Sets the per-account voicemail vibration.
6170 *
6171 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6172 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6173 *
6174 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6175 * voicemail vibration setting.
6176 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6177 * specific PhoneAccount.
6178 */
6179 @Override
6180 public void setVoicemailVibrationEnabled(String callingPackage,
6181 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006182 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006183 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006184 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6185 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6187 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6188 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006189 }
6190
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006191 final long identity = Binder.clearCallingIdentity();
6192 try {
6193 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6194 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006195 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006196 }
6197 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6198 } finally {
6199 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006200 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006201 }
6202
6203 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006204 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6205 *
6206 * @throws SecurityException if the caller does not have the required permission
6207 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006208 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006209 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006210 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006211 }
6212
6213 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006214 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6215 * permission.
6216 *
6217 * @throws SecurityException if the caller does not have the required permission
6218 */
6219 private void enforceSendSmsPermission() {
6220 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6221 }
6222
6223 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006224 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006225 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006226 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006227 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006228 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229 final long identity = Binder.clearCallingIdentity();
6230 try {
6231 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006232 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 if (componentName == null) {
6234 throw new SecurityException(
6235 "Caller not current active visual voicemail package[null]");
6236 }
6237 String vvmPackage = componentName.getPackageName();
6238 if (!callingPackage.equals(vvmPackage)) {
6239 throw new SecurityException("Caller not current active visual voicemail package["
6240 + vvmPackage + "]");
6241 }
6242 } finally {
6243 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006244 }
6245 }
6246
6247 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006248 * Return the application ID for the app type.
6249 *
6250 * @param subId the subscription ID that this request applies to.
6251 * @param appType the uicc app type.
6252 * @return Application ID for specificied app type, or null if no uicc.
6253 */
6254 @Override
6255 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006256 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006257 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258
6259 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006260 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006261 if (phone == null) {
6262 return null;
6263 }
6264 String aid = null;
6265 try {
6266 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6267 .getApplicationByType(appType).getAid();
6268 } catch (Exception e) {
6269 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6270 }
6271 return aid;
6272 } finally {
6273 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006274 }
Youhan Wange64578a2016-05-02 15:32:42 -07006275 }
6276
Youhan Wang4001d252016-05-11 10:29:41 -07006277 /**
6278 * Return the Electronic Serial Number.
6279 *
6280 * @param subId the subscription ID that this request applies to.
6281 * @return ESN or null if error.
6282 */
6283 @Override
6284 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006285 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006286 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006287
6288 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006289 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 if (phone == null) {
6291 return null;
6292 }
6293 String esn = null;
6294 try {
6295 esn = phone.getEsn();
6296 } catch (Exception e) {
6297 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6298 }
6299 return esn;
6300 } finally {
6301 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006302 }
Youhan Wang4001d252016-05-11 10:29:41 -07006303 }
6304
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006305 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006306 * Return the Preferred Roaming List Version.
6307 *
6308 * @param subId the subscription ID that this request applies to.
6309 * @return PRLVersion or null if error.
6310 */
6311 @Override
6312 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006313 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006314 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315
6316 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006317 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006318 if (phone == null) {
6319 return null;
6320 }
6321 String cdmaPrlVersion = null;
6322 try {
6323 cdmaPrlVersion = phone.getCdmaPrlVersion();
6324 } catch (Exception e) {
6325 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6326 }
6327 return cdmaPrlVersion;
6328 } finally {
6329 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006330 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006331 }
6332
6333 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006334 * Get snapshot of Telephony histograms
6335 * @return List of Telephony histograms
6336 * @hide
6337 */
6338 @Override
6339 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6341 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342
6343 final long identity = Binder.clearCallingIdentity();
6344 try {
6345 return RIL.getTelephonyRILTimingHistograms();
6346 } finally {
6347 Binder.restoreCallingIdentity(identity);
6348 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006349 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006350
6351 /**
6352 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006353 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6354 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006355 * Require system privileges. In the future we may add this to carrier APIs.
6356 *
Michele Berionne482f8202018-11-27 18:57:59 -08006357 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006358 */
6359 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006360 @TelephonyManager.SetCarrierRestrictionResult
6361 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006362 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006363 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006364
Michele Berionne482f8202018-11-27 18:57:59 -08006365 if (carrierRestrictionRules == null) {
6366 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006367 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006369 final long identity = Binder.clearCallingIdentity();
6370 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006371 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006372 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006373 } finally {
6374 Binder.restoreCallingIdentity(identity);
6375 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006376 }
6377
6378 /**
6379 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006380 * Get the allowed carrier list and the excluded carrier list, including the priority between
6381 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006382 * Require system privileges. In the future we may add this to carrier APIs.
6383 *
Michele Berionne482f8202018-11-27 18:57:59 -08006384 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006385 */
6386 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006387 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006388 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006389 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390
6391 final long identity = Binder.clearCallingIdentity();
6392 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006393 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6394 if (response instanceof CarrierRestrictionRules) {
6395 return (CarrierRestrictionRules) response;
6396 }
6397 // Response is an Exception of some kind,
6398 // which is signalled to the user as a NULL retval
6399 return null;
6400 } catch (Exception e) {
6401 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6402 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403 } finally {
6404 Binder.restoreCallingIdentity(identity);
6405 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006406 }
6407
fionaxu59545b42016-05-25 15:53:37 -07006408 /**
6409 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6410 * @param subId the subscription ID that this action applies to.
6411 * @param enabled control enable or disable metered apns.
6412 * {@hide}
6413 */
6414 @Override
6415 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6416 enforceModifyPermission();
6417 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006418
6419 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006420 if (phone == null) {
6421 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6422 return;
6423 }
6424 try {
6425 phone.carrierActionSetMeteredApnsEnabled(enabled);
6426 } catch (Exception e) {
6427 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006428 } finally {
6429 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006430 }
6431 }
6432
6433 /**
6434 * Action set from carrier signalling broadcast receivers to enable/disable radio
6435 * @param subId the subscription ID that this action applies to.
6436 * @param enabled control enable or disable radio.
6437 * {@hide}
6438 */
6439 @Override
6440 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6441 enforceModifyPermission();
6442 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006443
6444 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006445 if (phone == null) {
6446 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6447 return;
6448 }
6449 try {
6450 phone.carrierActionSetRadioEnabled(enabled);
6451 } catch (Exception e) {
6452 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006453 } finally {
6454 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006455 }
6456 }
6457
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006458 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006459 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6460 * network status based on which carrier apps could apply actions accordingly,
6461 * enable/disable default url handler for example.
6462 *
6463 * @param subId the subscription ID that this action applies to.
6464 * @param report control start/stop reporting the default network status.
6465 * {@hide}
6466 */
6467 @Override
6468 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6469 enforceModifyPermission();
6470 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006471
6472 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006473 if (phone == null) {
6474 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6475 return;
6476 }
6477 try {
6478 phone.carrierActionReportDefaultNetworkStatus(report);
6479 } catch (Exception e) {
6480 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481 } finally {
6482 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006483 }
6484 }
6485
6486 /**
fionaxud9622282017-07-17 17:51:30 -07006487 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6488 * @param subId the subscription ID that this action applies to.
6489 * {@hide}
6490 */
6491 @Override
6492 public void carrierActionResetAll(int subId) {
6493 enforceModifyPermission();
6494 final Phone phone = getPhone(subId);
6495 if (phone == null) {
6496 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6497 return;
6498 }
6499 try {
6500 phone.carrierActionResetAll();
6501 } catch (Exception e) {
6502 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6503 }
6504 }
6505
6506 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006507 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6508 * bug report is being generated.
6509 */
6510 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006511 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006512 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6513 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006514 writer.println("Permission Denial: can't dump Phone from pid="
6515 + Binder.getCallingPid()
6516 + ", uid=" + Binder.getCallingUid()
6517 + "without permission "
6518 + android.Manifest.permission.DUMP);
6519 return;
6520 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006521 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006522 }
Jack Yueb89b242016-06-22 13:27:47 -07006523
Brad Ebingerdac2f002018-04-03 15:17:52 -07006524 @Override
6525 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6526 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6527 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006528 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6529 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006530 }
6531
Jack Yueb89b242016-06-22 13:27:47 -07006532 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006533 * Get aggregated video call data usage since boot.
6534 *
6535 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6536 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006537 * {@hide}
6538 */
6539 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006540 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006541 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6542 null);
6543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544 final long identity = Binder.clearCallingIdentity();
6545 try {
6546 // NetworkStatsService keeps tracking the active network interface and identity. It
6547 // records the delta with the corresponding network identity.
6548 // We just return the total video call data usage snapshot since boot.
6549 Phone phone = getPhone(subId);
6550 if (phone != null) {
6551 return phone.getVtDataUsage(perUidStats);
6552 }
6553 return null;
6554 } finally {
6555 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006556 }
Jack Yueb89b242016-06-22 13:27:47 -07006557 }
Jack Yu75ab2952016-07-08 14:29:33 -07006558
6559 /**
6560 * Policy control of data connection. Usually used when data limit is passed.
6561 * @param enabled True if enabling the data, otherwise disabling.
6562 * @param subId Subscription index
6563 * {@hide}
6564 */
6565 @Override
6566 public void setPolicyDataEnabled(boolean enabled, int subId) {
6567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568
6569 final long identity = Binder.clearCallingIdentity();
6570 try {
6571 Phone phone = getPhone(subId);
6572 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006573 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574 }
6575 } finally {
6576 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006577 }
6578 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006579
6580 /**
6581 * Get Client request stats
6582 * @return List of Client Request Stats
6583 * @hide
6584 */
6585 @Override
6586 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006588 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006589 return null;
6590 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006591 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006593 final long identity = Binder.clearCallingIdentity();
6594 try {
6595 if (phone != null) {
6596 return phone.getClientRequestStats();
6597 }
6598
6599 return null;
6600 } finally {
6601 Binder.restoreCallingIdentity(identity);
6602 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006603 }
6604
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006605 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006606 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006607 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006608 }
Jack Yueb4124c2017-02-16 15:32:43 -08006609
6610 /**
Grace Chen70990072017-03-24 17:21:30 -07006611 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006612 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006613 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006614 * @param state State of SIM (power down, power up, pass through)
6615 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6616 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6617 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006618 *
6619 **/
6620 @Override
Grace Chen70990072017-03-24 17:21:30 -07006621 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006622 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006623 Phone phone = PhoneFactory.getPhone(slotIndex);
6624
vagdeviaf9a5b92018-08-15 16:01:53 -07006625 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006627 final long identity = Binder.clearCallingIdentity();
6628 try {
6629 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006630 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006631 }
6632 } finally {
6633 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006634 }
6635 }
Shuo Qiandd210312017-04-12 22:11:33 +00006636
Tyler Gunn65d45c22017-06-05 11:22:26 -07006637 private boolean isUssdApiAllowed(int subId) {
6638 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006639 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006640 if (configManager == null) {
6641 return false;
6642 }
6643 PersistableBundle pb = configManager.getConfigForSubId(subId);
6644 if (pb == null) {
6645 return false;
6646 }
6647 return pb.getBoolean(
6648 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6649 }
6650
Shuo Qiandd210312017-04-12 22:11:33 +00006651 /**
6652 * Check if phone is in emergency callback mode
6653 * @return true if phone is in emergency callback mode
6654 * @param subId sub id
6655 */
goneil9c5f4872017-12-05 14:07:56 -08006656 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006657 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006658 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006659 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006660
6661 final long identity = Binder.clearCallingIdentity();
6662 try {
6663 if (phone != null) {
6664 return phone.isInEcm();
6665 } else {
6666 return false;
6667 }
6668 } finally {
6669 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006670 }
6671 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006672
6673 /**
6674 * Get the current signal strength information for the given subscription.
6675 * Because this information is not updated when the device is in a low power state
6676 * it should not be relied-upon to be current.
6677 * @param subId Subscription index
6678 * @return the most recent cached signal strength info from the modem
6679 */
6680 @Override
6681 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006682 final long identity = Binder.clearCallingIdentity();
6683 try {
6684 Phone p = getPhone(subId);
6685 if (p == null) {
6686 return null;
6687 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006689 return p.getSignalStrength();
6690 } finally {
6691 Binder.restoreCallingIdentity(identity);
6692 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006693 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006694
Pengquan Meng77b7f132018-08-22 14:49:57 -07006695 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006696 * Get the current modem radio state for the given slot.
6697 * @param slotIndex slot index.
6698 * @param callingPackage the name of the package making the call.
6699 * @return the current radio power state from the modem
6700 */
6701 @Override
6702 public int getRadioPowerState(int slotIndex, String callingPackage) {
6703 Phone phone = PhoneFactory.getPhone(slotIndex);
6704 if (phone != null) {
6705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6706 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6707 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6708 }
6709
6710 final long identity = Binder.clearCallingIdentity();
6711 try {
6712 return phone.getRadioPowerState();
6713 } finally {
6714 Binder.restoreCallingIdentity(identity);
6715 }
6716 }
6717 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6718 }
6719
6720 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006721 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6722 *
6723 * <p>Requires one of the following permissions:
6724 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6725 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6726 * privileges.
6727 *
6728 * @param subId subscription id
6729 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6730 * {@code false}.
6731 */
6732 @Override
6733 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006734 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6735 null /* message */);
6736
Pengquan Menga1bb6272018-09-06 09:59:22 -07006737 boolean isEnabled = false;
6738 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006739 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006740 Phone phone = getPhone(subId);
6741 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006742 } catch (Exception e) {
6743 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6744 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006745 } finally {
6746 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006747 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006748 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006749 }
6750
6751
6752 /**
6753 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6754 *
6755 * <p> Requires permission:
6756 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6757 * privileges.
6758 *
6759 * @param subId subscription id
6760 * @param isEnabled {@code true} means enable, {@code false} means disable.
6761 */
6762 @Override
6763 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6765 mApp, subId, "setDataRoamingEnabled");
6766
Pengquan Menga1bb6272018-09-06 09:59:22 -07006767 final long identity = Binder.clearCallingIdentity();
6768 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006769 Phone phone = getPhone(subId);
6770 if (phone != null) {
6771 phone.setDataRoamingEnabled(isEnabled);
6772 }
6773 } finally {
6774 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006775 }
6776 }
6777
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006778 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006779 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006780 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6781 mApp, subId, "isManualNetworkSelectionAllowed");
6782
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006783 boolean isAllowed = true;
6784 final long identity = Binder.clearCallingIdentity();
6785 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006786 Phone phone = getPhone(subId);
6787 if (phone != null) {
6788 isAllowed = phone.isCspPlmnEnabled();
6789 }
6790 } finally {
6791 Binder.restoreCallingIdentity(identity);
6792 }
6793 return isAllowed;
6794 }
6795
6796 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006797 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006798 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006799 try {
6800 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006801 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006802 } catch (SecurityException e) {
6803 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6804 // has carrier privileges on an active UICC
6805 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6806 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006807 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006808 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006809 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006810
6811 final long identity = Binder.clearCallingIdentity();
6812 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006813 UiccController uiccController = UiccController.getInstance();
6814 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006815 if (hasReadPermission) {
6816 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006817 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006818
6819 // Remove private info if the caller doesn't have access
6820 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6821 for (UiccCardInfo cardInfo : cardInfos) {
6822 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6823 // is available
6824 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6825 if (card == null || card.getUiccProfile() == null) {
6826 // assume no access if the card or profile is unavailable
6827 filteredInfos.add(cardInfo.getUnprivileged());
6828 continue;
6829 }
6830 UiccProfile profile = card.getUiccProfile();
6831 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6832 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6833 filteredInfos.add(cardInfo);
6834 } else {
6835 filteredInfos.add(cardInfo.getUnprivileged());
6836 }
6837 }
6838 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006839 } finally {
6840 Binder.restoreCallingIdentity(identity);
6841 }
6842 }
6843
6844 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006845 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006846 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006847
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006848 final long identity = Binder.clearCallingIdentity();
6849 try {
6850 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6851 if (slots == null) {
6852 Rlog.i(LOG_TAG, "slots is null.");
6853 return null;
6854 }
6855
6856 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6857 for (int i = 0; i < slots.length; i++) {
6858 UiccSlot slot = slots[i];
6859 if (slot == null) {
6860 continue;
6861 }
6862
Jordan Liu7be7e652019-05-06 18:55:02 +00006863 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006864 UiccCard card = slot.getUiccCard();
6865 if (card != null) {
6866 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006867 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006868 cardId = slot.getEid();
6869 if (TextUtils.isEmpty(cardId)) {
6870 cardId = slot.getIccId();
6871 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006872 }
6873
Jordan Liu857451f2019-05-09 16:35:35 -07006874 if (cardId != null) {
6875 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6876 // if cardId is an EID, it's all digits so this is fine
6877 cardId = IccUtils.stripTrailingFs(cardId);
6878 }
6879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006880 int cardState = 0;
6881 switch (slot.getCardState()) {
6882 case CARDSTATE_ABSENT:
6883 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6884 break;
6885 case CARDSTATE_PRESENT:
6886 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6887 break;
6888 case CARDSTATE_ERROR:
6889 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6890 break;
6891 case CARDSTATE_RESTRICTED:
6892 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6893 break;
6894 default:
6895 break;
6896
6897 }
6898
6899 infos[i] = new UiccSlotInfo(
6900 slot.isActive(),
6901 slot.isEuicc(),
6902 cardId,
6903 cardState,
6904 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006905 slot.isExtendedApduSupported(),
6906 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907 }
6908 return infos;
6909 } finally {
6910 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006911 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006912 }
6913
6914 @Override
6915 public boolean switchSlots(int[] physicalSlots) {
6916 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006917
6918 final long identity = Binder.clearCallingIdentity();
6919 try {
6920 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6921 } finally {
6922 Binder.restoreCallingIdentity(identity);
6923 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006924 }
Jack Yu4c988042018-02-27 15:30:01 -08006925
6926 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006927 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006928 final long identity = Binder.clearCallingIdentity();
6929 try {
6930 return UiccController.getInstance().getCardIdForDefaultEuicc();
6931 } finally {
6932 Binder.restoreCallingIdentity(identity);
6933 }
6934 }
6935
6936 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006937 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6938 enforceModifyPermission();
6939 final Phone phone = getPhone(subId);
6940 if (phone == null) {
6941 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6942 return;
6943 }
6944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006945 final long identity = Binder.clearCallingIdentity();
6946 try {
6947 phone.setRadioIndicationUpdateMode(filters, mode);
6948 } finally {
6949 Binder.restoreCallingIdentity(identity);
6950 }
Jack Yu4c988042018-02-27 15:30:01 -08006951 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006952
6953 /**
goneil47ffb6e2018-04-06 15:40:58 -07006954 * A test API to reload the UICC profile.
6955 *
6956 * <p>Requires that the calling app has permission
6957 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6958 * @hide
6959 */
6960 @Override
6961 public void refreshUiccProfile(int subId) {
6962 enforceModifyPermission();
6963
6964 final long identity = Binder.clearCallingIdentity();
6965 try {
6966 Phone phone = getPhone(subId);
6967 if (phone == null) {
6968 return;
6969 }
6970 UiccCard uiccCard = phone.getUiccCard();
6971 if (uiccCard == null) {
6972 return;
6973 }
6974 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6975 if (uiccProfile == null) {
6976 return;
6977 }
6978 uiccProfile.refresh();
6979 } finally {
6980 Binder.restoreCallingIdentity(identity);
6981 }
6982 }
6983
6984 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006985 * Returns false if the mobile data is disabled by default, otherwise return true.
6986 */
6987 private boolean getDefaultDataEnabled() {
6988 return "true".equalsIgnoreCase(
6989 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6990 }
6991
6992 /**
6993 * Returns true if the data roaming is enabled by default, i.e the system property
6994 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6995 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6996 */
6997 private boolean getDefaultDataRoamingEnabled(int subId) {
6998 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006999 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007000 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
7001 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
7002 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7003 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7004 return isDataRoamingEnabled;
7005 }
7006
7007 /**
7008 * Returns the default network type for the given {@code subId}, if the default network type is
7009 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7010 */
7011 private int getDefaultNetworkType(int subId) {
7012 return Integer.parseInt(
7013 TelephonyManager.getTelephonyProperty(
7014 mSubscriptionController.getPhoneId(subId),
7015 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
7016 String.valueOf(Phone.PREFERRED_NT_MODE)));
7017 }
fionaxua13278b2018-03-21 00:08:13 -07007018
7019 @Override
7020 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007021 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007022 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023
7024 final long identity = Binder.clearCallingIdentity();
7025 try {
7026 final Phone phone = getPhone(subId);
7027 if (phone == null) {
7028 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7029 return;
7030 }
chen xueaba88a2019-03-15 13:15:10 -07007031 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7032 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007033 } finally {
7034 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007035 }
fionaxua13278b2018-03-21 00:08:13 -07007036 }
7037
7038 @Override
7039 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007040 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041
7042 final long identity = Binder.clearCallingIdentity();
7043 try {
7044 final Phone phone = getPhone(subId);
7045 if (phone == null) {
7046 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7047 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7048 }
7049 return phone.getCarrierIdListVersion();
7050 } finally {
7051 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007052 }
fionaxua13278b2018-03-21 00:08:13 -07007053 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007054
7055 @Override
7056 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
7057 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7058 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
7059 return -1;
7060 }
7061
7062 final long identity = Binder.clearCallingIdentity();
7063 try {
7064 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7065 } finally {
7066 Binder.restoreCallingIdentity(identity);
7067 }
7068 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007069
7070 @Override
7071 public int getCdmaRoamingMode(int subId) {
7072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7073 mApp, subId, "getCdmaRoamingMode");
7074
7075 final long identity = Binder.clearCallingIdentity();
7076 try {
7077 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7078 } finally {
7079 Binder.restoreCallingIdentity(identity);
7080 }
7081 }
7082
7083 @Override
7084 public boolean setCdmaRoamingMode(int subId, int mode) {
7085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7086 mApp, subId, "setCdmaRoamingMode");
7087
7088 final long identity = Binder.clearCallingIdentity();
7089 try {
7090 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7091 } finally {
7092 Binder.restoreCallingIdentity(identity);
7093 }
7094 }
7095
7096 @Override
7097 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7099 mApp, subId, "setCdmaSubscriptionMode");
7100
7101 final long identity = Binder.clearCallingIdentity();
7102 try {
7103 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7104 } finally {
7105 Binder.restoreCallingIdentity(identity);
7106 }
7107 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007108
sqianc5eccab2018-10-19 18:46:41 -07007109 @Override
sqian8c685422019-02-22 15:55:18 -08007110 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007111 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007112 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007113 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007114 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7115 }
7116 final long identity = Binder.clearCallingIdentity();
7117 try {
sqian854d44b2018-12-12 16:48:18 -08007118 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7119 for (Phone phone: PhoneFactory.getPhones()) {
7120 if (phone.getEmergencyNumberTracker() != null
7121 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7122 emergencyNumberListInternal.put(
7123 phone.getSubId(),
7124 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7125 }
sqian11b7a0e2018-12-05 18:48:28 -08007126 }
sqian854d44b2018-12-12 16:48:18 -08007127 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007128 } finally {
7129 Binder.restoreCallingIdentity(identity);
7130 }
sqianc5eccab2018-10-19 18:46:41 -07007131 }
7132
7133 @Override
sqian8c685422019-02-22 15:55:18 -08007134 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007135 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007136 if (!exactMatch) {
7137 TelephonyPermissions
7138 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007139 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007140 }
7141 final long identity = Binder.clearCallingIdentity();
7142 try {
sqian854d44b2018-12-12 16:48:18 -08007143 for (Phone phone: PhoneFactory.getPhones()) {
7144 if (phone.getEmergencyNumberTracker() != null
7145 && phone.getEmergencyNumberTracker() != null) {
7146 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7147 number, exactMatch)) {
7148 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007149 }
7150 }
sqian11b7a0e2018-12-05 18:48:28 -08007151 }
7152 return false;
7153 } finally {
7154 Binder.restoreCallingIdentity(identity);
7155 }
7156 }
7157
sqianf4ca7ed2019-01-15 18:32:07 -08007158 /**
7159 * Update emergency number list for test mode.
7160 */
7161 @Override
7162 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7163 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7164 "updateEmergencyNumberListTestMode");
7165
7166 final long identity = Binder.clearCallingIdentity();
7167 try {
7168 for (Phone phone: PhoneFactory.getPhones()) {
7169 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7170 if (tracker != null) {
7171 tracker.executeEmergencyNumberTestModeCommand(action, num);
7172 }
7173 }
7174 } finally {
7175 Binder.restoreCallingIdentity(identity);
7176 }
7177 }
7178
7179 /**
7180 * Get the full emergency number list for test mode.
7181 */
7182 @Override
7183 public List<String> getEmergencyNumberListTestMode() {
7184 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7185 "getEmergencyNumberListTestMode");
7186
7187 final long identity = Binder.clearCallingIdentity();
7188 try {
7189 Set<String> emergencyNumbers = new HashSet<>();
7190 for (Phone phone: PhoneFactory.getPhones()) {
7191 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7192 if (tracker != null) {
7193 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7194 emergencyNumbers.add(num.getNumber());
7195 }
7196 }
7197 }
7198 return new ArrayList<>(emergencyNumbers);
7199 } finally {
7200 Binder.restoreCallingIdentity(identity);
7201 }
7202 }
7203
chen xud6b45bd2018-10-30 22:27:10 -07007204 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007205 public int getEmergencyNumberDbVersion(int subId) {
7206 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7207
7208 final long identity = Binder.clearCallingIdentity();
7209 try {
7210 final Phone phone = getPhone(subId);
7211 if (phone == null) {
7212 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7213 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7214 }
7215 return phone.getEmergencyNumberDbVersion();
7216 } finally {
7217 Binder.restoreCallingIdentity(identity);
7218 }
7219 }
7220
7221 @Override
7222 public void notifyOtaEmergencyNumberDbInstalled() {
7223 enforceModifyPermission();
7224
7225 final long identity = Binder.clearCallingIdentity();
7226 try {
7227 for (Phone phone: PhoneFactory.getPhones()) {
7228 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7229 if (tracker != null) {
7230 tracker.updateOtaEmergencyNumberDatabase();
7231 }
7232 }
7233 } finally {
7234 Binder.restoreCallingIdentity(identity);
7235 }
7236 }
7237
7238 @Override
7239 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7240 enforceActiveEmergencySessionPermission();
7241
7242 final long identity = Binder.clearCallingIdentity();
7243 try {
7244 for (Phone phone: PhoneFactory.getPhones()) {
7245 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7246 if (tracker != null) {
7247 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7248 }
7249 }
7250 } finally {
7251 Binder.restoreCallingIdentity(identity);
7252 }
7253 }
7254
7255 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007256 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7257 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7258 Phone phone = getPhone(subId);
7259 if (phone == null) {
7260 return null;
7261 }
7262 final long identity = Binder.clearCallingIdentity();
7263 try {
7264 UiccProfile profile = UiccController.getInstance()
7265 .getUiccProfileForPhone(phone.getPhoneId());
7266 if (profile != null) {
7267 return profile.getCertsFromCarrierPrivilegeAccessRules();
7268 }
7269 } finally {
7270 Binder.restoreCallingIdentity(identity);
7271 }
7272 return null;
7273 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007274
7275 /**
7276 * Enable or disable a modem stack.
7277 */
7278 @Override
7279 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7280 enforceModifyPermission();
7281
7282 final long identity = Binder.clearCallingIdentity();
7283 try {
7284 Phone phone = PhoneFactory.getPhone(slotIndex);
7285 if (phone == null) {
7286 return false;
7287 } else {
7288 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7289 }
7290 } finally {
7291 Binder.restoreCallingIdentity(identity);
7292 }
7293 }
Michelecea4cf22018-12-21 15:00:11 -08007294
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007295 /**
7296 * Whether a modem stack is enabled or not.
7297 */
7298 @Override
7299 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7300 Phone phone = PhoneFactory.getPhone(slotIndex);
7301 if (phone == null) return false;
7302
7303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7304 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7305 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7306 }
7307
7308 final long identity = Binder.clearCallingIdentity();
7309 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007310 try {
7311 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7312 } catch (NoSuchElementException ex) {
7313 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7314 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007315 } finally {
7316 Binder.restoreCallingIdentity(identity);
7317 }
7318 }
7319
Michelecea4cf22018-12-21 15:00:11 -08007320 @Override
Michele0ea7d782019-03-19 14:58:42 -07007321 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007322 enforceModifyPermission();
7323
7324 final long identity = Binder.clearCallingIdentity();
7325 try {
7326 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007327 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007328 .commit();
7329 } finally {
7330 Binder.restoreCallingIdentity(identity);
7331 }
7332 }
7333
7334 @Override
Michele0ea7d782019-03-19 14:58:42 -07007335 @TelephonyManager.IsMultiSimSupportedResult
7336 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007338 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7339 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007340 }
Michelecea4cf22018-12-21 15:00:11 -08007341
7342 final long identity = Binder.clearCallingIdentity();
7343 try {
Michele0ea7d782019-03-19 14:58:42 -07007344 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007345 } finally {
7346 Binder.restoreCallingIdentity(identity);
7347 }
7348 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007349
Michele0ea7d782019-03-19 14:58:42 -07007350 @TelephonyManager.IsMultiSimSupportedResult
7351 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007352 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7353 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7354 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007355 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7356 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007357 }
7358 // Check if the hardware supports multisim functionality. If usage of multisim is not
7359 // supported by the modem, indicate that it is restricted.
7360 PhoneCapability staticCapability =
7361 mPhoneConfigurationManager.getStaticPhoneCapability();
7362 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007363 loge("isMultiSimSupportedInternal: no static configuration available");
7364 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007365 }
7366 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007367 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7368 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007369 }
7370 // Check if support of multiple SIMs is restricted by carrier
7371 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007372 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007373 }
7374
Michele0ea7d782019-03-19 14:58:42 -07007375 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007376 }
7377
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007378 /**
7379 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007380 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7381 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7382 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007383 * @param numOfSims number of active sims we want to switch to
7384 */
7385 @Override
7386 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007387 if (numOfSims == 1) {
7388 enforceModifyPermission();
7389 } else {
7390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7391 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7392 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007393 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007394
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007395 try {
Michele30b57b22019-03-01 12:01:14 -08007396 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007397 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007398 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7399 return;
7400 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007401 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7402 } finally {
7403 Binder.restoreCallingIdentity(identity);
7404 }
7405 }
7406
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007407 @Override
7408 public boolean isApplicationOnUicc(int subId, int appType) {
7409 enforceReadPrivilegedPermission("isApplicationOnUicc");
7410 Phone phone = getPhone(subId);
7411 if (phone == null) {
7412 return false;
7413 }
7414 final long identity = Binder.clearCallingIdentity();
7415 try {
7416 UiccCard uiccCard = phone.getUiccCard();
7417 if (uiccCard == null) {
7418 return false;
7419 }
7420 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7421 if (uiccProfile == null) {
7422 return false;
7423 }
7424 if (TelephonyManager.APPTYPE_SIM <= appType
7425 && appType <= TelephonyManager.APPTYPE_ISIM) {
7426 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7427 }
7428 return false;
7429 } finally {
7430 Binder.restoreCallingIdentity(identity);
7431 }
7432 }
7433
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007434 /**
chen xub4baa772019-04-03 10:23:41 -07007435 * Get whether making changes to modem configurations will trigger reboot.
7436 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007437 */
7438 @Override
chen xub4baa772019-04-03 10:23:41 -07007439 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7440 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7441 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7442 return false;
7443 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007444 final long identity = Binder.clearCallingIdentity();
7445 try {
7446 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7447 } finally {
7448 Binder.restoreCallingIdentity(identity);
7449 }
7450 }
7451
Nathan Harold29f5f052019-02-15 13:41:57 -08007452 private void updateModemStateMetrics() {
7453 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7454 // TODO: check the state for each modem if the api is ready.
7455 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7456 }
7457
Pengquan Meng3889a572019-01-23 11:16:29 -08007458 @Override
7459 public int[] getSlotsMapping() {
7460 enforceReadPrivilegedPermission("getSlotsMapping");
7461
7462 final long identity = Binder.clearCallingIdentity();
7463 try {
7464 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7465 // All logical slots should have a mapping to a physical slot.
7466 int[] logicalSlotsMapping = new int[phoneCount];
7467 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7468 for (int i = 0; i < slotInfos.length; i++) {
7469 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7470 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7471 }
7472 }
7473 return logicalSlotsMapping;
7474 } finally {
7475 Binder.restoreCallingIdentity(identity);
7476 }
7477 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007478
7479 /**
7480 * Get the IRadio HAL Version
7481 */
7482 @Override
7483 public int getRadioHalVersion() {
7484 Phone phone = getDefaultPhone();
7485 if (phone == null) return -1;
7486 HalVersion hv = phone.getHalVersion();
7487 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7488 return hv.major * 100 + hv.minor;
7489 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007490
7491 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007492 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7493 * corresponding network requests on a subId.
7494 *
7495 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007496 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007497 * 2) APN is un-metered for this subscription, or
7498 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7499 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7500 *
7501 * @return whether data is allowed for a apn type.
7502 *
7503 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007504 */
7505 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007506 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007507 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7508 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007509
7510 // Now that all security checks passes, perform the operation as ourselves.
7511 final long identity = Binder.clearCallingIdentity();
7512 try {
7513 Phone phone = getPhone(subId);
7514 if (phone == null) return false;
7515
Jack Yu41407ee2019-05-13 16:54:09 -07007516 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007517 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7518 } finally {
7519 Binder.restoreCallingIdentity(identity);
7520 }
7521 }
7522
7523 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007524 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007525 enforceReadPrivilegedPermission("isApnMetered");
7526
7527 // Now that all security checks passes, perform the operation as ourselves.
7528 final long identity = Binder.clearCallingIdentity();
7529 try {
7530 Phone phone = getPhone(subId);
7531 if (phone == null) return true; // By default return true.
7532
Jack Yu41407ee2019-05-13 16:54:09 -07007533 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007534 } finally {
7535 Binder.restoreCallingIdentity(identity);
7536 }
7537 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007538
7539 @Override
7540 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7541 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7542 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7543 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7544 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7545 }
7546 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7547 Intent intent = new Intent();
7548 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7549 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7550 // Bring up choose default SMS subscription dialog right now
7551 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7552 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7553 mApp.startActivity(intent);
7554 }
chen xud5ca2d52019-05-28 15:20:57 -07007555
7556 @Override
7557 public String getMmsUAProfUrl(int subId) {
7558 //TODO investigate if this API should require proper permission check in R b/133791609
7559 final long identity = Binder.clearCallingIdentity();
7560 try {
7561 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7562 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7563 } finally {
7564 Binder.restoreCallingIdentity(identity);
7565 }
7566 }
7567
7568 @Override
7569 public String getMmsUserAgent(int subId) {
7570 //TODO investigate if this API should require proper permission check in R b/133791609
7571 final long identity = Binder.clearCallingIdentity();
7572 try {
7573 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7574 .getString(com.android.internal.R.string.config_mms_user_agent);
7575 } finally {
7576 Binder.restoreCallingIdentity(identity);
7577 }
7578 }
Jack Yub07d4972019-05-28 16:12:25 -07007579
7580 @Override
7581 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7582 enforceModifyPermission();
7583
7584 // Now that all security checks passes, perform the operation as ourselves.
7585 final long identity = Binder.clearCallingIdentity();
7586 try {
7587 Phone phone = getPhone(subId);
7588 if (phone == null) return false;
7589
7590 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7591 } finally {
7592 Binder.restoreCallingIdentity(identity);
7593 }
7594 }
7595
7596 @Override
7597 public boolean isDataAllowedInVoiceCall(int subId) {
7598 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7599
7600 // Now that all security checks passes, perform the operation as ourselves.
7601 final long identity = Binder.clearCallingIdentity();
7602 try {
7603 Phone phone = getPhone(subId);
7604 if (phone == null) return false;
7605
7606 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7607 } finally {
7608 Binder.restoreCallingIdentity(identity);
7609 }
7610 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007611
7612 /**
7613 * Updates whether conference event pacakge handling is enabled.
7614 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7615 * otherwise.
7616 */
7617 @Override
7618 public void setCepEnabled(boolean isCepEnabled) {
7619 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7620
7621 final long identity = Binder.clearCallingIdentity();
7622 try {
7623 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7624 for (Phone phone : PhoneFactory.getPhones()) {
7625 Phone defaultPhone = phone.getImsPhone();
7626 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7627 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7628 ImsPhoneCallTracker imsPhoneCallTracker =
7629 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7630 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7631 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7632 + imsPhone.getMsisdn());
7633 }
7634 }
7635 } finally {
7636 Binder.restoreCallingIdentity(identity);
7637 }
7638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007639}