blob: a9d36ad8c5d776975b3d46ba91aea2ebd44f04eb [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070025import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070028import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070029import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.content.Context;
31import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070032import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070033import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070037import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080050import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070051import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070054import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-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 zhao2737e882019-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 Ebingera34a6c22019-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 Ebingerbc7dd582019-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;
Meng Wangafbc5852019-09-19 17:37:13 -0700159import 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 zhao2737e882019-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 Nallurid63128d2019-09-17 14:10:30 -0700266 private static final int CMD_ERASE_MODEM_CONFIG = 74;
267 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800269 // Parameters of select command.
270 private static final int SELECT_COMMAND = 0xA4;
271 private static final int SELECT_P1 = 0x04;
272 private static final int SELECT_P2 = 0;
273 private static final int SELECT_P3 = 0x10;
274
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 /** The singleton instance. */
276 private static PhoneInterfaceManager sInstance;
277
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800280 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700281 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private AppOpsManager mAppOps;
283 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800284 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700286 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287
Derek Tan97ebb422014-09-05 16:55:38 -0700288 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
289 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800290 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800291 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700292
Michelecea4cf22018-12-21 15:00:11 -0800293 // String to store multi SIM allowed
294 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
295
Derek Tan740e1672017-06-27 14:56:27 -0700296 // The AID of ISD-R.
297 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
298
yinxub1bed742017-04-17 11:45:04 -0700299 private NetworkScanRequestTracker mNetworkScanRequestTracker;
300
David Kelly5e06a7f2018-03-12 14:10:59 +0000301 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
302 private static final int MANUFACTURER_CODE_LENGTH = 8;
303
Derek Tan89e89d42014-07-08 17:00:10 -0700304 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700305 * Experiment flag to enable erase modem config on reset network, default value is false
306 */
307 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
308 "reset_network_erase_modem_config_enabled";
309
310 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700311 * A request object to use for transmitting data to an ICC.
312 */
313 private static final class IccAPDUArgument {
314 public int channel, cla, command, p1, p2, p3;
315 public String data;
316
317 public IccAPDUArgument(int channel, int cla, int command,
318 int p1, int p2, int p3, String data) {
319 this.channel = channel;
320 this.cla = cla;
321 this.command = command;
322 this.p1 = p1;
323 this.p2 = p2;
324 this.p3 = p3;
325 this.data = data;
326 }
327 }
328
329 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700330 * A request object to use for transmitting data to an ICC.
331 */
332 private static final class ManualNetworkSelectionArgument {
333 public OperatorInfo operatorInfo;
334 public boolean persistSelection;
335
336 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
337 this.operatorInfo = operatorInfo;
338 this.persistSelection = persistSelection;
339 }
340 }
341
342 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
344 * request after sending. The main thread will notify the request when it is complete.
345 */
346 private static final class MainThreadRequest {
347 /** The argument to use for the request */
348 public Object argument;
349 /** The result of the request that is run on the main thread */
350 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800351 // The subscriber id that this request applies to. Defaults to
352 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
353 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354
Nathan Harold92bed182018-10-12 18:16:49 -0700355 // In cases where subId is unavailable, the caller needs to specify the phone.
356 public Phone phone;
357
vagdeviaf9a5b92018-08-15 16:01:53 -0700358 public WorkSource workSource;
359
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360 public MainThreadRequest(Object argument) {
361 this.argument = argument;
362 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800363
Nathan Harold92bed182018-10-12 18:16:49 -0700364 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
365 this.argument = argument;
366 if (phone != null) {
367 this.phone = phone;
368 }
369 this.workSource = workSource;
370 }
371
vagdeviaf9a5b92018-08-15 16:01:53 -0700372 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800373 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800374 if (subId != null) {
375 this.subId = subId;
376 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700377 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800378 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 }
380
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800381 private static final class IncomingThirdPartyCallArgs {
382 public final ComponentName component;
383 public final String callId;
384 public final String callerDisplayName;
385
386 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
387 String callerDisplayName) {
388 this.component = component;
389 this.callId = callId;
390 this.callerDisplayName = callerDisplayName;
391 }
392 }
393
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 /**
395 * A handler that processes messages on the main thread in the phone process. Since many
396 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
397 * inbound binder threads to the main thread in the phone process. The Binder thread
398 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
399 * on, which will be notified when the operation completes and will contain the result of the
400 * request.
401 *
402 * <p>If a MainThreadRequest object is provided in the msg.obj field,
403 * note that request.result must be set to something non-null for the calling thread to
404 * unblock.
405 */
406 private final class MainThreadHandler extends Handler {
407 @Override
408 public void handleMessage(Message msg) {
409 MainThreadRequest request;
410 Message onCompleted;
411 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800412 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800414 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415
416 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700417 case CMD_HANDLE_USSD_REQUEST: {
418 request = (MainThreadRequest) msg.obj;
419 final Phone phone = getPhoneFromRequest(request);
420 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
421 String ussdRequest = ussdObject.first;
422 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700423
Pengquan Menga1bb6272018-09-06 09:59:22 -0700424 if (!isUssdApiAllowed(request.subId)) {
425 // Carrier does not support use of this API, return failure.
426 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
427 UssdResponse response = new UssdResponse(ussdRequest, null);
428 Bundle returnData = new Bundle();
429 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
430 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700431
Pengquan Menga1bb6272018-09-06 09:59:22 -0700432 request.result = true;
433 notifyRequester(request);
434 return;
435 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700436
Pengquan Menga1bb6272018-09-06 09:59:22 -0700437 try {
438 request.result = phone != null
439 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
440 } catch (CallStateException cse) {
441 request.result = false;
442 }
443 // Wake up the requesting thread
444 notifyRequester(request);
445 break;
pkanwar32d516d2016-10-14 19:37:38 -0700446 }
447
Yorke Lee716f67e2015-06-17 15:39:16 -0700448 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700450 final Phone phone = getPhoneFromRequest(request);
451 request.result = phone != null ?
452 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
453 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700455 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800462 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700463 if (uiccCard == null) {
464 loge("iccTransmitApduLogicalChannel: No UICC");
465 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700466 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700467 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700468 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
469 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700470 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 iccArgument.channel, iccArgument.cla, iccArgument.command,
472 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700473 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700474 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 break;
476
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 ar = (AsyncResult) msg.obj;
479 request = (MainThreadRequest) ar.userObj;
480 if (ar.exception == null && ar.result != null) {
481 request.result = ar.result;
482 } else {
483 request.result = new IccIoResult(0x6F, 0, (byte[])null);
484 if (ar.result == null) {
485 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800486 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700487 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800488 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 } else {
490 loge("iccTransmitApduLogicalChannel: Unknown exception");
491 }
492 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 break;
495
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
497 request = (MainThreadRequest) msg.obj;
498 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800499 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 if (uiccCard == null) {
501 loge("iccTransmitApduBasicChannel: No UICC");
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700504 } else {
505 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
506 request);
507 uiccCard.iccTransmitApduBasicChannel(
508 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
509 iccArgument.p3, iccArgument.data, onCompleted);
510 }
511 break;
512
513 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
514 ar = (AsyncResult) msg.obj;
515 request = (MainThreadRequest) ar.userObj;
516 if (ar.exception == null && ar.result != null) {
517 request.result = ar.result;
518 } else {
519 request.result = new IccIoResult(0x6F, 0, (byte[])null);
520 if (ar.result == null) {
521 loge("iccTransmitApduBasicChannel: Empty response");
522 } else if (ar.exception instanceof CommandException) {
523 loge("iccTransmitApduBasicChannel: CommandException: " +
524 ar.exception);
525 } else {
526 loge("iccTransmitApduBasicChannel: Unknown exception");
527 }
528 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 break;
531
532 case CMD_EXCHANGE_SIM_IO:
533 request = (MainThreadRequest) msg.obj;
534 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800535 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 if (uiccCard == null) {
537 loge("iccExchangeSimIO: No UICC");
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700539 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 } else {
541 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
542 request);
543 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
544 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
545 iccArgument.data, onCompleted);
546 }
547 break;
548
549 case EVENT_EXCHANGE_SIM_IO_DONE:
550 ar = (AsyncResult) msg.obj;
551 request = (MainThreadRequest) ar.userObj;
552 if (ar.exception == null && ar.result != null) {
553 request.result = ar.result;
554 } else {
555 request.result = new IccIoResult(0x6f, 0, (byte[])null);
556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 break;
559
Derek Tan4d5e5c12014-02-04 11:54:58 -0800560 case CMD_SEND_ENVELOPE:
561 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800562 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 if (uiccCard == null) {
564 loge("sendEnvelopeWithStatus: No UICC");
565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700567 } else {
568 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
569 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
570 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800571 break;
572
573 case EVENT_SEND_ENVELOPE_DONE:
574 ar = (AsyncResult) msg.obj;
575 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700576 if (ar.exception == null && ar.result != null) {
577 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800578 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700579 request.result = new IccIoResult(0x6F, 0, (byte[])null);
580 if (ar.result == null) {
581 loge("sendEnvelopeWithStatus: Empty response");
582 } else if (ar.exception instanceof CommandException) {
583 loge("sendEnvelopeWithStatus: CommandException: " +
584 ar.exception);
585 } else {
586 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
587 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800588 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 break;
591
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 case CMD_OPEN_CHANNEL:
593 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800594 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800595 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700596 if (uiccCard == null) {
597 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800598 request.result = new IccOpenLogicalChannelResponse(-1,
599 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 } else {
602 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800603 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
604 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700605 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 break;
607
608 case EVENT_OPEN_CHANNEL_DONE:
609 ar = (AsyncResult) msg.obj;
610 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 int[] result = (int[]) ar.result;
614 int channelId = result[0];
615 byte[] selectResponse = null;
616 if (result.length > 1) {
617 selectResponse = new byte[result.length - 1];
618 for (int i = 1; i < result.length; ++i) {
619 selectResponse[i - 1] = (byte) result[i];
620 }
621 }
622 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700623 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 if (ar.result == null) {
626 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 if (ar.exception != null) {
629 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
630 }
631
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700632 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700633 if (ar.exception instanceof CommandException) {
634 CommandException.Error error =
635 ((CommandException) (ar.exception)).getCommandError();
636 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700637 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700638 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700639 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 }
641 }
642 openChannelResp = new IccOpenLogicalChannelResponse(
643 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700645 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
649 case CMD_CLOSE_CHANNEL:
650 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800651 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700652 if (uiccCard == null) {
653 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900654 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700656 } else {
657 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
658 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
659 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 break;
661
662 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800663 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
664 break;
665
666 case CMD_NV_READ_ITEM:
667 request = (MainThreadRequest) msg.obj;
668 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800669 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
670 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800671 break;
672
673 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 ar = (AsyncResult) msg.obj;
675 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800676 if (ar.exception == null && ar.result != null) {
677 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800679 request.result = "";
680 if (ar.result == null) {
681 loge("nvReadItem: Empty response");
682 } else if (ar.exception instanceof CommandException) {
683 loge("nvReadItem: CommandException: " +
684 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700685 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800686 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 }
688 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700689 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 break;
691
Jake Hambye994d462014-02-03 13:10:13 -0800692 case CMD_NV_WRITE_ITEM:
693 request = (MainThreadRequest) msg.obj;
694 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
695 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800696 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700697 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
700 case EVENT_NV_WRITE_ITEM_DONE:
701 handleNullReturnEvent(msg, "nvWriteItem");
702 break;
703
704 case CMD_NV_WRITE_CDMA_PRL:
705 request = (MainThreadRequest) msg.obj;
706 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800707 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800708 break;
709
710 case EVENT_NV_WRITE_CDMA_PRL_DONE:
711 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
712 break;
713
chen xu6dac5ab2018-10-26 17:39:23 -0700714 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800715 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700716 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800717 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800718 break;
719
chen xu6dac5ab2018-10-26 17:39:23 -0700720 case EVENT_RESET_MODEM_CONFIG_DONE:
721 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800722 break;
723
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 case CMD_GET_PREFERRED_NETWORK_TYPE:
725 request = (MainThreadRequest) msg.obj;
726 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700727 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800728 break;
729
730 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
731 ar = (AsyncResult) msg.obj;
732 request = (MainThreadRequest) ar.userObj;
733 if (ar.exception == null && ar.result != null) {
734 request.result = ar.result; // Integer
735 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800736 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800737 if (ar.result == null) {
738 loge("getPreferredNetworkType: Empty response");
739 } else if (ar.exception instanceof CommandException) {
740 loge("getPreferredNetworkType: CommandException: " +
741 ar.exception);
742 } else {
743 loge("getPreferredNetworkType: Unknown exception");
744 }
745 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700746 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800747 break;
748
749 case CMD_SET_PREFERRED_NETWORK_TYPE:
750 request = (MainThreadRequest) msg.obj;
751 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
752 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700753 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800754 break;
755
756 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
757 handleNullReturnEvent(msg, "setPreferredNetworkType");
758 break;
759
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000760 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
761 request = (MainThreadRequest)msg.obj;
762 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800763 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000764 break;
765
766 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
767 ar = (AsyncResult)msg.obj;
768 request = (MainThreadRequest)ar.userObj;
769 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000771 break;
772
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800773 case CMD_SET_VOICEMAIL_NUMBER:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
776 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800777 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
778 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800779 break;
780
781 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
782 handleNullReturnEvent(msg, "setVoicemailNumber");
783 break;
784
Stuart Scott54788802015-03-30 13:18:01 -0700785 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
786 request = (MainThreadRequest) msg.obj;
787 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
788 request);
789 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
790 break;
791
792 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
793 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
794 break;
795
Shishir Agrawal302c8692015-06-19 13:49:39 -0700796 case CMD_PERFORM_NETWORK_SCAN:
797 request = (MainThreadRequest) msg.obj;
798 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
799 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
800 break;
801
802 case EVENT_PERFORM_NETWORK_SCAN_DONE:
803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
805 CellNetworkScanResult cellScanResult;
806 if (ar.exception == null && ar.result != null) {
807 cellScanResult = new CellNetworkScanResult(
808 CellNetworkScanResult.STATUS_SUCCESS,
809 (List<OperatorInfo>) ar.result);
810 } else {
811 if (ar.result == null) {
812 loge("getCellNetworkScanResults: Empty response");
813 }
814 if (ar.exception != null) {
815 loge("getCellNetworkScanResults: Exception: " + ar.exception);
816 }
817 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
818 if (ar.exception instanceof CommandException) {
819 CommandException.Error error =
820 ((CommandException) (ar.exception)).getCommandError();
821 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
822 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
823 } else if (error == CommandException.Error.GENERIC_FAILURE) {
824 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
825 }
826 }
827 cellScanResult = new CellNetworkScanResult(errorCode, null);
828 }
829 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700830 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700831 break;
832
833 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
834 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700835 ManualNetworkSelectionArgument selArg =
836 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700837 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
838 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700839 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
840 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700841 break;
842
843 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700844 ar = (AsyncResult) msg.obj;
845 request = (MainThreadRequest) ar.userObj;
846 if (ar.exception == null) {
847 request.result = true;
848 } else {
849 request.result = false;
850 loge("setNetworkSelectionModeManual " + ar.exception);
851 }
852 notifyRequester(request);
853 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700854 break;
855
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700856 case CMD_GET_MODEM_ACTIVITY_INFO:
857 request = (MainThreadRequest) msg.obj;
858 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700859 if (defaultPhone != null) {
860 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
861 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700862 break;
863
864 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
865 ar = (AsyncResult) msg.obj;
866 request = (MainThreadRequest) ar.userObj;
867 if (ar.exception == null && ar.result != null) {
868 request.result = ar.result;
869 } else {
870 if (ar.result == null) {
871 loge("queryModemActivityInfo: Empty response");
872 } else if (ar.exception instanceof CommandException) {
873 loge("queryModemActivityInfo: CommandException: " +
874 ar.exception);
875 } else {
876 loge("queryModemActivityInfo: Unknown exception");
877 }
878 }
Amit Mahajand4766222016-01-28 15:28:28 -0800879 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
880 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800881 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800882 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700883 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700884 break;
885
Meng Wang1a7c35a2016-05-05 20:56:15 -0700886 case CMD_SET_ALLOWED_CARRIERS:
887 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800888 CarrierRestrictionRules argument =
889 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700890 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800891 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700892 break;
893
894 case EVENT_SET_ALLOWED_CARRIERS_DONE:
895 ar = (AsyncResult) msg.obj;
896 request = (MainThreadRequest) ar.userObj;
897 if (ar.exception == null && ar.result != null) {
898 request.result = ar.result;
899 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800900 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
901 if (ar.exception instanceof CommandException) {
902 loge("setAllowedCarriers: CommandException: " + ar.exception);
903 CommandException.Error error =
904 ((CommandException) (ar.exception)).getCommandError();
905 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
906 request.result =
907 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
908 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700909 } else {
910 loge("setAllowedCarriers: Unknown exception");
911 }
912 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700913 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700914 break;
915
916 case CMD_GET_ALLOWED_CARRIERS:
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800919 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700920 break;
921
922 case EVENT_GET_ALLOWED_CARRIERS_DONE:
923 ar = (AsyncResult) msg.obj;
924 request = (MainThreadRequest) ar.userObj;
925 if (ar.exception == null && ar.result != null) {
926 request.result = ar.result;
927 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800928 request.result = new IllegalStateException(
929 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700930 if (ar.result == null) {
931 loge("getAllowedCarriers: Empty response");
932 } else if (ar.exception instanceof CommandException) {
933 loge("getAllowedCarriers: CommandException: " +
934 ar.exception);
935 } else {
936 loge("getAllowedCarriers: Unknown exception");
937 }
938 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700939 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700940 break;
941
Nathan Haroldb3014052017-01-25 15:57:32 -0800942 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
945 if (ar.exception == null && ar.result != null) {
946 request.result = ar.result;
947 } else {
948 request.result = new IllegalArgumentException(
949 "Failed to retrieve Forbidden Plmns");
950 if (ar.result == null) {
951 loge("getForbiddenPlmns: Empty response");
952 } else {
953 loge("getForbiddenPlmns: Unknown exception");
954 }
955 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800957 break;
958
959 case CMD_GET_FORBIDDEN_PLMNS:
960 request = (MainThreadRequest) msg.obj;
961 uiccCard = getUiccCardFromRequest(request);
962 if (uiccCard == null) {
963 loge("getForbiddenPlmns() UiccCard is null");
964 request.result = new IllegalArgumentException(
965 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700966 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800967 break;
968 }
969 Integer appType = (Integer) request.argument;
970 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
971 if (uiccApp == null) {
972 loge("getForbiddenPlmns() no app with specified type -- "
973 + appType);
974 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700975 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800976 break;
977 } else {
978 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
979 + " specified type -- " + appType);
980 }
981 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
982 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
983 onCompleted);
984 break;
985
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000986 case CMD_SWITCH_SLOTS:
987 request = (MainThreadRequest) msg.obj;
988 int[] physicalSlots = (int[]) request.argument;
989 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
990 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
991 break;
992
993 case EVENT_SWITCH_SLOTS_DONE:
994 ar = (AsyncResult) msg.obj;
995 request = (MainThreadRequest) ar.userObj;
996 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700997 notifyRequester(request);
998 break;
999 case CMD_GET_NETWORK_SELECTION_MODE:
1000 request = (MainThreadRequest) msg.obj;
1001 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1002 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1003 break;
1004
1005 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1006 ar = (AsyncResult) msg.obj;
1007 request = (MainThreadRequest) ar.userObj;
1008 if (ar.exception != null) {
1009 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1010 } else {
1011 int mode = ((int[]) ar.result)[0];
1012 if (mode == 0) {
1013 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1014 } else {
1015 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1016 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001017 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001018 notifyRequester(request);
1019 break;
1020 case CMD_GET_CDMA_ROAMING_MODE:
1021 request = (MainThreadRequest) msg.obj;
1022 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1023 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1024 break;
1025 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1026 ar = (AsyncResult) msg.obj;
1027 request = (MainThreadRequest) ar.userObj;
1028 if (ar.exception != null) {
1029 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1030 } else {
1031 request.result = ((int[]) ar.result)[0];
1032 }
1033 notifyRequester(request);
1034 break;
1035 case CMD_SET_CDMA_ROAMING_MODE:
1036 request = (MainThreadRequest) msg.obj;
1037 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1038 int mode = (int) request.argument;
1039 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1040 break;
1041 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
1044 request.result = ar.exception == null;
1045 notifyRequester(request);
1046 break;
1047 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1048 request = (MainThreadRequest) msg.obj;
1049 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1050 int subscriptionMode = (int) request.argument;
1051 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1052 break;
1053 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1054 ar = (AsyncResult) msg.obj;
1055 request = (MainThreadRequest) ar.userObj;
1056 request.result = ar.exception == null;
1057 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001058 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001059 case CMD_GET_ALL_CELL_INFO:
1060 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001062 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 case EVENT_GET_ALL_CELL_INFO_DONE:
1065 ar = (AsyncResult) msg.obj;
1066 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001067 // If a timeout occurs, the response will be null
1068 request.result = (ar.exception == null && ar.result != null)
1069 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001070 synchronized (request) {
1071 request.notifyAll();
1072 }
1073 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001074 case CMD_REQUEST_CELL_INFO_UPDATE:
1075 request = (MainThreadRequest) msg.obj;
1076 request.phone.requestCellInfoUpdate(request.workSource,
1077 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1078 break;
1079 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1080 ar = (AsyncResult) msg.obj;
1081 request = (MainThreadRequest) ar.userObj;
1082 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1083 try {
1084 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001086 cb.onError(
1087 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1088 ar.exception.getClass().getName(),
1089 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001090 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001091 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001092 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 } else {
1094 // use the result as returned
1095 cb.onCellInfo((List<CellInfo>) ar.result);
1096 }
1097 } catch (RemoteException re) {
1098 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1099 }
1100 break;
1101 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001102 request = (MainThreadRequest) msg.obj;
1103 WorkSource ws = (WorkSource) request.argument;
1104 Phone phone = getPhoneFromRequest(request);
1105 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1106 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001107 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001108 ar = (AsyncResult) msg.obj;
1109 request = (MainThreadRequest) ar.userObj;
1110 if (ar.exception == null) {
1111 request.result = ar.result;
1112 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001113 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001114 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1115 ? new CdmaCellLocation() : new GsmCellLocation();
1116 }
1117
1118 synchronized (request) {
1119 request.notifyAll();
1120 }
1121 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001122 case CMD_MODEM_REBOOT:
1123 request = (MainThreadRequest) msg.obj;
1124 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001125 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001126 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001127 case EVENT_CMD_MODEM_REBOOT_DONE:
1128 handleNullReturnEvent(msg, "rebootModem");
1129 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001130 case CMD_REQUEST_ENABLE_MODEM:
1131 request = (MainThreadRequest) msg.obj;
1132 boolean enable = (boolean) request.argument;
1133 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001134 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001135 PhoneConfigurationManager.getInstance()
1136 .enablePhone(request.phone, enable, onCompleted);
1137 break;
1138 case EVENT_ENABLE_MODEM_DONE:
1139 ar = (AsyncResult) msg.obj;
1140 request = (MainThreadRequest) ar.userObj;
1141 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001142 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001143 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001144 if ((boolean) request.result) {
1145 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1146 updateModemStateMetrics();
1147 } else {
1148 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1149 + ar.exception);
1150 }
1151 notifyRequester(request);
1152 break;
1153 case CMD_GET_MODEM_STATUS:
1154 request = (MainThreadRequest) msg.obj;
1155 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1156 PhoneConfigurationManager.getInstance()
1157 .getPhoneStatusFromModem(request.phone, onCompleted);
1158 break;
1159 case EVENT_GET_MODEM_STATUS_DONE:
1160 ar = (AsyncResult) msg.obj;
1161 request = (MainThreadRequest) ar.userObj;
1162 int id = request.phone.getPhoneId();
1163 if (ar.exception == null && ar.result != null) {
1164 request.result = ar.result;
1165 //update the cache as modem status has changed
1166 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1167 (boolean) request.result);
1168 } else {
1169 // Return true if modem status cannot be retrieved. For most cases,
1170 // modem status is on. And for older version modems, GET_MODEM_STATUS
1171 // and disable modem are not supported. Modem is always on.
1172 // TODO: this should be fixed in R to support a third
1173 // status UNKNOWN b/131631629
1174 request.result = true;
1175 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1176 + ar.exception);
1177 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001178 notifyRequester(request);
1179 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001180 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1181 ar = (AsyncResult) msg.obj;
1182 request = (MainThreadRequest) ar.userObj;
1183 if (ar.exception == null && ar.result != null) {
1184 request.result = ar.result;
1185 } else {
1186 request.result = -1;
1187 loge("Failed to set Forbidden Plmns");
1188 if (ar.result == null) {
1189 loge("setForbidenPlmns: Empty response");
1190 } else if (ar.exception != null) {
1191 loge("setForbiddenPlmns: Exception: " + ar.exception);
1192 request.result = -1;
1193 } else {
1194 loge("setForbiddenPlmns: Unknown exception");
1195 }
1196 }
1197 notifyRequester(request);
1198 break;
1199 case CMD_SET_FORBIDDEN_PLMNS:
1200 request = (MainThreadRequest) msg.obj;
1201 uiccCard = getUiccCardFromRequest(request);
1202 if (uiccCard == null) {
1203 loge("setForbiddenPlmns: UiccCard is null");
1204 request.result = -1;
1205 notifyRequester(request);
1206 break;
1207 }
1208 Pair<Integer, List<String>> setFplmnsArgs =
1209 (Pair<Integer, List<String>>) request.argument;
1210 appType = setFplmnsArgs.first;
1211 List<String> fplmns = setFplmnsArgs.second;
1212 uiccApp = uiccCard.getApplicationByType(appType);
1213 if (uiccApp == null) {
1214 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1215 request.result = -1;
1216 loge("Failed to get UICC App");
1217 notifyRequester(request);
1218 } else {
1219 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1220 ((SIMRecords) uiccApp.getIccRecords())
1221 .setForbiddenPlmns(onCompleted, fplmns);
1222 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001223 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001224 case CMD_ERASE_MODEM_CONFIG:
1225 request = (MainThreadRequest) msg.obj;
1226 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1227 defaultPhone.eraseModemConfig(onCompleted);
1228 break;
1229 case EVENT_ERASE_MODEM_CONFIG_DONE:
1230 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001231 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232 default:
1233 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1234 break;
1235 }
1236 }
Jake Hambye994d462014-02-03 13:10:13 -08001237
Pengquan Menga1bb6272018-09-06 09:59:22 -07001238 private void notifyRequester(MainThreadRequest request) {
1239 synchronized (request) {
1240 request.notifyAll();
1241 }
1242 }
1243
Jake Hambye994d462014-02-03 13:10:13 -08001244 private void handleNullReturnEvent(Message msg, String command) {
1245 AsyncResult ar = (AsyncResult) msg.obj;
1246 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1247 if (ar.exception == null) {
1248 request.result = true;
1249 } else {
1250 request.result = false;
1251 if (ar.exception instanceof CommandException) {
1252 loge(command + ": CommandException: " + ar.exception);
1253 } else {
1254 loge(command + ": Unknown exception");
1255 }
1256 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001257 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259 }
1260
1261 /**
1262 * Posts the specified command to be executed on the main thread,
1263 * waits for the request to complete, and returns the result.
1264 * @see #sendRequestAsync
1265 */
1266 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001267 return sendRequest(
1268 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001269 }
1270
1271 /**
1272 * Posts the specified command to be executed on the main thread,
1273 * waits for the request to complete, and returns the result.
1274 * @see #sendRequestAsync
1275 */
1276 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1277 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001278 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001279 }
1280
1281 /**
1282 * Posts the specified command to be executed on the main thread,
1283 * waits for the request to complete, and returns the result.
1284 * @see #sendRequestAsync
1285 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001286 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001287 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001288 }
1289
1290 /**
1291 * Posts the specified command to be executed on the main thread,
1292 * waits for the request to complete, and returns the result.
1293 * @see #sendRequestAsync
1294 */
Nathan Harold92bed182018-10-12 18:16:49 -07001295 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1296 return sendRequest(command, argument, subId, null, workSource);
1297 }
1298
1299 /**
1300 * Posts the specified command to be executed on the main thread,
1301 * waits for the request to complete, and returns the result.
1302 * @see #sendRequestAsync
1303 */
1304 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1305 return sendRequest(
1306 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1307 }
1308
1309 /**
1310 * Posts the specified command to be executed on the main thread,
1311 * waits for the request to complete, and returns the result.
1312 * @see #sendRequestAsync
1313 */
1314 private Object sendRequest(
1315 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1317 throw new RuntimeException("This method will deadlock if called from the main thread.");
1318 }
1319
Nathan Harold92bed182018-10-12 18:16:49 -07001320 MainThreadRequest request = null;
1321 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1322 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1323 } else if (phone != null) {
1324 request = new MainThreadRequest(argument, phone, workSource);
1325 } else {
1326 request = new MainThreadRequest(argument, subId, workSource);
1327 }
1328
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329 Message msg = mMainThreadHandler.obtainMessage(command, request);
1330 msg.sendToTarget();
1331
1332 // Wait for the request to complete
1333 synchronized (request) {
1334 while (request.result == null) {
1335 try {
1336 request.wait();
1337 } catch (InterruptedException e) {
1338 // Do nothing, go back and wait until the request is complete
1339 }
1340 }
1341 }
1342 return request.result;
1343 }
1344
1345 /**
1346 * Asynchronous ("fire and forget") version of sendRequest():
1347 * Posts the specified command to be executed on the main thread, and
1348 * returns immediately.
1349 * @see #sendRequest
1350 */
1351 private void sendRequestAsync(int command) {
1352 mMainThreadHandler.sendEmptyMessage(command);
1353 }
1354
1355 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001356 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001357 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001358 */
1359 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001360 sendRequestAsync(command, argument, null, null);
1361 }
1362
1363 /**
1364 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1365 * @see {@link #sendRequest(int,Object)}
1366 */
1367 private void sendRequestAsync(
1368 int command, Object argument, Phone phone, WorkSource workSource) {
1369 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001370 Message msg = mMainThreadHandler.obtainMessage(command, request);
1371 msg.sendToTarget();
1372 }
1373
1374 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 * Initialize the singleton PhoneInterfaceManager instance.
1376 * This is only done once, at startup, from PhoneApp.onCreate().
1377 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001378 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 synchronized (PhoneInterfaceManager.class) {
1380 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001381 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 } else {
1383 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1384 }
1385 return sInstance;
1386 }
1387 }
1388
1389 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001390 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001393 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001394 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1396 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001397 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001398 mTelephonySharedPreferences =
1399 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001400 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001401 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001402
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 publish();
1404 }
1405
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001406 private Phone getDefaultPhone() {
1407 Phone thePhone = getPhone(getDefaultSubscription());
1408 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1409 }
1410
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 private void publish() {
1412 if (DBG) log("publish: " + this);
1413
1414 ServiceManager.addService("phone", this);
1415 }
1416
Stuart Scott584921c2015-01-15 17:10:34 -08001417 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001418 if (request.phone != null) {
1419 return request.phone;
1420 } else {
1421 return getPhoneFromSubId(request.subId);
1422 }
1423 }
1424
1425 private Phone getPhoneFromSubId(int subId) {
1426 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1427 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001428 }
1429
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001430 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1431 Phone phone = getPhoneFromRequest(request);
1432 return phone == null ? null :
1433 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1434 }
1435
Wink Saville36469e72014-06-11 15:17:00 -07001436 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001437 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001438 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440
Naina Nallurid63128d2019-09-17 14:10:30 -07001441 private void sendEraseModemConfig(Phone phone) {
1442 if (phone != null) {
1443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1444 mApp, phone.getSubId(), "eraseModemConfig");
1445 final long identity = Binder.clearCallingIdentity();
1446 try {
1447 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1448 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1449 } finally {
1450 Binder.restoreCallingIdentity(identity);
1451 }
1452 }
1453 }
1454
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001455 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001456 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001457 }
1458
Wink Savilleb564aae2014-10-23 10:18:09 -07001459 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 if (DBG) log("dial: " + number);
1461 // No permission check needed here: This is just a wrapper around the
1462 // ACTION_DIAL intent, which is available to any app since it puts up
1463 // the UI before it does anything.
1464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001465 final long identity = Binder.clearCallingIdentity();
1466 try {
1467 String url = createTelUrl(number);
1468 if (url == null) {
1469 return;
1470 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001472 // PENDING: should we just silently fail if phone is offhook or ringing?
1473 PhoneConstants.State state = mCM.getState(subId);
1474 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1475 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1476 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1477 mApp.startActivity(intent);
1478 }
1479 } finally {
1480 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 }
1482 }
1483
1484 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001485 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001486 }
1487
Wink Savilleb564aae2014-10-23 10:18:09 -07001488 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 if (DBG) log("call: " + number);
1490
1491 // This is just a wrapper around the ACTION_CALL intent, but we still
1492 // need to do a permission check since we're calling startActivity()
1493 // from the context of the phone app.
1494 enforceCallPermission();
1495
Jordan Liu1617b712019-07-10 15:06:26 -07001496 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 != AppOpsManager.MODE_ALLOWED) {
1498 return;
1499 }
1500
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001501 final long identity = Binder.clearCallingIdentity();
1502 try {
1503 String url = createTelUrl(number);
1504 if (url == null) {
1505 return;
1506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001508 boolean isValid = false;
1509 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1510 if (slist != null) {
1511 for (SubscriptionInfo subInfoRecord : slist) {
1512 if (subInfoRecord.getSubscriptionId() == subId) {
1513 isValid = true;
1514 break;
1515 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001516 }
Wink Saville08874612014-08-31 19:19:58 -07001517 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001518 if (!isValid) {
1519 return;
1520 }
Wink Saville08874612014-08-31 19:19:58 -07001521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001522 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1523 intent.putExtra(SUBSCRIPTION_KEY, subId);
1524 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1525 mApp.startActivity(intent);
1526 } finally {
1527 Binder.restoreCallingIdentity(identity);
1528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 }
1530
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001532 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001533 }
1534
Wink Savilleb564aae2014-10-23 10:18:09 -07001535 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001537 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1538 }
1539
1540 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001541 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
Wink Savilleb564aae2014-10-23 10:18:09 -07001544 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001545 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001546 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1547 }
1548
1549 /** {@hide} */
1550 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001551 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001552 }
1553
Wink Savilleb564aae2014-10-23 10:18:09 -07001554 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001556
1557 final long identity = Binder.clearCallingIdentity();
1558 try {
1559 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1560 checkSimPin.start();
1561 return checkSimPin.unlockSim(null, pin);
1562 } finally {
1563 Binder.restoreCallingIdentity(identity);
1564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 }
1566
Wink Saville9de0f752013-10-22 19:04:03 -07001567 /** {@hide} */
1568 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001569 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001570 }
1571
Wink Savilleb564aae2014-10-23 10:18:09 -07001572 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001574
1575 final long identity = Binder.clearCallingIdentity();
1576 try {
1577 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1578 checkSimPuk.start();
1579 return checkSimPuk.unlockSim(puk, pin);
1580 } finally {
1581 Binder.restoreCallingIdentity(identity);
1582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
1585 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001586 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 * a synchronous one.
1588 */
1589 private static class UnlockSim extends Thread {
1590
1591 private final IccCard mSimCard;
1592
1593 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001594 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1595 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596
1597 // For replies from SimCard interface
1598 private Handler mHandler;
1599
1600 // For async handler to identify request type
1601 private static final int SUPPLY_PIN_COMPLETE = 100;
1602
1603 public UnlockSim(IccCard simCard) {
1604 mSimCard = simCard;
1605 }
1606
1607 @Override
1608 public void run() {
1609 Looper.prepare();
1610 synchronized (UnlockSim.this) {
1611 mHandler = new Handler() {
1612 @Override
1613 public void handleMessage(Message msg) {
1614 AsyncResult ar = (AsyncResult) msg.obj;
1615 switch (msg.what) {
1616 case SUPPLY_PIN_COMPLETE:
1617 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1618 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001619 mRetryCount = msg.arg1;
1620 if (ar.exception != null) {
1621 if (ar.exception instanceof CommandException &&
1622 ((CommandException)(ar.exception)).getCommandError()
1623 == CommandException.Error.PASSWORD_INCORRECT) {
1624 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1625 } else {
1626 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1627 }
1628 } else {
1629 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 mDone = true;
1632 UnlockSim.this.notifyAll();
1633 }
1634 break;
1635 }
1636 }
1637 };
1638 UnlockSim.this.notifyAll();
1639 }
1640 Looper.loop();
1641 }
1642
1643 /*
1644 * Use PIN or PUK to unlock SIM card
1645 *
1646 * If PUK is null, unlock SIM card with PIN
1647 *
1648 * If PUK is not null, unlock SIM card with PUK and set PIN code
1649 */
Wink Saville9de0f752013-10-22 19:04:03 -07001650 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651
1652 while (mHandler == null) {
1653 try {
1654 wait();
1655 } catch (InterruptedException e) {
1656 Thread.currentThread().interrupt();
1657 }
1658 }
1659 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1660
1661 if (puk == null) {
1662 mSimCard.supplyPin(pin, callback);
1663 } else {
1664 mSimCard.supplyPuk(puk, pin, callback);
1665 }
1666
1667 while (!mDone) {
1668 try {
1669 Log.d(LOG_TAG, "wait for done");
1670 wait();
1671 } catch (InterruptedException e) {
1672 // Restore the interrupted status
1673 Thread.currentThread().interrupt();
1674 }
1675 }
1676 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001677 int[] resultArray = new int[2];
1678 resultArray[0] = mResult;
1679 resultArray[1] = mRetryCount;
1680 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 }
1682 }
1683
1684 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001685 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001686
1687 }
1688
Wink Savilleb564aae2014-10-23 10:18:09 -07001689 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 // No permission check needed here: this call is harmless, and it's
1691 // needed for the ServiceState.requestStateUpdate() call (which is
1692 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001693 final long identity = Binder.clearCallingIdentity();
1694 try {
1695 final Phone phone = getPhone(subId);
1696 if (phone != null) {
1697 phone.updateServiceLocation();
1698 }
1699 } finally {
1700 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 }
1703
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001704 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001705 @Override
1706 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001707 return isRadioOnWithFeature(callingPackage, null);
1708 }
1709
1710
1711 @Override
1712 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1713 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1714 callingFeatureId);
1715 }
1716
1717 @Deprecated
1718 @Override
1719 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1720 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001721 }
1722
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001723 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001724 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1725 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001727 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001728 return false;
1729 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001730
1731 final long identity = Binder.clearCallingIdentity();
1732 try {
1733 return isRadioOnForSubscriber(subId);
1734 } finally {
1735 Binder.restoreCallingIdentity(identity);
1736 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001737 }
1738
1739 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001740 final long identity = Binder.clearCallingIdentity();
1741 try {
1742 final Phone phone = getPhone(subId);
1743 if (phone != null) {
1744 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1745 } else {
1746 return false;
1747 }
1748 } finally {
1749 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 }
1752
1753 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001754 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 }
Wink Saville36469e72014-06-11 15:17:00 -07001756
Wink Savilleb564aae2014-10-23 10:18:09 -07001757 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001759
1760 final long identity = Binder.clearCallingIdentity();
1761 try {
1762 final Phone phone = getPhone(subId);
1763 if (phone != null) {
1764 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1765 }
1766 } finally {
1767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 }
Wink Saville36469e72014-06-11 15:17:00 -07001769 }
1770
1771 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001772 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001773 }
1774
Wink Savilleb564aae2014-10-23 10:18:09 -07001775 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001776 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001777
1778 final long identity = Binder.clearCallingIdentity();
1779 try {
1780 final Phone phone = getPhone(subId);
1781 if (phone == null) {
1782 return false;
1783 }
1784 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1785 toggleRadioOnOffForSubscriber(subId);
1786 }
1787 return true;
1788 } finally {
1789 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001790 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 }
Wink Saville36469e72014-06-11 15:17:00 -07001792
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001793 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001794 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001795 /*
1796 * If any of the Radios are available, it will need to be
1797 * shutdown. So return true if any Radio is available.
1798 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799 final long identity = Binder.clearCallingIdentity();
1800 try {
1801 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1802 Phone phone = PhoneFactory.getPhone(i);
1803 if (phone != null && phone.isRadioAvailable()) return true;
1804 }
1805 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1806 return false;
1807 } finally {
1808 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001809 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001810 }
1811
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001812 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001813 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001814 enforceModifyPermission();
1815
1816 final long identity = Binder.clearCallingIdentity();
1817 try {
1818 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1819 logv("Shutting down Phone " + i);
1820 shutdownRadioUsingPhoneId(i);
1821 }
1822 } finally {
1823 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001824 }
1825 }
1826
1827 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001828 Phone phone = PhoneFactory.getPhone(phoneId);
1829 if (phone != null && phone.isRadioAvailable()) {
1830 phone.shutdownRadio();
1831 }
1832 }
1833
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001834 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001835 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001836
1837 final long identity = Binder.clearCallingIdentity();
1838 try {
1839 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1840 if (defaultPhone != null) {
1841 defaultPhone.setRadioPower(turnOn);
1842 return true;
1843 } else {
1844 loge("There's no default phone.");
1845 return false;
1846 }
1847 } finally {
1848 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001849 }
Wink Saville36469e72014-06-11 15:17:00 -07001850 }
1851
Wink Savilleb564aae2014-10-23 10:18:09 -07001852 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001854
1855 final long identity = Binder.clearCallingIdentity();
1856 try {
1857 final Phone phone = getPhone(subId);
1858 if (phone != null) {
1859 phone.setRadioPower(turnOn);
1860 return true;
1861 } else {
1862 return false;
1863 }
1864 } finally {
1865 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001866 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 }
1868
Wink Saville36469e72014-06-11 15:17:00 -07001869 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001870 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 public boolean enableDataConnectivity() {
1872 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001873
1874 final long identity = Binder.clearCallingIdentity();
1875 try {
1876 int subId = mSubscriptionController.getDefaultDataSubId();
1877 final Phone phone = getPhone(subId);
1878 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001879 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001880 return true;
1881 } else {
1882 return false;
1883 }
1884 } finally {
1885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 }
1888
Wink Saville36469e72014-06-11 15:17:00 -07001889 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001890 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 public boolean disableDataConnectivity() {
1892 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001893
1894 final long identity = Binder.clearCallingIdentity();
1895 try {
1896 int subId = mSubscriptionController.getDefaultDataSubId();
1897 final Phone phone = getPhone(subId);
1898 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001899 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001900 return true;
1901 } else {
1902 return false;
1903 }
1904 } finally {
1905 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 }
1908
Sanket Padawe356d7632015-06-22 14:03:32 -07001909 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001910 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001911 final long identity = Binder.clearCallingIdentity();
1912 try {
1913 final Phone phone = getPhone(subId);
1914 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001915 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001916 } else {
1917 return false;
1918 }
1919 } finally {
1920 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001921 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 }
1923
1924 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001925 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001926 }
1927
pkanwarae03a6b2016-11-06 20:37:09 -08001928 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001929 enforceCallPermission();
1930
1931 final long identity = Binder.clearCallingIdentity();
1932 try {
1933 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1934 return;
1935 }
1936 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1937 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1938 } finally {
1939 Binder.restoreCallingIdentity(identity);
1940 }
pkanwar32d516d2016-10-14 19:37:38 -07001941 };
1942
Wink Savilleb564aae2014-10-23 10:18:09 -07001943 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001945
1946 final long identity = Binder.clearCallingIdentity();
1947 try {
1948 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1949 return false;
1950 }
1951 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1952 } finally {
1953 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 }
1956
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001958 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001959 }
1960
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001961 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001962 final long identity = Binder.clearCallingIdentity();
1963 try {
1964 Phone phone = PhoneFactory.getPhone(slotIndex);
1965 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1966 PhoneConstantConversions.convertCallState(phone.getState());
1967 } finally {
1968 Binder.restoreCallingIdentity(identity);
1969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 }
1971
Sanket Padawe356d7632015-06-22 14:03:32 -07001972 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001973 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001974 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1975 }
1976
1977 @Override
1978 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001979 final long identity = Binder.clearCallingIdentity();
1980 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001981 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001982 if (phone != null) {
1983 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1984 } else {
1985 return PhoneConstantConversions.convertDataState(
1986 PhoneConstants.DataState.DISCONNECTED);
1987 }
1988 } finally {
1989 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 }
1992
Sanket Padawe356d7632015-06-22 14:03:32 -07001993 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001994 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001995 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1996 }
1997
1998 @Override
1999 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000 final long identity = Binder.clearCallingIdentity();
2001 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002002 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002003 if (phone != null) {
2004 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2005 } else {
2006 return TelephonyManager.DATA_ACTIVITY_NONE;
2007 }
2008 } finally {
2009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 }
2012
2013 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002014 public Bundle getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002015 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002016 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002017
2018 LocationAccessPolicy.LocationPermissionResult locationResult =
2019 LocationAccessPolicy.checkLocationPermission(mApp,
2020 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2021 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002022 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002023 .setCallingPid(Binder.getCallingPid())
2024 .setCallingUid(Binder.getCallingUid())
2025 .setMethod("getCellLocation")
2026 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2027 .build());
2028 switch (locationResult) {
2029 case DENIED_HARD:
2030 throw new SecurityException("Not allowed to access cell location");
2031 case DENIED_SOFT:
2032 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 }
2034
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002035 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002036 final long identity = Binder.clearCallingIdentity();
2037 try {
2038 if (DBG_LOC) log("getCellLocation: is active user");
2039 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002040 int subId = mSubscriptionController.getDefaultDataSubId();
2041 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2042 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002043 return data;
2044 } finally {
2045 Binder.restoreCallingIdentity(identity);
2046 }
Svetoslav64fad262015-04-14 14:35:21 -07002047 }
2048
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002050 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2051 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002052 if (!TextUtils.isEmpty(callingPackage)) {
2053 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002054 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2055 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002056 return "";
2057 }
2058 }
2059
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002060 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2061 // registered cell info, so return a NULL country instead.
2062 final long identity = Binder.clearCallingIdentity();
2063 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002064 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2065 // Get default phone in this case.
2066 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2067 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002068 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002069 // Todo: fix this when we can get the actual cellular network info when the device
2070 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002071 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002072 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2073 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002074 return "";
2075 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002076 Phone phone = PhoneFactory.getPhone(phoneId);
2077 if (phone != null) {
2078 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002079 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080 if (sst != null) {
2081 LocaleTracker lt = sst.getLocaleTracker();
2082 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002083 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2084 return lt.getCurrentCountry();
2085 } else if (emergencyNumberTracker != null) {
2086 return emergencyNumberTracker.getEmergencyCountryIso();
2087 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002088 }
2089 }
2090 }
2091 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002092 } finally {
2093 Binder.restoreCallingIdentity(identity);
2094 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002095 }
2096
2097 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002099 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002100 }
2101
Sanket Padawe356d7632015-06-22 14:03:32 -07002102 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002103 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 mApp.enforceCallingOrSelfPermission(
2105 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002106
2107 final long identity = Binder.clearCallingIdentity();
2108 try {
2109 final Phone phone = getPhone(subId);
2110 if (phone != null) {
2111 phone.enableLocationUpdates();
2112 }
2113 } finally {
2114 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002115 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 }
2117
2118 @Override
2119 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002120 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002121 }
2122
Sanket Padawe356d7632015-06-22 14:03:32 -07002123 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002124 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002125 mApp.enforceCallingOrSelfPermission(
2126 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002127
2128 final long identity = Binder.clearCallingIdentity();
2129 try {
2130 final Phone phone = getPhone(subId);
2131 if (phone != null) {
2132 phone.disableLocationUpdates();
2133 }
2134 } finally {
2135 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002136 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137 }
2138
Nathan Harold31d7ff32018-10-15 20:20:30 -07002139 /**
2140 * Returns the target SDK version number for a given package name.
2141 *
Nathan Haroldec184742019-07-10 17:04:16 -07002142 * This call MUST be invoked before clearing the calling UID.
2143 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002144 * @return target SDK if the package is found or INT_MAX.
2145 */
2146 private int getTargetSdk(String packageName) {
2147 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002148 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002149 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002150 if (ai != null) return ai.targetSdkVersion;
2151 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002152 loge("Failed to get package info for pkg="
2153 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002154 }
2155 return Integer.MAX_VALUE;
2156 }
2157
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 @Override
2159 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002160 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2161 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002162 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002163 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2164 throw new SecurityException(
2165 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2166 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002167
Jordan Liu1617b712019-07-10 15:06:26 -07002168 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2170 return null;
2171 }
Svetoslav64fad262015-04-14 14:35:21 -07002172
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002173 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002175 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002176 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177
Nathan Haroldf180aac2018-06-01 18:43:55 -07002178 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2179 for (CellInfo ci : info) {
2180 if (ci instanceof CellInfoGsm) {
2181 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2182 } else if (ci instanceof CellInfoWcdma) {
2183 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2184 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002186 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002187 }
2188
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002189 private List<CellInfo> getCachedCellInfo() {
2190 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2191 for (Phone phone : PhoneFactory.getPhones()) {
2192 List<CellInfo> info = phone.getAllCellInfo();
2193 if (info != null) cellInfos.addAll(info);
2194 }
2195 return cellInfos;
2196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197
2198 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002199 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002200 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002201 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002202
2203 LocationAccessPolicy.LocationPermissionResult locationResult =
2204 LocationAccessPolicy.checkLocationPermission(mApp,
2205 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2206 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002207 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002208 .setCallingPid(Binder.getCallingPid())
2209 .setCallingUid(Binder.getCallingUid())
2210 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002211 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002212 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2213 .build());
2214 switch (locationResult) {
2215 case DENIED_HARD:
2216 throw new SecurityException("Not allowed to access cell info");
2217 case DENIED_SOFT:
2218 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 }
2220
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002221 final int targetSdk = getTargetSdk(callingPackage);
2222 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2223 return getCachedCellInfo();
2224 }
2225
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002226 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002227 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002228 final long identity = Binder.clearCallingIdentity();
2229 try {
2230 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2231 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002232 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002233 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002234 if (info != null) cellInfos.addAll(info);
2235 }
2236 return cellInfos;
2237 } finally {
2238 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 }
2240 }
2241
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002242 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002243 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2244 String callingFeatureId) {
2245 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2246 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002247 }
2248
2249 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002250 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2251 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002252 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002253 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002254 }
2255
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002256 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2257 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002258 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002259 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002260
2261 LocationAccessPolicy.LocationPermissionResult locationResult =
2262 LocationAccessPolicy.checkLocationPermission(mApp,
2263 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2264 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002265 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002266 .setCallingPid(Binder.getCallingPid())
2267 .setCallingUid(Binder.getCallingUid())
2268 .setMethod("requestCellInfoUpdate")
2269 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2270 .build());
2271 switch (locationResult) {
2272 case DENIED_HARD:
2273 throw new SecurityException("Not allowed to access cell info");
2274 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002275 try {
2276 cb.onCellInfo(new ArrayList<CellInfo>());
2277 } catch (RemoteException re) {
2278 // Drop without consequences
2279 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002280 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002281 }
2282
Nathan Harolda939a962019-05-09 10:13:47 -07002283
2284 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002285 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2286
2287 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2288 }
2289
2290 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002292 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002293 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002294
2295 final long identity = Binder.clearCallingIdentity();
2296 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002297 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002298 } finally {
2299 Binder.restoreCallingIdentity(identity);
2300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
Shishir Agrawala9f32182016-04-12 12:00:16 -07002303 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002304 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002305 Phone phone = PhoneFactory.getPhone(slotIndex);
2306 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002307 return null;
2308 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002309 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002310 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002311 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002312 return null;
2313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002314
2315 final long identity = Binder.clearCallingIdentity();
2316 try {
2317 return phone.getImei();
2318 } finally {
2319 Binder.restoreCallingIdentity(identity);
2320 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002321 }
2322
2323 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002324 public String getTypeAllocationCodeForSlot(int slotIndex) {
2325 Phone phone = PhoneFactory.getPhone(slotIndex);
2326 String tac = null;
2327 if (phone != null) {
2328 String imei = phone.getImei();
2329 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2330 }
2331 return tac;
2332 }
2333
2334 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002335 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002336 Phone phone = PhoneFactory.getPhone(slotIndex);
2337 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002338 return null;
2339 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002340
Jeff Davidson913390f2018-02-23 17:11:49 -08002341 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002342 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002343 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002344 return null;
2345 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002346
2347 final long identity = Binder.clearCallingIdentity();
2348 try {
2349 return phone.getMeid();
2350 } finally {
2351 Binder.restoreCallingIdentity(identity);
2352 }
Jack Yu2af8d712017-03-15 17:14:14 -07002353 }
2354
2355 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002356 public String getManufacturerCodeForSlot(int slotIndex) {
2357 Phone phone = PhoneFactory.getPhone(slotIndex);
2358 String manufacturerCode = null;
2359 if (phone != null) {
2360 String meid = phone.getMeid();
2361 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2362 }
2363 return manufacturerCode;
2364 }
2365
2366 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002367 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2368 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002369 Phone phone = PhoneFactory.getPhone(slotIndex);
2370 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002371 return null;
2372 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002373 int subId = phone.getSubId();
2374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002375 mApp, subId, callingPackage, callingFeatureId,
2376 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002377 return null;
2378 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002379
2380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 return phone.getDeviceSvn();
2383 } finally {
2384 Binder.restoreCallingIdentity(identity);
2385 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002386 }
2387
fionaxu43304da2017-11-27 22:51:16 -08002388 @Override
2389 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002390 final long identity = Binder.clearCallingIdentity();
2391 try {
2392 final Phone phone = getPhone(subId);
2393 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2394 } finally {
2395 Binder.restoreCallingIdentity(identity);
2396 }
fionaxu43304da2017-11-27 22:51:16 -08002397 }
2398
2399 @Override
2400 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002401 final long identity = Binder.clearCallingIdentity();
2402 try {
2403 final Phone phone = getPhone(subId);
2404 return phone == null ? null : phone.getCarrierName();
2405 } finally {
2406 Binder.restoreCallingIdentity(identity);
2407 }
fionaxu43304da2017-11-27 22:51:16 -08002408 }
2409
calvinpanffe225e2018-11-01 19:43:06 +08002410 @Override
chen xu0026ca62019-03-06 15:28:50 -08002411 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002412 final long identity = Binder.clearCallingIdentity();
2413 try {
2414 final Phone phone = getPhone(subId);
2415 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002416 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002417 } finally {
2418 Binder.restoreCallingIdentity(identity);
2419 }
2420 }
2421
2422 @Override
chen xu0026ca62019-03-06 15:28:50 -08002423 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002424 final long identity = Binder.clearCallingIdentity();
2425 try {
2426 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002427 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002428 } finally {
2429 Binder.restoreCallingIdentity(identity);
2430 }
2431 }
2432
chen xu651eec72018-11-11 19:03:44 -08002433 @Override
chen xu864e11c2018-12-06 22:10:03 -08002434 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2435 if (!isSubscriptionMccMnc) {
2436 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2437 }
chen xu651eec72018-11-11 19:03:44 -08002438 final Phone phone = PhoneFactory.getPhone(slotIndex);
2439 if (phone == null) {
2440 return TelephonyManager.UNKNOWN_CARRIER_ID;
2441 }
2442 final long identity = Binder.clearCallingIdentity();
2443 try {
2444 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2445 } finally {
2446 Binder.restoreCallingIdentity(identity);
2447 }
2448 }
2449
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 //
2451 // Internal helper methods.
2452 //
2453
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002454 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2456 *
2457 * @throws SecurityException if the caller does not have the required permission
2458 */
2459 private void enforceModifyPermission() {
2460 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2461 }
2462
Shuo Qian3b6ee772019-11-13 17:43:31 -08002463 private void enforceActiveEmergencySessionPermission() {
2464 mApp.enforceCallingOrSelfPermission(
2465 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2466 }
2467
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 /**
2469 * Make sure the caller has the CALL_PHONE permission.
2470 *
2471 * @throws SecurityException if the caller does not have the required permission
2472 */
2473 private void enforceCallPermission() {
2474 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2475 }
2476
paulhu5a773602019-08-23 19:17:33 +08002477 private void enforceSettingsPermission() {
2478 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002479 }
2480
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 private String createTelUrl(String number) {
2482 if (TextUtils.isEmpty(number)) {
2483 return null;
2484 }
2485
Jake Hambye994d462014-02-03 13:10:13 -08002486 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 }
2488
Ihab Awadf9e92732013-12-05 18:02:52 -08002489 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002490 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2491 }
2492
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002493 private static void logv(String msg) {
2494 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2495 }
2496
Ihab Awadf9e92732013-12-05 18:02:52 -08002497 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2499 }
2500
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002501 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002503 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002504 }
2505
Sanket Padawe356d7632015-06-22 14:03:32 -07002506 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002507 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508 final long identity = Binder.clearCallingIdentity();
2509 try {
2510 final Phone phone = PhoneFactory.getPhone(slotIndex);
2511 if (phone == null) {
2512 return PhoneConstants.PHONE_TYPE_NONE;
2513 } else {
2514 return phone.getPhoneType();
2515 }
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 }
2520
2521 /**
2522 * Returns the CDMA ERI icon index to display
2523 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002524 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002525 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2526 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2527 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002528 }
2529
Sanket Padawe356d7632015-06-22 14:03:32 -07002530 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002531 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2532 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002533 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002534 mApp, subId, callingPackage, callingFeatureId,
2535 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002536 return -1;
2537 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002538
2539 final long identity = Binder.clearCallingIdentity();
2540 try {
2541 final Phone phone = getPhone(subId);
2542 if (phone != null) {
2543 return phone.getCdmaEriIconIndex();
2544 } else {
2545 return -1;
2546 }
2547 } finally {
2548 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002550 }
2551
2552 /**
2553 * Returns the CDMA ERI icon mode,
2554 * 0 - ON
2555 * 1 - FLASHING
2556 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002557 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002558 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2559 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2560 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002561 }
2562
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002564 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2565 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002567 mApp, subId, callingPackage, callingFeatureId,
2568 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002569 return -1;
2570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571
2572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 final Phone phone = getPhone(subId);
2575 if (phone != null) {
2576 return phone.getCdmaEriIconMode();
2577 } else {
2578 return -1;
2579 }
2580 } finally {
2581 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 }
2584
2585 /**
2586 * Returns the CDMA ERI text,
2587 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002588 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002589 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2590 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2591 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002592 }
2593
Sanket Padawe356d7632015-06-22 14:03:32 -07002594 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002595 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2596 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002598 mApp, subId, callingPackage, callingFeatureId,
2599 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002600 return null;
2601 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602
2603 final long identity = Binder.clearCallingIdentity();
2604 try {
2605 final Phone phone = getPhone(subId);
2606 if (phone != null) {
2607 return phone.getCdmaEriText();
2608 } else {
2609 return null;
2610 }
2611 } finally {
2612 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002614 }
2615
2616 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002617 * Returns the CDMA MDN.
2618 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002619 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002620 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2622 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623
2624 final long identity = Binder.clearCallingIdentity();
2625 try {
2626 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002627 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628 return phone.getLine1Number();
2629 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002630 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631 return null;
2632 }
2633 } finally {
2634 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002635 }
2636 }
2637
2638 /**
2639 * Returns the CDMA MIN.
2640 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002641 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002642 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2644 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002645
2646 final long identity = Binder.clearCallingIdentity();
2647 try {
2648 final Phone phone = getPhone(subId);
2649 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2650 return phone.getCdmaMin();
2651 } else {
2652 return null;
2653 }
2654 } finally {
2655 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002656 }
2657 }
2658
Hall Liud892bec2018-11-30 14:51:45 -08002659 @Override
2660 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2661 INumberVerificationCallback callback, String callingPackage) {
2662 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2663 != PERMISSION_GRANTED) {
2664 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2665 }
2666 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2667
2668 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2669 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2670 throw new SecurityException("Calling package must be configured in the device config");
2671 }
2672
2673 if (range == null) {
2674 throw new NullPointerException("Range must be non-null");
2675 }
2676
2677 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002678 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002679
2680 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2681 }
2682
Junda Liuca05d5d2014-08-14 22:36:34 -07002683 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 * Returns true if CDMA provisioning needs to run.
2685 */
2686 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687 final long identity = Binder.clearCallingIdentity();
2688 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002689 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690 } finally {
2691 Binder.restoreCallingIdentity(identity);
2692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 }
2694
2695 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002696 * Sets the voice mail number of a given subId.
2697 */
2698 @Override
2699 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002700 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2701 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2706 new Pair<String, String>(alphaTag, number), new Integer(subId));
2707 return success;
2708 } finally {
2709 Binder.restoreCallingIdentity(identity);
2710 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002711 }
2712
Ta-wei Yen87c49842016-05-13 21:19:52 -07002713 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002714 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2715 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002716 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2717 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002718 if (!TextUtils.equals(callingPackage, systemDialer)) {
2719 throw new SecurityException("caller must be system dialer");
2720 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721
2722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2725 if (phoneAccountHandle == null) {
2726 return null;
2727 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002728 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729 } finally {
2730 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002731 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002732 }
2733
2734 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002735 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2736 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002737 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002739 mApp, subId, callingPackage, callingFeatureId,
2740 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002741 return null;
2742 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002743
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002744 final long identity = Binder.clearCallingIdentity();
2745 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002746 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002747 } finally {
2748 Binder.restoreCallingIdentity(identity);
2749 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002750 }
2751
2752 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002753 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2754 VisualVoicemailSmsFilterSettings settings) {
2755 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756
2757 final long identity = Binder.clearCallingIdentity();
2758 try {
2759 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002760 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002761 } finally {
2762 Binder.restoreCallingIdentity(identity);
2763 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002764 }
2765
2766 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002767 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2768 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769
2770 final long identity = Binder.clearCallingIdentity();
2771 try {
2772 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002773 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774 } finally {
2775 Binder.restoreCallingIdentity(identity);
2776 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002777 }
2778
2779 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002780 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2781 String callingPackage, int subId) {
2782 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783
2784 final long identity = Binder.clearCallingIdentity();
2785 try {
2786 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002787 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788 } finally {
2789 Binder.restoreCallingIdentity(identity);
2790 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002791 }
2792
2793 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002794 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002795 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796
2797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002800 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801 } finally {
2802 Binder.restoreCallingIdentity(identity);
2803 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002804 }
2805
2806 @Override
2807 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2808 String number, int port, String text, PendingIntent sentIntent) {
2809 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002810 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002811 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002812 SmsController smsController = PhoneFactory.getSmsController();
2813 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2814 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002815 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002816
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002817 /**
fionaxu0152e512016-11-14 13:36:14 -08002818 * Sets the voice activation state of a given subId.
2819 */
2820 @Override
2821 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2823 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824
2825 final long identity = Binder.clearCallingIdentity();
2826 try {
2827 final Phone phone = getPhone(subId);
2828 if (phone != null) {
2829 phone.setVoiceActivationState(activationState);
2830 } else {
2831 loge("setVoiceActivationState fails with invalid subId: " + subId);
2832 }
2833 } finally {
2834 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002835 }
2836 }
2837
2838 /**
2839 * Sets the data activation state of a given subId.
2840 */
2841 @Override
2842 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2844 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845
2846 final long identity = Binder.clearCallingIdentity();
2847 try {
2848 final Phone phone = getPhone(subId);
2849 if (phone != null) {
2850 phone.setDataActivationState(activationState);
2851 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002852 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853 }
2854 } finally {
2855 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002856 }
2857 }
2858
2859 /**
2860 * Returns the voice activation state of a given subId.
2861 */
2862 @Override
2863 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002864 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865
fionaxu0152e512016-11-14 13:36:14 -08002866 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 if (phone != null) {
2870 return phone.getVoiceActivationState();
2871 } else {
2872 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2873 }
2874 } finally {
2875 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002876 }
2877 }
2878
2879 /**
2880 * Returns the data activation state of a given subId.
2881 */
2882 @Override
2883 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002884 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885
fionaxu0152e512016-11-14 13:36:14 -08002886 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002887 final long identity = Binder.clearCallingIdentity();
2888 try {
2889 if (phone != null) {
2890 return phone.getDataActivationState();
2891 } else {
2892 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2893 }
2894 } finally {
2895 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002896 }
2897 }
2898
2899 /**
Wink Saville36469e72014-06-11 15:17:00 -07002900 * Returns the unread count of voicemails for a subId
2901 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002902 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002903 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2904 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002906 mApp, subId, callingPackage, callingFeatureId,
2907 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002908 return 0;
2909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 final Phone phone = getPhone(subId);
2913 if (phone != null) {
2914 return phone.getVoiceMessageCount();
2915 } else {
2916 return 0;
2917 }
2918 } finally {
2919 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002921 }
2922
2923 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002924 * returns true, if the device is in a state where both voice and data
2925 * are supported simultaneously. This can change based on location or network condition.
2926 */
2927 @Override
2928 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929 final long identity = Binder.clearCallingIdentity();
2930 try {
2931 final Phone phone = getPhone(subId);
2932 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2933 } finally {
2934 Binder.restoreCallingIdentity(identity);
2935 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002936 }
2937
2938 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002939 * Send the dialer code if called from the current default dialer or the caller has
2940 * carrier privilege.
2941 * @param inputCode The dialer code to send
2942 */
2943 @Override
2944 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002945 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002946 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002947 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2948 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002949 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002950 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002951 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002953
2954 final long identity = Binder.clearCallingIdentity();
2955 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002956 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957 } finally {
2958 Binder.restoreCallingIdentity(identity);
2959 }
fionaxu235cc5e2017-03-06 22:25:57 -08002960 }
2961
Pengquan Menga1bb6272018-09-06 09:59:22 -07002962 @Override
2963 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002964 if (!isActiveSubscription(subId)) {
2965 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2966 }
2967
Pengquan Menga1bb6272018-09-06 09:59:22 -07002968 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2969 }
2970
Brad Ebinger35c841c2018-10-01 10:40:55 -07002971 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002972 public boolean isInEmergencySmsMode() {
2973 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 for (Phone phone : PhoneFactory.getPhones()) {
2977 if (phone.isInEmergencySmsMode()) {
2978 return true;
2979 }
2980 }
2981 } finally {
2982 Binder.restoreCallingIdentity(identity);
2983 }
2984 return false;
2985 }
2986
2987 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002988 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2989 throws RemoteException {
2990 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002991 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2992 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2993 "IMS not available on device.");
2994 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002995 final long token = Binder.clearCallingIdentity();
2996 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002997 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002998 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002999 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003000 } catch (ImsException e) {
3001 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003002 } finally {
3003 Binder.restoreCallingIdentity(token);
3004 }
3005 }
3006
3007 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003008 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
3009 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003010 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3011 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3012 }
Meng Wangafbc5852019-09-19 17:37:13 -07003013 final long token = Binder.clearCallingIdentity();
3014 try {
3015 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3016 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3017 .removeRegistrationCallbackForSubscription(c, subId);
3018 } catch (ImsException e) {
3019 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3020 + "is inactive, ignoring unregister.");
3021 // If the subscription is no longer active, just return, since the callback
3022 // will already have been removed internally.
3023 } finally {
3024 Binder.restoreCallingIdentity(token);
3025 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003026 }
3027
Brad Ebingera34a6c22019-10-22 17:36:18 -07003028 /**
3029 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3030 */
3031 @Override
3032 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3033 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3034 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3035 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3036 "IMS not available on device.");
3037 }
3038 final long token = Binder.clearCallingIdentity();
3039 try {
3040 Phone phone = getPhone(subId);
3041 if (phone == null) {
3042 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3043 + subId + "'");
3044 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3045 }
3046 phone.getImsRegistrationState(regState -> {
3047 try {
3048 consumer.accept((regState == null)
3049 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3050 } catch (RemoteException e) {
3051 // Ignore if the remote process is no longer available to call back.
3052 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3053 }
3054 });
3055 } finally {
3056 Binder.restoreCallingIdentity(token);
3057 }
3058 }
3059
3060 /**
3061 * Get the transport type for the IMS service registration state.
3062 */
3063 @Override
3064 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3065 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3066 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3067 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3068 "IMS not available on device.");
3069 }
3070 final long token = Binder.clearCallingIdentity();
3071 try {
3072 Phone phone = getPhone(subId);
3073 if (phone == null) {
3074 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3075 + subId + "'");
3076 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3077 }
3078 phone.getImsRegistrationTech(regTech -> {
3079 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3080 int regTechConverted = (regTech == null)
3081 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3082 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3083 regTechConverted);
3084 try {
3085 consumer.accept(regTechConverted);
3086 } catch (RemoteException e) {
3087 // Ignore if the remote process is no longer available to call back.
3088 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3089 }
3090 });
3091 } finally {
3092 Binder.restoreCallingIdentity(token);
3093 }
3094 }
3095
Brad Ebinger35c841c2018-10-01 10:40:55 -07003096 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003097 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3098 throws RemoteException {
3099 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003100 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3101 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3102 "IMS not available on device.");
3103 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003104 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3105 final long token = Binder.clearCallingIdentity();
3106 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003107 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003109 } catch (ImsException e) {
3110 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003111 } finally {
3112 Binder.restoreCallingIdentity(token);
3113 }
3114 }
3115
3116 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003117 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3118 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003119 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3120 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3121 }
Meng Wangafbc5852019-09-19 17:37:13 -07003122
3123 final long token = Binder.clearCallingIdentity();
3124 try {
3125 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3126 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003127 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003128 } catch (ImsException e) {
3129 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3130 + "is inactive, ignoring unregister.");
3131 // If the subscription is no longer active, just return, since the callback
3132 // will already have been removed internally.
3133 } finally {
3134 Binder.restoreCallingIdentity(token);
3135 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003136 }
3137
3138 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003139 public boolean isCapable(int subId, int capability, int regTech) {
3140 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003141 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3142 final long token = Binder.clearCallingIdentity();
3143 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003144 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003146 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003147 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3148 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003149 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003150 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3151 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003152 } finally {
3153 Binder.restoreCallingIdentity(token);
3154 }
3155 }
3156
3157 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003158 public boolean isAvailable(int subId, int capability, int regTech) {
3159 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003160 final long token = Binder.clearCallingIdentity();
3161 try {
3162 Phone phone = getPhone(subId);
3163 if (phone == null) return false;
3164 return phone.isImsCapabilityAvailable(capability, regTech);
3165 } finally {
3166 Binder.restoreCallingIdentity(token);
3167 }
3168 }
3169
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003170 /**
3171 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3172 * subscription.
3173 * @param subId The subscription to use to check the configuration.
3174 * @param callback The callback that will be used to send the result.
3175 * @param capability The MmTelFeature capability that will be used to send the result.
3176 * @param transportType The transport type of the MmTelFeature capability.
3177 */
3178 @Override
3179 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3180 int transportType) {
3181 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3182 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3183 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3184 "IMS not available on device.");
3185 }
3186 final long token = Binder.clearCallingIdentity();
3187 try {
3188 int slotId = getSlotIndex(subId);
3189 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3190 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3191 + subId + "'");
3192 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3193 }
3194 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3195 transportType, aBoolean -> {
3196 try {
3197 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3198 } catch (RemoteException e) {
3199 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3200 + "running. Ignore");
3201 }
3202 });
3203 } finally {
3204 Binder.restoreCallingIdentity(token);
3205 }
3206 }
3207
Brad Ebinger35c841c2018-10-01 10:40:55 -07003208 @Override
3209 public boolean isAdvancedCallingSettingEnabled(int subId) {
3210 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3211 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3212 final long token = Binder.clearCallingIdentity();
3213 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003214 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003215 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
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(token);
3220 }
3221 }
3222
3223 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003224 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003226 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003230 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003231 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003232 } catch (ImsException e) {
3233 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003234 } finally {
3235 Binder.restoreCallingIdentity(identity);
3236 }
3237 }
3238
3239 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003240 public boolean isVtSettingEnabled(int subId) {
3241 enforceReadPrivilegedPermission("isVtSettingEnabled");
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.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003245 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3246 } 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
Brad Ebinger1c162042019-02-21 14:49:10 -08003254 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003256 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003257 final long identity = Binder.clearCallingIdentity();
3258 try {
3259 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003260 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
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
3269 public boolean isVoWiFiSettingEnabled(int subId) {
3270 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3271 final long identity = Binder.clearCallingIdentity();
3272 try {
3273 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003274 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003275 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003276 } catch (ImsException e) {
3277 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 } finally {
3279 Binder.restoreCallingIdentity(identity);
3280 }
3281 }
3282
3283 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003284 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003286 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003287 final long identity = Binder.clearCallingIdentity();
3288 try {
3289 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003290 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003291 } catch (ImsException e) {
3292 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003293 } finally {
3294 Binder.restoreCallingIdentity(identity);
3295 }
3296 }
3297
3298 @Override
3299 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3300 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3301 final long identity = Binder.clearCallingIdentity();
3302 try {
3303 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003304 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003305 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003306 } catch (ImsException e) {
3307 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003308 } finally {
3309 Binder.restoreCallingIdentity(identity);
3310 }
3311 }
3312
3313 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003314 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003316 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003317 final long identity = Binder.clearCallingIdentity();
3318 try {
3319 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003320 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003321 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003322 } catch (ImsException e) {
3323 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003324 } finally {
3325 Binder.restoreCallingIdentity(identity);
3326 }
3327 }
3328
3329 @Override
3330 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3332 "setVoWiFiNonPersistent");
3333 final long identity = Binder.clearCallingIdentity();
3334 try {
3335 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003336 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003337 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003338 } catch (ImsException e) {
3339 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
3343 }
3344
3345 @Override
3346 public int getVoWiFiModeSetting(int subId) {
3347 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003351 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003352 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003353 } catch (ImsException e) {
3354 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003355 } finally {
3356 Binder.restoreCallingIdentity(identity);
3357 }
3358 }
3359
3360 @Override
3361 public void setVoWiFiModeSetting(int subId, int mode) {
3362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3363 "setVoWiFiModeSetting");
3364 final long identity = Binder.clearCallingIdentity();
3365 try {
3366 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003367 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003368 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003369 } catch (ImsException e) {
3370 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003371 } finally {
3372 Binder.restoreCallingIdentity(identity);
3373 }
3374 }
3375
3376 @Override
3377 public int getVoWiFiRoamingModeSetting(int subId) {
3378 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003382 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003384 } catch (ImsException e) {
3385 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003386 } finally {
3387 Binder.restoreCallingIdentity(identity);
3388 }
3389 }
3390
3391 @Override
3392 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3394 "setVoWiFiRoamingModeSetting");
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,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003399 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003400 } catch (ImsException e) {
3401 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003402 } finally {
3403 Binder.restoreCallingIdentity(identity);
3404 }
3405 }
3406
3407 @Override
3408 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3410 "setRttCapabilityEnabled");
3411 final long identity = Binder.clearCallingIdentity();
3412 try {
3413 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003414 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3415 } catch (ImsException e) {
3416 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003417 } finally {
3418 Binder.restoreCallingIdentity(identity);
3419 }
3420 }
3421
3422 @Override
3423 public boolean isTtyOverVolteEnabled(int subId) {
3424 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3425 final long identity = Binder.clearCallingIdentity();
3426 try {
3427 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003428 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003429 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003430 } catch (ImsException e) {
3431 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003432 } finally {
3433 Binder.restoreCallingIdentity(identity);
3434 }
3435 }
3436
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003437 @Override
3438 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3439 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3440 final long identity = Binder.clearCallingIdentity();
3441 try {
3442 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003443 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003444 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003445 } catch (ImsException e) {
3446 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003447 } finally {
3448 Binder.restoreCallingIdentity(identity);
3449 }
3450 }
3451
3452 @Override
3453 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3454 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3455 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003456 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3457 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3458 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003459 try {
3460 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003461 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003462 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003463 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003464 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3465 + "is inactive, ignoring unregister.");
3466 // If the subscription is no longer active, just return, since the callback will already
3467 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003468 } finally {
3469 Binder.restoreCallingIdentity(identity);
3470 }
3471 }
3472
3473 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003474 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3475 boolean isProvisioned) {
3476 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3477 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3478 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3479 }
3480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3481 "setProvisioningStatusForCapability");
3482 final long identity = Binder.clearCallingIdentity();
3483 try {
3484 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3485 Phone phone = getPhone(subId);
3486 if (phone == null) {
3487 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3488 + subId);
3489 return;
3490 }
3491 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3492 return;
3493 }
3494
3495 // this capability requires provisioning, route to the correct API.
3496 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3497 switch (capability) {
3498 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3499 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3500 ims.setVolteProvisioned(isProvisioned);
3501 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3502 ims.setWfcProvisioned(isProvisioned);
3503 }
3504 break;
3505 }
3506 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3507 // There is currently no difference in VT provisioning type.
3508 ims.setVtProvisioned(isProvisioned);
3509 break;
3510 }
3511 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3512 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3513 // change the capability of the feature instead if needed.
3514 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3515 == isProvisioned) {
3516 // No change in provisioning.
3517 return;
3518 }
3519 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3520 try {
3521 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003522 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003523 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3524 + ", Exception" + e.getMessage());
3525 }
3526 break;
3527 }
3528 default: {
3529 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3530 + capability + "', which does not require provisioning.");
3531 }
3532 }
3533
3534 } finally {
3535 Binder.restoreCallingIdentity(identity);
3536 }
3537 }
3538
3539 @Override
3540 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3541 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3542 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3543 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3544 }
3545 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3549 Phone phone = getPhone(subId);
3550 if (phone == null) {
3551 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3552 + subId);
3553 // We will fail with "true" as the provisioning status because this is the default
3554 // if we do not require provisioning.
3555 return true;
3556 }
3557
3558 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3559 return true;
3560 }
3561
3562 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3563 switch (capability) {
3564 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3565 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3566 return ims.isVolteProvisionedOnDevice();
3567 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3568 return ims.isWfcProvisionedOnDevice();
3569 }
3570 // This should never happen, since we are checking tech above to make sure it
3571 // is either LTE or IWLAN.
3572 throw new IllegalArgumentException("Invalid radio technology for voice "
3573 + "capability.");
3574 }
3575 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3576 // There is currently no difference in VT provisioning type.
3577 return ims.isVtProvisionedOnDevice();
3578 }
3579 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3580 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3581 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3582 }
3583 default: {
3584 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3585 + capability + "', which does not require provisioning.");
3586 }
3587 }
3588
3589 } finally {
3590 Binder.restoreCallingIdentity(identity);
3591 }
3592 }
3593
3594 @Override
3595 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3596 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3597 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3598 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3599 }
3600 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3601 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3602 return (provisionedBits & capability) > 0;
3603 }
3604
3605 @Override
3606 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3607 boolean isProvisioned) {
3608 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3609 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3610 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3611 }
3612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3613 "setProvisioningStatusForCapability");
3614 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3615 // If the current provisioning status for capability already matches isProvisioned,
3616 // do nothing.
3617 if (((provisionedBits & capability) > 0) == isProvisioned) {
3618 return;
3619 }
3620 if (isProvisioned) {
3621 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3622 } else {
3623 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3624 }
3625 }
3626
3627 /**
3628 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3629 * technology. The bitfield should mirror the bitfield defined by
3630 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3631 */
3632 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3633 String key = getMmTelProvisioningKey(subId, tech);
3634 // Default is no capabilities are provisioned.
3635 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3636 }
3637
3638 /**
3639 * Sets the MmTel capability provisioning bitfield (defined by
3640 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3641 * technology specified.
3642 *
3643 * Note: This is a synchronous command and should not be called on UI thread.
3644 */
3645 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3646 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3647 String key = getMmTelProvisioningKey(subId, tech);
3648 editor.putInt(key, newField);
3649 editor.commit();
3650 }
3651
3652 private static String getMmTelProvisioningKey(int subId, int tech) {
3653 // resulting key is provision_ims_mmtel_{subId}_{tech}
3654 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3655 }
3656
3657 /**
3658 * Query CarrierConfig to see if the specified capability requires provisioning for the
3659 * carrier associated with the subscription id.
3660 */
3661 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3662 int capability) {
3663 CarrierConfigManager configManager = new CarrierConfigManager(context);
3664 PersistableBundle c = configManager.getConfigForSubId(subId);
3665 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003666 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003667 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3668 false);
3669 boolean requireVoiceVtProvisioning = c.getBoolean(
3670 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3671
3672 // First check to make sure that the capability requires provisioning.
3673 switch (capability) {
3674 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3675 // intentional fallthrough
3676 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3677 if (requireVoiceVtProvisioning) {
3678 // Voice and Video requires provisioning
3679 return true;
3680 }
3681 break;
3682 }
3683 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3684 if (requireUtProvisioning) {
3685 // UT requires provisioning
3686 return true;
3687 }
3688 break;
3689 }
3690 }
3691 return false;
3692 }
3693
3694 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003695 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003696 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3697 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3698 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003699 enforceReadPrivilegedPermission("getImsProvisioningInt");
3700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003703 int slotId = getSlotIndex(subId);
3704 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3705 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3706 + subId + "' for key:" + key);
3707 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3708 }
3709 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003710 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003711 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3712 + subId + "' for key:" + key);
3713 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003714 } finally {
3715 Binder.restoreCallingIdentity(identity);
3716 }
3717 }
3718
3719 @Override
3720 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003721 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3722 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3723 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003724 enforceReadPrivilegedPermission("getImsProvisioningString");
3725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003728 int slotId = getSlotIndex(subId);
3729 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3730 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3731 + subId + "' for key:" + key);
3732 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3733 }
3734 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003735 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003736 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3737 + subId + "' for key:" + key);
3738 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003739 } finally {
3740 Binder.restoreCallingIdentity(identity);
3741 }
3742 }
3743
3744 @Override
3745 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003746 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3747 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3748 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3750 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003754 int slotId = getSlotIndex(subId);
3755 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3756 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3757 + subId + "' for key:" + key);
3758 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3759 }
3760 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003761 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003762 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3763 + "' for key:" + key);
3764 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003765 } finally {
3766 Binder.restoreCallingIdentity(identity);
3767 }
3768 }
3769
3770 @Override
3771 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003772 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3773 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3774 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3776 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003777 final long identity = Binder.clearCallingIdentity();
3778 try {
3779 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003780 int slotId = getSlotIndex(subId);
3781 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3782 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3783 + subId + "' for key:" + key);
3784 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3785 }
3786 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003787 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003788 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3789 + "' for key:" + key);
3790 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003791 } finally {
3792 Binder.restoreCallingIdentity(identity);
3793 }
3794 }
3795
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003796 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003797 int slotId = SubscriptionManager.getSlotIndex(subId);
3798 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003799 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3800 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003801 }
3802 return slotId;
3803 }
3804
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003805 private int getSlotIndex(int subId) {
3806 int slotId = SubscriptionManager.getSlotIndex(subId);
3807 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3808 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3809 }
3810 return slotId;
3811 }
3812
Wink Saville36469e72014-06-11 15:17:00 -07003813 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003814 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003815 */
3816 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003817 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3818 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003819 final int targetSdk = getTargetSdk(callingPackage);
3820 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003821 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003822 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003823 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003824 mApp, subId, callingPackage, callingFeatureId,
3825 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003826 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3827 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003829 final long identity = Binder.clearCallingIdentity();
3830 try {
3831 final Phone phone = getPhone(subId);
3832 if (phone != null) {
3833 return phone.getServiceState().getDataNetworkType();
3834 } else {
3835 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3836 }
3837 } finally {
3838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003840 }
3841
3842 /**
3843 * Returns the data network type
3844 */
3845 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003846 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3847 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3848 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003849 }
3850
3851 /**
3852 * Returns the data network type for a subId
3853 */
3854 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003855 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3856 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003857 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003858 mApp, subId, callingPackage, callingFeatureId,
3859 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003860 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3861 }
3862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003863 final long identity = Binder.clearCallingIdentity();
3864 try {
3865 final Phone phone = getPhone(subId);
3866 if (phone != null) {
3867 return phone.getServiceState().getDataNetworkType();
3868 } else {
3869 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3870 }
3871 } finally {
3872 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003874 }
3875
3876 /**
Wink Saville36469e72014-06-11 15:17:00 -07003877 * Returns the Voice network type for a subId
3878 */
3879 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003880 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3881 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003882 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003883 mApp, subId, callingPackage, callingFeatureId,
3884 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003885 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3886 }
3887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003888 final long identity = Binder.clearCallingIdentity();
3889 try {
3890 final Phone phone = getPhone(subId);
3891 if (phone != null) {
3892 return phone.getServiceState().getVoiceNetworkType();
3893 } else {
3894 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3895 }
3896 } finally {
3897 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003898 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003899 }
3900
3901 /**
3902 * @return true if a ICC card is present
3903 */
3904 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003905 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003906 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3907 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003908 }
3909
3910 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003911 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003912 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003913 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003914 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003915 final long identity = Binder.clearCallingIdentity();
3916 try {
3917 final Phone phone = PhoneFactory.getPhone(slotIndex);
3918 if (phone != null) {
3919 return phone.getIccCard().hasIccCard();
3920 } else {
3921 return false;
3922 }
3923 } finally {
3924 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003925 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003926 }
3927
3928 /**
3929 * Return if the current radio is LTE on CDMA. This
3930 * is a tri-state return value as for a period of time
3931 * the mode may be unknown.
3932 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003933 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003934 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003935 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003936 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003937 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003938 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3939 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3940 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003941 }
3942
Sanket Padawe356d7632015-06-22 14:03:32 -07003943 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003944 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3945 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003946 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003947 mApp, subId, callingPackage, callingFeatureId,
3948 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003949 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3950 }
3951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 final Phone phone = getPhone(subId);
3955 if (phone == null) {
3956 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3957 } else {
3958 return phone.getLteOnCdmaMode();
3959 }
3960 } finally {
3961 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003962 }
Wink Saville36469e72014-06-11 15:17:00 -07003963 }
3964
Wink Saville36469e72014-06-11 15:17:00 -07003965 /**
3966 * {@hide}
3967 * Returns Default subId, 0 in the case of single standby.
3968 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003969 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003970 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003971 }
3972
Shishir Agrawala9f32182016-04-12 12:00:16 -07003973 private int getSlotForDefaultSubscription() {
3974 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3975 }
3976
Wink Savilleb564aae2014-10-23 10:18:09 -07003977 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003978 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003979 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003980
Pengquan Menge92a50d2018-09-21 15:54:48 -07003981 private boolean isActiveSubscription(int subId) {
3982 return mSubscriptionController.isActiveSubId(subId);
3983 }
3984
Ihab Awadf2177b72013-11-25 13:33:23 -08003985 /**
3986 * @see android.telephony.TelephonyManager.WifiCallingChoices
3987 */
3988 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003989 final long identity = Binder.clearCallingIdentity();
3990 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003991 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003992 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3993 getWhenToMakeWifiCallsDefaultPreference());
3994 } finally {
3995 Binder.restoreCallingIdentity(identity);
3996 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003997 }
3998
3999 /**
4000 * @see android.telephony.TelephonyManager.WifiCallingChoices
4001 */
4002 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004003 final long identity = Binder.clearCallingIdentity();
4004 try {
4005 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004006 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4008 } finally {
4009 Binder.restoreCallingIdentity(identity);
4010 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004011 }
4012
Sailesh Nepald1e68152013-12-12 19:08:02 -08004013 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004014 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004015 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004016 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004017
Jordan Liu4c733742019-02-28 12:03:40 -08004018 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4019 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4020 if (phoneId == -1) {
4021 throw new IllegalArgumentException("Given slot index: " + slotIndex
4022 + " does not correspond to an active phone");
4023 }
4024 return PhoneFactory.getPhone(phoneId);
4025 }
4026
Shishir Agrawal566b7612013-10-28 14:41:00 -07004027 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004028 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4029 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4031 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004032 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004033 if (DBG) {
4034 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4035 }
4036 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4037 p2);
4038 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004039
Jordan Liu4c733742019-02-28 12:03:40 -08004040
4041 @Override
4042 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4043 int slotIndex, String callingPackage, String aid, int p2) {
4044 enforceModifyPermission();
4045 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4046 if (DBG) {
4047 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4048 }
4049 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4050 callingPackage, aid, p2);
4051 }
4052
4053 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4054 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004055 final long identity = Binder.clearCallingIdentity();
4056 try {
4057 if (TextUtils.equals(ISDR_AID, aid)) {
4058 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004059 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4060 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004061 if (bestComponent == null
4062 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4063 loge("The calling package is not allowed to access ISD-R.");
4064 throw new SecurityException(
4065 "The calling package is not allowed to access ISD-R.");
4066 }
Derek Tan740e1672017-06-27 14:56:27 -07004067 }
Derek Tan740e1672017-06-27 14:56:27 -07004068
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004069 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004070 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4071 null /* workSource */);
4072 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004073 return response;
4074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004077 }
4078
4079 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004080 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4082 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004083 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4084 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4085 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004086
Jordan Liu4c733742019-02-28 12:03:40 -08004087 @Override
4088 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4089 enforceModifyPermission();
4090 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4091 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4092 channel);
4093 }
4094
4095 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096 final long identity = Binder.clearCallingIdentity();
4097 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004098 if (channel < 0) {
4099 return false;
4100 }
Jordan Liu4c733742019-02-28 12:03:40 -08004101 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4102 null /* workSource */);
4103 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104 return success;
4105 } finally {
4106 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004107 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004108 }
4109
4110 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004111 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004112 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4114 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004115 if (DBG) {
4116 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4117 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4118 + p3 + " data=" + data);
4119 }
4120 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4121 command, p1, p2, p3, data);
4122 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004123
Jordan Liu4c733742019-02-28 12:03:40 -08004124 @Override
4125 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4126 int command, int p1, int p2, int p3, String data) {
4127 enforceModifyPermission();
4128 if (DBG) {
4129 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4130 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4131 + p3 + " data=" + data);
4132 }
4133 return iccTransmitApduLogicalChannelWithPermission(
4134 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4135 data);
4136 }
4137
4138 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4139 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004140 final long identity = Binder.clearCallingIdentity();
4141 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004142 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143 return "";
4144 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004145
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004146 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004147 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4148 null /* workSource */);
4149 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004150
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004151 // Append the returned status code to the end of the response payload.
4152 String s = Integer.toHexString(
4153 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4154 if (response.payload != null) {
4155 s = IccUtils.bytesToHexString(response.payload) + s;
4156 }
4157 return s;
4158 } finally {
4159 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004160 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004161 }
Jake Hambye994d462014-02-03 13:10:13 -08004162
Evan Charltonc66da362014-05-16 14:06:40 -07004163 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004164 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4165 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4167 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004168 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004169 if (DBG) {
4170 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4171 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4172 }
4173 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4174 cla, command, p1, p2, p3, data);
4175 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004176
Jordan Liu4c733742019-02-28 12:03:40 -08004177 @Override
4178 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4179 int command, int p1, int p2, int p3, String data) {
4180 enforceModifyPermission();
4181 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4182 if (DBG) {
4183 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4184 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4185 + " data=" + data);
4186 }
4187
4188 return iccTransmitApduBasicChannelWithPermission(
4189 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4190 p2, p3, data);
4191 }
4192
4193 // open APDU basic channel assuming the caller has sufficient permissions
4194 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4195 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004196 final long identity = Binder.clearCallingIdentity();
4197 try {
4198 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4199 && TextUtils.equals(ISDR_AID, data)) {
4200 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004201 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4202 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004203 if (bestComponent == null
4204 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4205 loge("The calling package is not allowed to select ISD-R.");
4206 throw new SecurityException(
4207 "The calling package is not allowed to select ISD-R.");
4208 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004209 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004212 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4213 null /* workSource */);
4214 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004216 // Append the returned status code to the end of the response payload.
4217 String s = Integer.toHexString(
4218 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4219 if (response.payload != null) {
4220 s = IccUtils.bytesToHexString(response.payload) + s;
4221 }
4222 return s;
4223 } finally {
4224 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004225 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004226 }
4227
4228 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004229 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004230 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4232 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004234 final long identity = Binder.clearCallingIdentity();
4235 try {
4236 if (DBG) {
4237 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4238 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4239 }
4240
4241 IccIoResult response =
4242 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4243 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4244 subId);
4245
4246 if (DBG) {
4247 log("Exchange SIM_IO [R]" + response);
4248 }
4249
4250 byte[] result = null;
4251 int length = 2;
4252 if (response.payload != null) {
4253 length = 2 + response.payload.length;
4254 result = new byte[length];
4255 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4256 } else {
4257 result = new byte[length];
4258 }
4259
4260 result[length - 1] = (byte) response.sw2;
4261 result[length - 2] = (byte) response.sw1;
4262 return result;
4263 } finally {
4264 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004265 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004266 }
4267
Nathan Haroldb3014052017-01-25 15:57:32 -08004268 /**
4269 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4270 * on a particular subscription
4271 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004272 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4273 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004274 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004275 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004276 return null;
4277 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278
4279 final long identity = Binder.clearCallingIdentity();
4280 try {
4281 if (appType != TelephonyManager.APPTYPE_USIM
4282 && appType != TelephonyManager.APPTYPE_SIM) {
4283 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4284 return null;
4285 }
4286 Object response = sendRequest(
4287 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4288 if (response instanceof String[]) {
4289 return (String[]) response;
4290 }
yincheng zhao2737e882019-09-06 17:06:54 -07004291 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004292 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004293 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004294 } finally {
4295 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004296 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004297 }
4298
yincheng zhao2737e882019-09-06 17:06:54 -07004299 /**
4300 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4301 * subscription.
4302 *
4303 * @param subId the id of the subscription.
4304 * @param appType the uicc app type, must be USIM or SIM.
4305 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4306 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004307 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004308 * @return number of fplmns that is successfully written to the SIM.
4309 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004310 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4311 String callingFeatureId) {
4312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4313 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004314 if (DBG) logv("no permissions for setForbiddenplmns");
4315 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4316 }
4317 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4318 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4319 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4320 }
4321 if (fplmns == null) {
4322 throw new IllegalArgumentException("Fplmn List provided is null");
4323 }
4324 for (String fplmn : fplmns) {
4325 if (!CellIdentity.isValidPlmn(fplmn)) {
4326 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4327 }
4328 }
4329 final long identity = Binder.clearCallingIdentity();
4330 try {
4331 Object response = sendRequest(
4332 CMD_SET_FORBIDDEN_PLMNS,
4333 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4334 subId);
4335 return (int) response;
4336 } finally {
4337 Binder.restoreCallingIdentity(identity);
4338 }
4339 }
4340
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004341 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004342 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4344 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004346 final long identity = Binder.clearCallingIdentity();
4347 try {
4348 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4349 if (response.payload == null) {
4350 return "";
4351 }
Evan Charltonc66da362014-05-16 14:06:40 -07004352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353 // Append the returned status code to the end of the response payload.
4354 String s = Integer.toHexString(
4355 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4356 s = IccUtils.bytesToHexString(response.payload) + s;
4357 return s;
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
Evan Charltonc66da362014-05-16 14:06:40 -07004361 }
4362
Jake Hambye994d462014-02-03 13:10:13 -08004363 /**
4364 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4365 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4366 *
4367 * @param itemID the ID of the item to read
4368 * @return the NV item as a String, or null on error.
4369 */
4370 @Override
4371 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004372 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4374 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375
4376 final long identity = Binder.clearCallingIdentity();
4377 try {
4378 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004379 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004380 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4381 return value;
4382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
Jake Hambye994d462014-02-03 13:10:13 -08004385 }
4386
4387 /**
4388 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4389 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4390 *
4391 * @param itemID the ID of the item to read
4392 * @param itemValue the value to write, as a String
4393 * @return true on success; false on any failure
4394 */
4395 @Override
4396 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004397 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4399 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004400
4401 final long identity = Binder.clearCallingIdentity();
4402 try {
4403 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4404 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004405 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4407 return success;
4408 } finally {
4409 Binder.restoreCallingIdentity(identity);
4410 }
Jake Hambye994d462014-02-03 13:10:13 -08004411 }
4412
4413 /**
4414 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4415 * Used for device configuration by some CDMA operators.
4416 *
4417 * @param preferredRoamingList byte array containing the new PRL
4418 * @return true on success; false on any failure
4419 */
4420 @Override
4421 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4423 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004424
4425 final long identity = Binder.clearCallingIdentity();
4426 try {
4427 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4428 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4429 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4430 return success;
4431 } finally {
4432 Binder.restoreCallingIdentity(identity);
4433 }
Jake Hambye994d462014-02-03 13:10:13 -08004434 }
4435
4436 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004437 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004438 * Used for device configuration by some CDMA operators.
4439 *
chen xu6dac5ab2018-10-26 17:39:23 -07004440 * @param slotIndex - device slot.
4441 *
Jake Hambye994d462014-02-03 13:10:13 -08004442 * @return true on success; false on any failure
4443 */
4444 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004445 public boolean resetModemConfig(int slotIndex) {
4446 Phone phone = PhoneFactory.getPhone(slotIndex);
4447 if (phone != null) {
4448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4449 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450
chen xu6dac5ab2018-10-26 17:39:23 -07004451 final long identity = Binder.clearCallingIdentity();
4452 try {
4453 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4454 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4455 return success;
4456 } finally {
4457 Binder.restoreCallingIdentity(identity);
4458 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004459 }
chen xu6dac5ab2018-10-26 17:39:23 -07004460 return false;
4461 }
4462
4463 /**
4464 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4465 *
4466 * @param slotIndex - device slot.
4467 *
4468 * @return true on success; false on any failure
4469 */
4470 @Override
4471 public boolean rebootModem(int slotIndex) {
4472 Phone phone = PhoneFactory.getPhone(slotIndex);
4473 if (phone != null) {
4474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4475 mApp, phone.getSubId(), "rebootModem");
4476
4477 final long identity = Binder.clearCallingIdentity();
4478 try {
4479 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4480 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4481 return success;
4482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
4485 }
4486 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004487 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004488
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004489 public String[] getPcscfAddress(String apnType, String callingPackage,
4490 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004491 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004492 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4493 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004494 return new String[0];
4495 }
4496
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004497 final long identity = Binder.clearCallingIdentity();
4498 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004499 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
Wink Saville36469e72014-06-11 15:17:00 -07004503 }
4504
Brad Ebinger51f743a2017-01-23 13:50:20 -08004505 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004506 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4507 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004508 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004509 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004510 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004511
4512 final long identity = Binder.clearCallingIdentity();
4513 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004514 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004515 // may happen if the device does not support IMS.
4516 return;
4517 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004518 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519 } finally {
4520 Binder.restoreCallingIdentity(identity);
4521 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004522 }
4523
4524 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004525 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4526 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004527 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004528 public void disableIms(int slotId) {
4529 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004530
4531 final long identity = Binder.clearCallingIdentity();
4532 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004533 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004534 // may happen if the device does not support IMS.
4535 return;
4536 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004537 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004538 } finally {
4539 Binder.restoreCallingIdentity(identity);
4540 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004541 }
4542
4543 /**
4544 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4545 * feature or {@link null} if the service is not available. If the feature is available, the
4546 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4547 */
4548 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004549 IImsServiceFeatureCallback callback) {
4550 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004551
4552 final long identity = Binder.clearCallingIdentity();
4553 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004554 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004555 // may happen if the device does not support IMS.
4556 return null;
4557 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004558 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559 } finally {
4560 Binder.restoreCallingIdentity(identity);
4561 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004562 }
4563
4564 /**
4565 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4566 * feature during emergency calling or {@link null} if the service is not available. If the
4567 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4568 * listener for feature updates.
4569 */
4570 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572
4573 final long identity = Binder.clearCallingIdentity();
4574 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004575 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004576 // may happen if the device does not support IMS.
4577 return null;
4578 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004579 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004580 } finally {
4581 Binder.restoreCallingIdentity(identity);
4582 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004583 }
4584
Brad Ebinger5f64b052017-12-14 14:26:15 -08004585 /**
4586 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004587 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004588 */
4589 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4590 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591
4592 final long identity = Binder.clearCallingIdentity();
4593 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004594 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004595 // may happen if the device does not support IMS.
4596 return null;
4597 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004598 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004599 } finally {
4600 Binder.restoreCallingIdentity(identity);
4601 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004602 }
4603
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004604 /**
4605 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004606 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004607 */
4608 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4609 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004610
4611 final long identity = Binder.clearCallingIdentity();
4612 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004613 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004614 // may happen if the device does not support IMS.
4615 return null;
4616 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004617 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004618 } finally {
4619 Binder.restoreCallingIdentity(identity);
4620 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004621 }
4622
Brad Ebinger884c07b2018-02-15 16:17:40 -08004623 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004624 * Sets the ImsService Package Name that Telephony will bind to.
4625 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004626 * @param slotIndex the slot ID that the ImsService should bind for.
4627 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004628 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004629 * @param featureTypes An integer array of feature types associated with a packageName.
4630 * @param packageName The name of the package that the current configuration will be replaced
4631 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004632 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004633 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004634 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4635 int[] featureTypes, String packageName) {
4636 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4637 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4639 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004640 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004642 final long identity = Binder.clearCallingIdentity();
4643 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004644 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004645 // may happen if the device does not support IMS.
4646 return false;
4647 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004648 Map<Integer, String> featureConfig = new HashMap<>();
4649 for (int featureType : featureTypes) {
4650 featureConfig.put(featureType, packageName);
4651 }
4652 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4653 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004654 } finally {
4655 Binder.restoreCallingIdentity(identity);
4656 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004657 }
4658
4659 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004660 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004661 *
4662 * @param slotId The slot that the ImsService is associated with.
4663 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4664 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004665 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004666 * @return the package name of the ImsService configuration.
4667 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004668 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4669 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004670 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004671 TelephonyPermissions
4672 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4673 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4674 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004676 final long identity = Binder.clearCallingIdentity();
4677 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004678 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004679 // may happen if the device does not support IMS.
4680 return "";
4681 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004682 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004683 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4684 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685 } finally {
4686 Binder.restoreCallingIdentity(identity);
4687 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004688 }
4689
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004690 /**
4691 * Get the MmTelFeature state associated with the requested subscription id.
4692 * @param subId The subscription that the MmTelFeature is associated with.
4693 * @param callback A callback with an integer containing the
4694 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4695 */
4696 @Override
4697 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4698 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4699 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4700 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4701 "IMS not available on device.");
4702 }
4703 final long token = Binder.clearCallingIdentity();
4704 try {
4705 int slotId = getSlotIndex(subId);
4706 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4707 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4708 + subId + "'");
4709 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4710 }
4711 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4712 try {
4713 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4714 } catch (RemoteException e) {
4715 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4716 + "Ignore");
4717 }
4718 });
4719 } finally {
4720 Binder.restoreCallingIdentity(token);
4721 }
4722 }
4723
Wink Saville36469e72014-06-11 15:17:00 -07004724 public void setImsRegistrationState(boolean registered) {
4725 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004726
4727 final long identity = Binder.clearCallingIdentity();
4728 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004729 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004730 } finally {
4731 Binder.restoreCallingIdentity(identity);
4732 }
Wink Saville36469e72014-06-11 15:17:00 -07004733 }
4734
4735 /**
Stuart Scott54788802015-03-30 13:18:01 -07004736 * Set the network selection mode to automatic.
4737 *
4738 */
4739 @Override
4740 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4742 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004743
Pengquan Menge92a50d2018-09-21 15:54:48 -07004744 if (!isActiveSubscription(subId)) {
4745 return;
4746 }
4747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004748 final long identity = Binder.clearCallingIdentity();
4749 try {
4750 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4751 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
4754 }
Stuart Scott54788802015-03-30 13:18:01 -07004755 }
4756
Pengquan Mengea84e042018-09-20 14:57:26 -07004757 /**
4758 * Ask the radio to connect to the input network and change selection mode to manual.
4759 *
4760 * @param subId the id of the subscription.
4761 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4762 * the operator to attach to.
4763 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4764 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4765 * normal network selection next time.
4766 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004767 */
4768 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004769 public boolean setNetworkSelectionModeManual(
4770 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4772 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004773
4774 if (!isActiveSubscription(subId)) {
4775 return false;
4776 }
4777
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004778 final long identity = Binder.clearCallingIdentity();
4779 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004780 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004781 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004782 if (DBG) {
4783 log("setNetworkSelectionModeManual: subId: " + subId
4784 + " operator: " + operatorInfo);
4785 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004786 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4787 } finally {
4788 Binder.restoreCallingIdentity(identity);
4789 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004790 }
4791
4792 /**
4793 * Scans for available networks.
4794 */
4795 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004796 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4797 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4799 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004800 LocationAccessPolicy.LocationPermissionResult locationResult =
4801 LocationAccessPolicy.checkLocationPermission(mApp,
4802 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4803 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004804 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004805 .setCallingPid(Binder.getCallingPid())
4806 .setCallingUid(Binder.getCallingUid())
4807 .setMethod("getCellNetworkScanResults")
4808 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4809 .build());
4810 switch (locationResult) {
4811 case DENIED_HARD:
4812 throw new SecurityException("Not allowed to access scan results -- location");
4813 case DENIED_SOFT:
4814 return null;
4815 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816
Pengquan Menga1bb6272018-09-06 09:59:22 -07004817 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818 try {
4819 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004820 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004821 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004822 } finally {
4823 Binder.restoreCallingIdentity(identity);
4824 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004825 }
4826
4827 /**
yinxub1bed742017-04-17 11:45:04 -07004828 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004829 *
yinxub1bed742017-04-17 11:45:04 -07004830 * @param subId id of the subscription
4831 * @param request contains the radio access networks with bands/channels to scan
4832 * @param messenger callback messenger for scan results or errors
4833 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004834 * @return the id of the requested scan which can be used to stop the scan.
4835 */
4836 @Override
4837 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004838 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4840 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004841 LocationAccessPolicy.LocationPermissionResult locationResult =
4842 LocationAccessPolicy.checkLocationPermission(mApp,
4843 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4844 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004845 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004846 .setCallingPid(Binder.getCallingPid())
4847 .setCallingUid(Binder.getCallingUid())
4848 .setMethod("requestNetworkScan")
4849 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4850 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004851 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004852 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004853 if (e != null) {
4854 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4855 throw e;
4856 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004857 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004858 return TelephonyScanManager.INVALID_SCAN_ID;
4859 }
4860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004861 }
Hall Liu912dfd32019-04-25 14:02:26 -07004862 int callingUid = Binder.getCallingUid();
4863 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004864 final long identity = Binder.clearCallingIdentity();
4865 try {
4866 return mNetworkScanRequestTracker.startNetworkScan(
4867 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004868 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004869 } finally {
4870 Binder.restoreCallingIdentity(identity);
4871 }
yinxu504e1392017-04-12 16:03:22 -07004872 }
4873
Hall Liub2ac8ef2019-02-28 15:56:23 -08004874 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004875 NetworkScanRequest request, int subId) {
4876 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4877 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4878 boolean hasNetworkScanPermission =
4879 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4880 == PERMISSION_GRANTED;
4881
4882 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4883 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4884 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004885 }
4886
4887 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4888 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004889 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4890 return new SecurityException("Specific channels must not be"
4891 + " scanned without location access.");
4892 }
4893 }
4894 }
4895
Hall Liub2ac8ef2019-02-28 15:56:23 -08004896 return null;
4897 }
4898
yinxu504e1392017-04-12 16:03:22 -07004899 /**
4900 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004901 *
4902 * @param subId id of the subscription
4903 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004904 */
4905 @Override
4906 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4908 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909
Hall Liu912dfd32019-04-25 14:02:26 -07004910 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004911 final long identity = Binder.clearCallingIdentity();
4912 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004913 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914 } finally {
4915 Binder.restoreCallingIdentity(identity);
4916 }
yinxu504e1392017-04-12 16:03:22 -07004917 }
4918
4919 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004920 * Get the calculated preferred network type.
4921 * Used for debugging incorrect network type.
4922 *
4923 * @return the preferred network type, defined in RILConstants.java.
4924 */
4925 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004926 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004927 final Phone defaultPhone = getDefaultPhone();
4928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004929 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004930 return RILConstants.PREFERRED_NETWORK_MODE;
4931 }
4932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 final long identity = Binder.clearCallingIdentity();
4934 try {
4935 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004936 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004937 } finally {
4938 Binder.restoreCallingIdentity(identity);
4939 }
Junda Liu84d15a22014-07-02 11:21:04 -07004940 }
4941
4942 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004943 * Get the preferred network type.
4944 * Used for device configuration by some CDMA operators.
4945 *
4946 * @return the preferred network type, defined in RILConstants.java.
4947 */
4948 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004949 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004950 TelephonyPermissions
4951 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4952 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953
4954 final long identity = Binder.clearCallingIdentity();
4955 try {
4956 if (DBG) log("getPreferredNetworkType");
4957 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4958 int networkType = (result != null ? result[0] : -1);
4959 if (DBG) log("getPreferredNetworkType: " + networkType);
4960 return networkType;
4961 } finally {
4962 Binder.restoreCallingIdentity(identity);
4963 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004964 }
4965
4966 /**
4967 * Set the preferred network type.
4968 * Used for device configuration by some CDMA operators.
4969 *
4970 * @param networkType the preferred network type, defined in RILConstants.java.
4971 * @return true on success; false on any failure.
4972 */
4973 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004974 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4976 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977
4978 final long identity = Binder.clearCallingIdentity();
4979 try {
4980 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4981 Boolean success = (Boolean) sendRequest(
4982 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4983 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4984 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004985 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4987 }
4988 return success;
4989 } finally {
4990 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004991 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004992 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004993
4994 /**
Miaoa84611c2019-03-15 09:21:10 +08004995 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004996 *
Miaoa84611c2019-03-15 09:21:10 +08004997 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004998 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004999 * @hide
5000 */
5001 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005002 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005003 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005005 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006 try {
Miaoa84611c2019-03-15 09:21:10 +08005007 if (phone != null) {
5008 return phone.hasMatchedTetherApnSetting();
5009 } else {
5010 return false;
5011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 } finally {
5013 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005014 }
Junda Liu475951f2014-11-07 16:45:03 -08005015 }
5016
5017 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005018 * Set mobile data enabled
5019 * Used by the user through settings etc to turn on/off mobile data
5020 *
5021 * @param enable {@code true} turn turn data on, else {@code false}
5022 */
5023 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005024 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5026 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005027
5028 final long identity = Binder.clearCallingIdentity();
5029 try {
5030 int phoneId = mSubscriptionController.getPhoneId(subId);
5031 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5032 Phone phone = PhoneFactory.getPhone(phoneId);
5033 if (phone != null) {
5034 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005035 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005037 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 }
5039 } finally {
5040 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005041 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005042 }
5043
5044 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005045 * Get the user enabled state of Mobile Data.
5046 *
5047 * TODO: remove and use isUserDataEnabled.
5048 * This can't be removed now because some vendor codes
5049 * calls through ITelephony directly while they should
5050 * use TelephonyManager.
5051 *
5052 * @return true on enabled
5053 */
5054 @Override
5055 public boolean getDataEnabled(int subId) {
5056 return isUserDataEnabled(subId);
5057 }
5058
5059 /**
5060 * Get whether mobile data is enabled per user setting.
5061 *
5062 * There are other factors deciding whether mobile data is actually enabled, but they are
5063 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005064 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005065 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005066 *
5067 * @return {@code true} if data is enabled else {@code false}
5068 */
5069 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005070 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005071 try {
5072 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5073 null);
5074 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5076 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005077 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078
5079 final long identity = Binder.clearCallingIdentity();
5080 try {
5081 int phoneId = mSubscriptionController.getPhoneId(subId);
5082 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5083 Phone phone = PhoneFactory.getPhone(phoneId);
5084 if (phone != null) {
5085 boolean retVal = phone.isUserDataEnabled();
5086 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5087 return retVal;
5088 } else {
5089 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5090 return false;
5091 }
5092 } finally {
5093 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005094 }
5095 }
5096
5097 /**
5098 * Get whether mobile data is enabled.
5099 *
5100 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5101 * whether mobile data is actually enabled.
5102 *
5103 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5104 *
5105 * @return {@code true} if data is enabled else {@code false}
5106 */
5107 @Override
5108 public boolean isDataEnabled(int subId) {
5109 try {
5110 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5111 null);
5112 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5114 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005115 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116
5117 final long identity = Binder.clearCallingIdentity();
5118 try {
5119 int phoneId = mSubscriptionController.getPhoneId(subId);
5120 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5121 Phone phone = PhoneFactory.getPhone(phoneId);
5122 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005123 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005124 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5125 return retVal;
5126 } else {
5127 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5128 return false;
5129 }
5130 } finally {
5131 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005132 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005133 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005134
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005135 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5136 Phone phone) {
5137 //load access rules from carrier configs, and check those as well: b/139133814
5138 SubscriptionController subController = SubscriptionController.getInstance();
5139 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5140 || subController == null) return privilegeFromSim;
5141
5142 int uid = Binder.getCallingUid();
5143 PackageManager pkgMgr = phone.getContext().getPackageManager();
5144 String[] packages = pkgMgr.getPackagesForUid(uid);
5145
5146 final long identity = Binder.clearCallingIdentity();
5147 try {
5148 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5149 SubscriptionManager subManager = (SubscriptionManager)
5150 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5151 for (String pkg : packages) {
5152 if (subManager.canManageSubscription(subInfo, pkg)) {
5153 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5154 }
5155 }
5156 return privilegeFromSim;
5157 } finally {
5158 Binder.restoreCallingIdentity(identity);
5159 }
5160 }
5161
5162 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5163 String pkgName) {
5164 //load access rules from carrier configs, and check those as well: b/139133814
5165 SubscriptionController subController = SubscriptionController.getInstance();
5166 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5167 || subController == null) return privilegeFromSim;
5168
5169 final long identity = Binder.clearCallingIdentity();
5170 try {
5171 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5172 SubscriptionManager subManager = (SubscriptionManager)
5173 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5174 return subManager.canManageSubscription(subInfo, pkgName)
5175 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
5179 }
5180
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005181 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005182 public int getCarrierPrivilegeStatus(int subId) {
5183 final Phone phone = getPhone(subId);
5184 if (phone == null) {
5185 loge("getCarrierPrivilegeStatus: Invalid subId");
5186 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5187 }
5188 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005189 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005190 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005191 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5192 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005193
5194 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5195 card.getCarrierPrivilegeStatusForCurrentTransaction(
5196 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005197 }
Junda Liu29340342014-07-10 15:23:27 -07005198
5199 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005200 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005201 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005202 final Phone phone = getPhone(subId);
5203 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005204 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005205 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5206 }
5207 UiccProfile profile =
5208 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5209 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005210 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005211 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5212 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005213 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005214 profile.getCarrierPrivilegeStatusForUid(
5215 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005216 }
5217
5218 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005219 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5220 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005221 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005222 }
5223
5224 int phoneId = SubscriptionManager.getPhoneId(subId);
5225 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005226 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005227 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005228 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5229 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005230 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5231 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5232 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005233 }
5234
5235 @Override
5236 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005237 if (TextUtils.isEmpty(pkgName))
5238 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005239 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5240 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5241 UiccCard card = UiccController.getInstance().getUiccCard(i);
5242 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005243 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005244 continue;
5245 }
5246
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005247 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5248 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5249 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005250 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5251 break;
5252 }
5253 }
5254
5255 return result;
Junda Liu29340342014-07-10 15:23:27 -07005256 }
Derek Tan89e89d42014-07-08 17:00:10 -07005257
5258 @Override
Junda Liue64de782015-04-16 17:19:16 -07005259 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5260 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5261 loge("phoneId " + phoneId + " is not valid.");
5262 return null;
5263 }
5264 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005265 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005266 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005267 return null ;
5268 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005269 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005270 }
5271
Amith Yamasani6e118872016-02-19 12:53:51 -08005272 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005273 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005274 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005275 List<String> privilegedPackages = new ArrayList<>();
5276 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005277 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5278 // has UICC in that slot.
5279 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005280 if (card.hasCarrierPrivilegeRules()) {
5281 if (packages == null) {
5282 // Only check packages in user 0 for now
5283 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005284 PackageManager.MATCH_DISABLED_COMPONENTS
5285 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005286 | PackageManager.GET_SIGNING_CERTIFICATES,
5287 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005288 }
5289 for (int p = packages.size() - 1; p >= 0; p--) {
5290 PackageInfo pkgInfo = packages.get(p);
5291 if (pkgInfo != null && pkgInfo.packageName != null
5292 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005293 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005294 privilegedPackages.add(pkgInfo.packageName);
5295 }
5296 }
5297 }
5298 }
5299 return privilegedPackages;
5300 }
5301
chen xuf7e9fe82019-05-09 19:31:02 -07005302 @Override
5303 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005304 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5305
5306 final long identity = Binder.clearCallingIdentity();
5307
chen xuf7e9fe82019-05-09 19:31:02 -07005308 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005309 try {
5310 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5311 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5312 }
5313 } finally {
5314 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005315 }
5316 return privilegedPackages;
5317 }
5318
Wink Savilleb564aae2014-10-23 10:18:09 -07005319 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005320 final Phone phone = getPhone(subId);
5321 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005322 if (card == null) {
5323 loge("getIccId: No UICC");
5324 return null;
5325 }
5326 String iccId = card.getIccId();
5327 if (TextUtils.isEmpty(iccId)) {
5328 loge("getIccId: ICC ID is null or empty.");
5329 return null;
5330 }
5331 return iccId;
5332 }
5333
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005334 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005335 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5336 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005337 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005338 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340 final long identity = Binder.clearCallingIdentity();
5341 try {
5342 final String iccId = getIccId(subId);
5343 final Phone phone = getPhone(subId);
5344 if (phone == null) {
5345 return false;
5346 }
5347 final String subscriberId = phone.getSubscriberId();
5348
5349 if (DBG_MERGE) {
5350 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5351 + subscriberId + " to " + number);
5352 }
5353
5354 if (TextUtils.isEmpty(iccId)) {
5355 return false;
5356 }
5357
5358 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5359
5360 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5361 if (alphaTag == null) {
5362 editor.remove(alphaTagPrefKey);
5363 } else {
5364 editor.putString(alphaTagPrefKey, alphaTag);
5365 }
5366
5367 // Record both the line number and IMSI for this ICCID, since we need to
5368 // track all merged IMSIs based on line number
5369 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5370 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5371 if (number == null) {
5372 editor.remove(numberPrefKey);
5373 editor.remove(subscriberPrefKey);
5374 } else {
5375 editor.putString(numberPrefKey, number);
5376 editor.putString(subscriberPrefKey, subscriberId);
5377 }
5378
5379 editor.commit();
5380 return true;
5381 } finally {
5382 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005383 }
Derek Tan7226c842014-07-02 17:42:23 -07005384 }
5385
5386 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005387 public String getLine1NumberForDisplay(int subId, String callingPackage,
5388 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005389 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005391 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005392 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005393 return null;
5394 }
Derek Tan97ebb422014-09-05 16:55:38 -07005395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 final long identity = Binder.clearCallingIdentity();
5397 try {
5398 String iccId = getIccId(subId);
5399 if (iccId != null) {
5400 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5401 if (DBG_MERGE) {
5402 log("getLine1NumberForDisplay returning "
5403 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5404 }
5405 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005406 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5408 return null;
5409 } finally {
5410 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005411 }
Derek Tan7226c842014-07-02 17:42:23 -07005412 }
5413
5414 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005415 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5416 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005418 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005419 return null;
5420 }
Derek Tan97ebb422014-09-05 16:55:38 -07005421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422 final long identity = Binder.clearCallingIdentity();
5423 try {
5424 String iccId = getIccId(subId);
5425 if (iccId != null) {
5426 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5427 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5428 }
5429 return null;
5430 } finally {
5431 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005432 }
Derek Tan7226c842014-07-02 17:42:23 -07005433 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005434
5435 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005436 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5437 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005438 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5439 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005440 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005441 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005442 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005443 return null;
5444 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005445
Jordan Liub49b04b2019-05-06 14:45:15 -07005446 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5447 // the process, where TelephonyManager was instantiated.
5448 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005449 final long identity = Binder.clearCallingIdentity();
5450 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005451 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452 final TelephonyManager tele = TelephonyManager.from(context);
5453 final SubscriptionManager sub = SubscriptionManager.from(context);
5454
5455 // Figure out what subscribers are currently active
5456 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457
Jordan Liub49b04b2019-05-06 14:45:15 -07005458 // Only consider subs which match the current subId
5459 // This logic can be simplified. See b/131189269 for progress.
5460 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005461 activeSubscriberIds.add(tele.getSubscriberId(subId));
5462 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005463
5464 // First pass, find a number override for an active subscriber
5465 String mergeNumber = null;
5466 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5467 for (String key : prefs.keySet()) {
5468 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5469 final String subscriberId = (String) prefs.get(key);
5470 if (activeSubscriberIds.contains(subscriberId)) {
5471 final String iccId = key.substring(
5472 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5473 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5474 mergeNumber = (String) prefs.get(numberKey);
5475 if (DBG_MERGE) {
5476 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5477 + " for active subscriber " + subscriberId);
5478 }
5479 if (!TextUtils.isEmpty(mergeNumber)) {
5480 break;
5481 }
5482 }
5483 }
5484 }
5485
5486 // Shortcut when no active merged subscribers
5487 if (TextUtils.isEmpty(mergeNumber)) {
5488 return null;
5489 }
5490
5491 // Second pass, find all subscribers under that line override
5492 final ArraySet<String> result = new ArraySet<>();
5493 for (String key : prefs.keySet()) {
5494 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5495 final String number = (String) prefs.get(key);
5496 if (mergeNumber.equals(number)) {
5497 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5498 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5499 final String subscriberId = (String) prefs.get(subscriberKey);
5500 if (!TextUtils.isEmpty(subscriberId)) {
5501 result.add(subscriberId);
5502 }
5503 }
5504 }
5505 }
5506
5507 final String[] resultArray = result.toArray(new String[result.size()]);
5508 Arrays.sort(resultArray);
5509 if (DBG_MERGE) {
5510 Slog.d(LOG_TAG,
5511 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5512 }
5513 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005514 } finally {
5515 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005516 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005517 }
5518
5519 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005520 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5521 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5522
5523 final long identity = Binder.clearCallingIdentity();
5524 try {
5525 final TelephonyManager telephonyManager = mApp.getSystemService(
5526 TelephonyManager.class);
5527 String subscriberId = telephonyManager.getSubscriberId(subId);
5528 if (subscriberId == null) {
5529 if (DBG) {
5530 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5531 + subId);
5532 }
5533 return null;
5534 }
5535
5536 final SubscriptionInfo info = SubscriptionController.getInstance()
5537 .getSubscriptionInfo(subId);
5538 final ParcelUuid groupUuid = info.getGroupUuid();
5539 // If it doesn't belong to any group, return just subscriberId of itself.
5540 if (groupUuid == null) {
5541 return new String[]{subscriberId};
5542 }
5543
5544 // Get all subscriberIds from the group.
5545 final List<String> mergedSubscriberIds = new ArrayList<>();
5546 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005547 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5548 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005549 for (SubscriptionInfo subInfo : groupInfos) {
5550 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5551 if (subscriberId != null) {
5552 mergedSubscriberIds.add(subscriberId);
5553 }
5554 }
5555
5556 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5557 } finally {
5558 Binder.restoreCallingIdentity(identity);
5559
5560 }
5561 }
5562
5563 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005564 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005565 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005566 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567
5568 final long identity = Binder.clearCallingIdentity();
5569 try {
5570 final Phone phone = getPhone(subId);
5571 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5572 } finally {
5573 Binder.restoreCallingIdentity(identity);
5574 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005575 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005576
5577 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005578 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005579 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5580 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005581 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5582 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583
5584 final long identity = Binder.clearCallingIdentity();
5585 try {
5586 final Phone phone = getPhone(subId);
5587 if (phone == null) {
5588 return false;
5589 }
5590 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5591 cdmaNonRoamingList);
5592 } finally {
5593 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005594 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005595 }
5596
5597 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005598 @Deprecated
5599 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5600 enforceModifyPermission();
5601
5602 int returnValue = 0;
5603 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005604 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005605 if(result.exception == null) {
5606 if (result.result != null) {
5607 byte[] responseData = (byte[])(result.result);
5608 if(responseData.length > oemResp.length) {
5609 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5610 responseData.length + "bytes. Buffer Size is " +
5611 oemResp.length + "bytes.");
5612 }
5613 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5614 returnValue = responseData.length;
5615 }
5616 } else {
5617 CommandException ex = (CommandException) result.exception;
5618 returnValue = ex.getCommandError().ordinal();
5619 if(returnValue > 0) returnValue *= -1;
5620 }
5621 } catch (RuntimeException e) {
5622 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5623 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5624 if(returnValue > 0) returnValue *= -1;
5625 }
5626
5627 return returnValue;
5628 }
5629
5630 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005631 public void setRadioCapability(RadioAccessFamily[] rafs) {
5632 try {
5633 ProxyController.getInstance().setRadioCapability(rafs);
5634 } catch (RuntimeException e) {
5635 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5636 }
5637 }
5638
5639 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005640 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005641 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005642 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005643 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005644 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005645 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646 final long identity = Binder.clearCallingIdentity();
5647 try {
chen xub97461a2018-10-26 14:17:57 -07005648 TelephonyPermissions
5649 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5650 mApp, phone.getSubId(), "getRadioAccessFamily");
5651 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005652 } finally {
5653 Binder.restoreCallingIdentity(identity);
5654 }
chen xub97461a2018-10-26 14:17:57 -07005655 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005656 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005657
5658 @Override
5659 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005660 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662
5663 final long identity = Binder.clearCallingIdentity();
5664 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005665 ImsManager.getInstance(defaultPhone.getContext(),
5666 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 } finally {
5668 Binder.restoreCallingIdentity(identity);
5669 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005670 }
5671
5672 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005673 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005674 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5676 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005677 return false;
5678 }
Svet Ganovb320e182015-04-16 12:30:10 -07005679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 final long identity = Binder.clearCallingIdentity();
5681 try {
5682 // Check the user preference and the system-level IMS setting. Even if the user has
5683 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5684 // In the long run, we may instead need to check if there exists a connection service
5685 // which can support video calling.
5686 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005687 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688 return imsManager.isVtEnabledByPlatform()
5689 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5690 && imsManager.isVtEnabledByUser();
5691 } finally {
5692 Binder.restoreCallingIdentity(identity);
5693 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005694 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005695
Andrew Leea1239f22015-03-02 17:44:07 -08005696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005697 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5698 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005700 mApp, subId, callingPackage, callingFeatureId,
5701 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 return false;
5703 }
5704
5705 final long identity = Binder.clearCallingIdentity();
5706 try {
5707 CarrierConfigManager configManager =
5708 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005709 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5711 } finally {
5712 Binder.restoreCallingIdentity(identity);
5713 }
Andrew Leea1239f22015-03-02 17:44:07 -08005714 }
5715
5716 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005717 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005719 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 return false;
5721 }
5722
5723 final long identity = Binder.clearCallingIdentity();
5724 try {
5725 CarrierConfigManager configManager =
5726 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005727 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5729 } finally {
5730 Binder.restoreCallingIdentity(identity);
5731 }
Andrew Leea1239f22015-03-02 17:44:07 -08005732 }
5733
Andrew Lee9431b832015-03-09 18:46:45 -07005734 @Override
5735 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005736 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005737 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005738 }
5739
5740 @Override
5741 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 final long identity = Binder.clearCallingIdentity();
5743 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005744 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745 } finally {
5746 Binder.restoreCallingIdentity(identity);
5747 }
Andrew Lee9431b832015-03-09 18:46:45 -07005748 }
5749
Hall Liuf6668912018-10-31 17:05:23 -07005750 /**
5751 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5752 * support for the feature and device firmware support.
5753 *
5754 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5755 */
5756 @Override
5757 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005758 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005759 final Phone phone = getPhone(subscriptionId);
5760 if (phone == null) {
5761 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5762 return false;
5763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005765 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5767 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005768 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769 return isCarrierSupported && isDeviceSupported;
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
Hall Liu98187582018-01-22 19:15:32 -08005773 }
5774
Hall Liuf6668912018-10-31 17:05:23 -07005775 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005776 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5777 * RTT setting, will return true if the device and carrier both support RTT.
5778 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005779 */
5780 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781 final long identity = Binder.clearCallingIdentity();
5782 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00005783 boolean isRttSupported = isRttSupported(subscriptionId);
5784 boolean isUserRttSettingOn = Settings.Secure.getInt(
5785 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5786 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5787 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5788 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005789 } finally {
5790 Binder.restoreCallingIdentity(identity);
5791 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005792 }
5793
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005794 @Deprecated
5795 @Override
5796 public String getDeviceId(String callingPackage) {
5797 return getDeviceIdWithFeature(callingPackage, null);
5798 }
5799
Sanket Padawe7310cc72015-01-14 09:53:20 -08005800 /**
5801 * Returns the unique device ID of phone, for example, the IMEI for
5802 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5803 *
5804 * <p>Requires Permission:
5805 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5806 */
5807 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005808 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005809 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005810 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005811 return null;
5812 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005813 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005814 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005815 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005816 return null;
5817 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818
5819 final long identity = Binder.clearCallingIdentity();
5820 try {
5821 return phone.getDeviceId();
5822 } finally {
5823 Binder.restoreCallingIdentity(identity);
5824 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005825 }
5826
Ping Sunc67b7c22016-03-02 19:16:45 +08005827 /**
5828 * {@hide}
5829 * Returns the IMS Registration Status on a particular subid
5830 *
5831 * @param subId
5832 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005833 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005834 Phone phone = getPhone(subId);
5835 if (phone != null) {
5836 return phone.isImsRegistered();
5837 } else {
5838 return false;
5839 }
5840 }
5841
Santos Cordon7a1885b2015-02-03 11:15:19 -08005842 @Override
5843 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005844 final long identity = Binder.clearCallingIdentity();
5845 try {
5846 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5847 } finally {
5848 Binder.restoreCallingIdentity(identity);
5849 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005850 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005851
Tyler Gunnf70ed162019-04-03 15:28:53 -07005852 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005853 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005854 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005856 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005857 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5858 }
5859 final long identity = Binder.clearCallingIdentity();
5860 try {
5861 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5862 } finally {
5863 Binder.restoreCallingIdentity(identity);
5864 }
5865 }
5866
5867 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005868 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5869 final long identity = Binder.clearCallingIdentity();
5870 try {
5871 Phone phone = getPhone(subscriptionId);
5872 if (phone == null) {
5873 return null;
5874 }
5875 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5876 } finally {
5877 Binder.restoreCallingIdentity(identity);
5878 }
5879 }
5880
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005881 /**
5882 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005883 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005884 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005885 final long identity = Binder.clearCallingIdentity();
5886 try {
5887 Phone phone = getPhone(subId);
5888 if (phone != null) {
5889 return phone.isWifiCallingEnabled();
5890 } else {
5891 return false;
5892 }
5893 } finally {
5894 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005895 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005896 }
5897
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005898 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005899 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005900 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005901 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 final long identity = Binder.clearCallingIdentity();
5903 try {
5904 Phone phone = getPhone(subId);
5905 if (phone != null) {
5906 return phone.isVideoEnabled();
5907 } else {
5908 return false;
5909 }
5910 } finally {
5911 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005912 }
5913 }
5914
5915 /**
5916 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5917 * defined in {@link ImsRegistrationImplBase}.
5918 */
5919 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005920 final long identity = Binder.clearCallingIdentity();
5921 try {
5922 Phone phone = getPhone(subId);
5923 if (phone != null) {
5924 return phone.getImsRegistrationTech();
5925 } else {
5926 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5927 }
5928 } finally {
5929 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005930 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005931 }
5932
Stuart Scott8eef64f2015-04-08 15:13:54 -07005933 @Override
5934 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08005935 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005936 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5937 return;
5938 }
5939
Svet Ganovcc087f82015-05-12 20:35:54 -07005940 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005941
Svet Ganovcc087f82015-05-12 20:35:54 -07005942 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005943 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5944 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005945 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005946 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005947 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005948 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5949 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005950 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005951 // There has been issues when Sms raw table somehow stores orphan
5952 // fragments. They lead to garbled message when new fragments come
5953 // in and combined with those stale ones. In case this happens again,
5954 // user can reset all network settings which will clean up this table.
5955 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005956 // Clean up IMS settings as well here.
5957 int slotId = getSlotIndex(subId);
5958 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5959 ImsManager.getInstance(mApp, slotId).factoryReset();
5960 }
Naina Nallurid63128d2019-09-17 14:10:30 -07005961
5962 // Erase modem config if erase modem on network setting is enabled.
5963 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5964 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5965 if (configValue != null && Boolean.parseBoolean(configValue)) {
5966 sendEraseModemConfig(getDefaultPhone());
5967 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005968 } finally {
5969 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005970 }
5971 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005972
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005973 private void cleanUpSmsRawTable(Context context) {
5974 ContentResolver resolver = context.getContentResolver();
5975 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5976 resolver.delete(uri, null, null);
5977 }
5978
Narayan Kamath1c496c22015-04-16 14:40:19 +01005979 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005980 public String getSimLocaleForSubscriber(int subId) {
5981 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5982 final Phone phone = getPhone(subId);
5983 if (phone == null) {
5984 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005985 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 final long identity = Binder.clearCallingIdentity();
5988 try {
chen xu5d3637b2019-01-21 23:31:38 -08005989 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005990 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08005991 if (info == null) {
5992 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5993 return null;
5994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 // Try and fetch the locale from the carrier properties or from the SIM language
5996 // preferences (EF-PL and EF-LI)...
5997 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005999 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6000 if (localeFromDefaultSim != null) {
6001 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6002 if (DBG) log("Using locale from subId: " + subId + " locale: "
6003 + localeFromDefaultSim);
6004 return localeFromDefaultSim.toLanguageTag();
6005 } else {
6006 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 }
6008 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010 // The SIM language preferences only store a language (e.g. fr = French), not an
6011 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6012 // the SIM and carrier preferences does not include a country we add the country
6013 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006014 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006016 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 return mccLocale.toLanguageTag();
6018 }
6019
6020 if (DBG) log("No locale found - returning null");
6021 return null;
6022 } finally {
6023 Binder.restoreCallingIdentity(identity);
6024 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006025 }
6026
6027 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006028 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6029 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006030 }
6031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006032 /**
6033 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6034 */
6035 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006036 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6037 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006038 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006039
Chenjie Yu1ba97252018-01-11 18:16:20 -08006040 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006041 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006042
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006043 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006044 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6045 * representing the state of the modem.
6046 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006047 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6048 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006049 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006050 */
6051 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006052 public void requestModemActivityInfo(ResultReceiver result) {
6053 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006054 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055
6056 final long identity = Binder.clearCallingIdentity();
6057 try {
6058 ModemActivityInfo ret = null;
6059 synchronized (mLastModemActivityInfo) {
6060 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6061 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006062 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006063 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006065 int[] txTimeMs = info.getTransmitTimeMillis();
6066 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006068 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069 }
6070 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006071 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6072 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 mLastModemActivityInfo.setIdleTimeMillis(
6074 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006075 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6076 mLastModemActivityInfo.setReceiveTimeMillis(
6077 info.getReceiveTimeMillis() + mLastModemActivityInfo
6078 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006079 }
Chen Xud78231e2019-09-10 18:49:52 -07006080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6082 mLastModemActivityInfo.getSleepTimeMillis(),
6083 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006084 mLastModemActivityInfo.getTransmitTimeMillis(),
6085 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006086 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 Bundle bundle = new Bundle();
6088 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6089 result.send(0, bundle);
6090 } finally {
6091 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006092 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006093 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006094
Siddharth Rayb8114062018-06-17 15:02:38 -07006095 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6096 // less than total activity duration.
6097 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6098 if (info == null) {
6099 return false;
6100 }
6101 int activityDurationMs =
6102 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6103 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006104 int[] txTimeMs = info.getTransmitTimeMillis();
6105 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6106 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006107 }
6108 return (info.isValid()
6109 && (info.getSleepTimeMillis() <= activityDurationMs)
6110 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006111 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006112 && (totalTxTimeMs <= activityDurationMs));
6113 }
6114
Jack Yu85bd38a2015-11-09 11:34:32 -08006115 /**
6116 * {@hide}
6117 * Returns the service state information on specified subscription.
6118 */
6119 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006120 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6121 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006123 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006124 return null;
6125 }
6126
Hall Liuf19c44f2018-11-27 14:38:17 -08006127 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6128 LocationAccessPolicy.checkLocationPermission(mApp,
6129 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6130 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006131 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006132 .setCallingPid(Binder.getCallingPid())
6133 .setCallingUid(Binder.getCallingUid())
6134 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006135 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006136 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6137 .build());
6138
6139 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6140 LocationAccessPolicy.checkLocationPermission(mApp,
6141 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6142 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006143 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006144 .setCallingPid(Binder.getCallingPid())
6145 .setCallingUid(Binder.getCallingUid())
6146 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006147 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006148 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6149 .build());
6150 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6151 boolean hasFinePermission =
6152 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6153 boolean hasCoarsePermission =
6154 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156 final long identity = Binder.clearCallingIdentity();
6157 try {
6158 final Phone phone = getPhone(subId);
6159 if (phone == null) {
6160 return null;
6161 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006162
Hall Liuf19c44f2018-11-27 14:38:17 -08006163 ServiceState ss = phone.getServiceState();
6164
6165 // Scrub out the location info in ServiceState depending on what level of access
6166 // the caller has.
6167 if (hasFinePermission) return ss;
6168 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6169 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006170 } finally {
6171 Binder.restoreCallingIdentity(identity);
6172 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006173 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006174
6175 /**
6176 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6177 *
6178 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6179 * voicemail ringtone.
6180 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6181 * PhoneAccount.
6182 */
6183 @Override
6184 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006185 final long identity = Binder.clearCallingIdentity();
6186 try {
6187 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6188 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006189 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6193 } finally {
6194 Binder.restoreCallingIdentity(identity);
6195 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006196 }
6197
6198 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006199 * Sets the per-account voicemail ringtone.
6200 *
6201 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6202 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6203 *
6204 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6205 * voicemail ringtone.
6206 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6207 * PhoneAccount.
6208 */
6209 @Override
6210 public void setVoicemailRingtoneUri(String callingPackage,
6211 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006212 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006213 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006214 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6215 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6217 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6218 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006219 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220
6221 final long identity = Binder.clearCallingIdentity();
6222 try {
6223 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6224 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006225 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226 }
6227 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6228 } finally {
6229 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006230 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006231 }
6232
6233 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006234 * Returns whether vibration is set for voicemail notification in Phone settings.
6235 *
6236 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6237 * voicemail vibration setting.
6238 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6239 */
6240 @Override
6241 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 final long identity = Binder.clearCallingIdentity();
6243 try {
6244 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6245 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006246 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006247 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006248
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6250 } finally {
6251 Binder.restoreCallingIdentity(identity);
6252 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006253 }
6254
Youhan Wange64578a2016-05-02 15:32:42 -07006255 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006256 * Sets the per-account voicemail vibration.
6257 *
6258 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6259 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6260 *
6261 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6262 * voicemail vibration setting.
6263 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6264 * specific PhoneAccount.
6265 */
6266 @Override
6267 public void setVoicemailVibrationEnabled(String callingPackage,
6268 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006269 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006270 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006271 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6272 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6274 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6275 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006276 }
6277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278 final long identity = Binder.clearCallingIdentity();
6279 try {
6280 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6281 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006282 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283 }
6284 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6285 } finally {
6286 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006287 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006288 }
6289
6290 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006291 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6292 *
6293 * @throws SecurityException if the caller does not have the required permission
6294 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006295 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006296 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006297 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006298 }
6299
6300 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006301 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6302 * permission.
6303 *
6304 * @throws SecurityException if the caller does not have the required permission
6305 */
6306 private void enforceSendSmsPermission() {
6307 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6308 }
6309
6310 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006311 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006312 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006313 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006314 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006315 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 final long identity = Binder.clearCallingIdentity();
6317 try {
6318 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006319 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006320 if (componentName == null) {
6321 throw new SecurityException(
6322 "Caller not current active visual voicemail package[null]");
6323 }
6324 String vvmPackage = componentName.getPackageName();
6325 if (!callingPackage.equals(vvmPackage)) {
6326 throw new SecurityException("Caller not current active visual voicemail package["
6327 + vvmPackage + "]");
6328 }
6329 } finally {
6330 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006331 }
6332 }
6333
6334 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006335 * Return the application ID for the app type.
6336 *
6337 * @param subId the subscription ID that this request applies to.
6338 * @param appType the uicc app type.
6339 * @return Application ID for specificied app type, or null if no uicc.
6340 */
6341 @Override
6342 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006343 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006344 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345
6346 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006347 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006348 if (phone == null) {
6349 return null;
6350 }
6351 String aid = null;
6352 try {
6353 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6354 .getApplicationByType(appType).getAid();
6355 } catch (Exception e) {
6356 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6357 }
6358 return aid;
6359 } finally {
6360 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006361 }
Youhan Wange64578a2016-05-02 15:32:42 -07006362 }
6363
Youhan Wang4001d252016-05-11 10:29:41 -07006364 /**
6365 * Return the Electronic Serial Number.
6366 *
6367 * @param subId the subscription ID that this request applies to.
6368 * @return ESN or null if error.
6369 */
6370 @Override
6371 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006372 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006373 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374
6375 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006376 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377 if (phone == null) {
6378 return null;
6379 }
6380 String esn = null;
6381 try {
6382 esn = phone.getEsn();
6383 } catch (Exception e) {
6384 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6385 }
6386 return esn;
6387 } finally {
6388 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006389 }
Youhan Wang4001d252016-05-11 10:29:41 -07006390 }
6391
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006392 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006393 * Return the Preferred Roaming List Version.
6394 *
6395 * @param subId the subscription ID that this request applies to.
6396 * @return PRLVersion or null if error.
6397 */
6398 @Override
6399 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006400 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006401 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402
6403 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006404 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 if (phone == null) {
6406 return null;
6407 }
6408 String cdmaPrlVersion = null;
6409 try {
6410 cdmaPrlVersion = phone.getCdmaPrlVersion();
6411 } catch (Exception e) {
6412 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6413 }
6414 return cdmaPrlVersion;
6415 } finally {
6416 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006417 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006418 }
6419
6420 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006421 * Get snapshot of Telephony histograms
6422 * @return List of Telephony histograms
6423 * @hide
6424 */
6425 @Override
6426 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6428 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429
6430 final long identity = Binder.clearCallingIdentity();
6431 try {
6432 return RIL.getTelephonyRILTimingHistograms();
6433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006436 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006437
6438 /**
6439 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006440 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6441 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006442 * Require system privileges. In the future we may add this to carrier APIs.
6443 *
Michele Berionne482f8202018-11-27 18:57:59 -08006444 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006445 */
6446 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006447 @TelephonyManager.SetCarrierRestrictionResult
6448 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006449 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006450 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006451
Michele Berionne482f8202018-11-27 18:57:59 -08006452 if (carrierRestrictionRules == null) {
6453 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006454 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006455
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006456 final long identity = Binder.clearCallingIdentity();
6457 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006458 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006459 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006460 } finally {
6461 Binder.restoreCallingIdentity(identity);
6462 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006463 }
6464
6465 /**
6466 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006467 * Get the allowed carrier list and the excluded carrier list, including the priority between
6468 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006469 * Require system privileges. In the future we may add this to carrier APIs.
6470 *
Michele Berionne482f8202018-11-27 18:57:59 -08006471 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006472 */
6473 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006474 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006475 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006476 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477
6478 final long identity = Binder.clearCallingIdentity();
6479 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006480 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6481 if (response instanceof CarrierRestrictionRules) {
6482 return (CarrierRestrictionRules) response;
6483 }
6484 // Response is an Exception of some kind,
6485 // which is signalled to the user as a NULL retval
6486 return null;
6487 } catch (Exception e) {
6488 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6489 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490 } finally {
6491 Binder.restoreCallingIdentity(identity);
6492 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006493 }
6494
fionaxu59545b42016-05-25 15:53:37 -07006495 /**
6496 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6497 * @param subId the subscription ID that this action applies to.
6498 * @param enabled control enable or disable metered apns.
6499 * {@hide}
6500 */
6501 @Override
6502 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6503 enforceModifyPermission();
6504 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006505
6506 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006507 if (phone == null) {
6508 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6509 return;
6510 }
6511 try {
6512 phone.carrierActionSetMeteredApnsEnabled(enabled);
6513 } catch (Exception e) {
6514 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006515 } finally {
6516 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006517 }
6518 }
6519
6520 /**
6521 * Action set from carrier signalling broadcast receivers to enable/disable radio
6522 * @param subId the subscription ID that this action applies to.
6523 * @param enabled control enable or disable radio.
6524 * {@hide}
6525 */
6526 @Override
6527 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6528 enforceModifyPermission();
6529 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530
6531 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006532 if (phone == null) {
6533 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6534 return;
6535 }
6536 try {
6537 phone.carrierActionSetRadioEnabled(enabled);
6538 } catch (Exception e) {
6539 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006540 } finally {
6541 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006542 }
6543 }
6544
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006545 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006546 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6547 * network status based on which carrier apps could apply actions accordingly,
6548 * enable/disable default url handler for example.
6549 *
6550 * @param subId the subscription ID that this action applies to.
6551 * @param report control start/stop reporting the default network status.
6552 * {@hide}
6553 */
6554 @Override
6555 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6556 enforceModifyPermission();
6557 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558
6559 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006560 if (phone == null) {
6561 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6562 return;
6563 }
6564 try {
6565 phone.carrierActionReportDefaultNetworkStatus(report);
6566 } catch (Exception e) {
6567 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 } finally {
6569 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006570 }
6571 }
6572
6573 /**
fionaxud9622282017-07-17 17:51:30 -07006574 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6575 * @param subId the subscription ID that this action applies to.
6576 * {@hide}
6577 */
6578 @Override
6579 public void carrierActionResetAll(int subId) {
6580 enforceModifyPermission();
6581 final Phone phone = getPhone(subId);
6582 if (phone == null) {
6583 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6584 return;
6585 }
6586 try {
6587 phone.carrierActionResetAll();
6588 } catch (Exception e) {
6589 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6590 }
6591 }
6592
6593 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006594 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6595 * bug report is being generated.
6596 */
6597 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006598 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006599 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6600 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006601 writer.println("Permission Denial: can't dump Phone from pid="
6602 + Binder.getCallingPid()
6603 + ", uid=" + Binder.getCallingUid()
6604 + "without permission "
6605 + android.Manifest.permission.DUMP);
6606 return;
6607 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006608 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006609 }
Jack Yueb89b242016-06-22 13:27:47 -07006610
Brad Ebingerdac2f002018-04-03 15:17:52 -07006611 @Override
6612 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6613 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6614 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006615 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6616 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006617 }
6618
Jack Yueb89b242016-06-22 13:27:47 -07006619 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006620 * Get aggregated video call data usage since boot.
6621 *
6622 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6623 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006624 * {@hide}
6625 */
6626 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006627 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006628 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6629 null);
6630
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006631 final long identity = Binder.clearCallingIdentity();
6632 try {
6633 // NetworkStatsService keeps tracking the active network interface and identity. It
6634 // records the delta with the corresponding network identity.
6635 // We just return the total video call data usage snapshot since boot.
6636 Phone phone = getPhone(subId);
6637 if (phone != null) {
6638 return phone.getVtDataUsage(perUidStats);
6639 }
6640 return null;
6641 } finally {
6642 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006643 }
Jack Yueb89b242016-06-22 13:27:47 -07006644 }
Jack Yu75ab2952016-07-08 14:29:33 -07006645
6646 /**
6647 * Policy control of data connection. Usually used when data limit is passed.
6648 * @param enabled True if enabling the data, otherwise disabling.
6649 * @param subId Subscription index
6650 * {@hide}
6651 */
6652 @Override
6653 public void setPolicyDataEnabled(boolean enabled, int subId) {
6654 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006655
6656 final long identity = Binder.clearCallingIdentity();
6657 try {
6658 Phone phone = getPhone(subId);
6659 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006660 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006661 }
6662 } finally {
6663 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006664 }
6665 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006666
6667 /**
6668 * Get Client request stats
6669 * @return List of Client Request Stats
6670 * @hide
6671 */
6672 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006673 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6674 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006676 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006677 return null;
6678 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006679 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006681 final long identity = Binder.clearCallingIdentity();
6682 try {
6683 if (phone != null) {
6684 return phone.getClientRequestStats();
6685 }
6686
6687 return null;
6688 } finally {
6689 Binder.restoreCallingIdentity(identity);
6690 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006691 }
6692
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006693 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006694 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006695 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006696 }
Jack Yueb4124c2017-02-16 15:32:43 -08006697
6698 /**
Grace Chen70990072017-03-24 17:21:30 -07006699 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006700 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006701 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006702 * @param state State of SIM (power down, power up, pass through)
6703 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6704 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6705 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006706 *
6707 **/
6708 @Override
Grace Chen70990072017-03-24 17:21:30 -07006709 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006710 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006711 Phone phone = PhoneFactory.getPhone(slotIndex);
6712
vagdeviaf9a5b92018-08-15 16:01:53 -07006713 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 final long identity = Binder.clearCallingIdentity();
6716 try {
6717 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006718 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006719 }
6720 } finally {
6721 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006722 }
6723 }
Shuo Qiandd210312017-04-12 22:11:33 +00006724
Tyler Gunn65d45c22017-06-05 11:22:26 -07006725 private boolean isUssdApiAllowed(int subId) {
6726 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006727 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006728 if (configManager == null) {
6729 return false;
6730 }
6731 PersistableBundle pb = configManager.getConfigForSubId(subId);
6732 if (pb == null) {
6733 return false;
6734 }
6735 return pb.getBoolean(
6736 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6737 }
6738
Shuo Qiandd210312017-04-12 22:11:33 +00006739 /**
6740 * Check if phone is in emergency callback mode
6741 * @return true if phone is in emergency callback mode
6742 * @param subId sub id
6743 */
goneil9c5f4872017-12-05 14:07:56 -08006744 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006745 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006746 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006747 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006748
6749 final long identity = Binder.clearCallingIdentity();
6750 try {
6751 if (phone != null) {
6752 return phone.isInEcm();
6753 } else {
6754 return false;
6755 }
6756 } finally {
6757 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006758 }
6759 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006760
6761 /**
6762 * Get the current signal strength information for the given subscription.
6763 * Because this information is not updated when the device is in a low power state
6764 * it should not be relied-upon to be current.
6765 * @param subId Subscription index
6766 * @return the most recent cached signal strength info from the modem
6767 */
6768 @Override
6769 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006770 final long identity = Binder.clearCallingIdentity();
6771 try {
6772 Phone p = getPhone(subId);
6773 if (p == null) {
6774 return null;
6775 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006777 return p.getSignalStrength();
6778 } finally {
6779 Binder.restoreCallingIdentity(identity);
6780 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006781 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006782
Pengquan Meng77b7f132018-08-22 14:49:57 -07006783 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006784 * Get the current modem radio state for the given slot.
6785 * @param slotIndex slot index.
6786 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006787 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006788 * @return the current radio power state from the modem
6789 */
6790 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006791 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006792 Phone phone = PhoneFactory.getPhone(slotIndex);
6793 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6795 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006796 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6797 }
6798
6799 final long identity = Binder.clearCallingIdentity();
6800 try {
6801 return phone.getRadioPowerState();
6802 } finally {
6803 Binder.restoreCallingIdentity(identity);
6804 }
6805 }
6806 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6807 }
6808
6809 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006810 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6811 *
6812 * <p>Requires one of the following permissions:
6813 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6814 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6815 * privileges.
6816 *
6817 * @param subId subscription id
6818 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6819 * {@code false}.
6820 */
6821 @Override
6822 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006823 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6824 null /* message */);
6825
Pengquan Menga1bb6272018-09-06 09:59:22 -07006826 boolean isEnabled = false;
6827 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006828 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006829 Phone phone = getPhone(subId);
6830 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006831 } catch (Exception e) {
6832 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6833 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006834 } finally {
6835 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006836 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006837 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006838 }
6839
6840
6841 /**
6842 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6843 *
6844 * <p> Requires permission:
6845 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6846 * privileges.
6847 *
6848 * @param subId subscription id
6849 * @param isEnabled {@code true} means enable, {@code false} means disable.
6850 */
6851 @Override
6852 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6854 mApp, subId, "setDataRoamingEnabled");
6855
Pengquan Menga1bb6272018-09-06 09:59:22 -07006856 final long identity = Binder.clearCallingIdentity();
6857 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006858 Phone phone = getPhone(subId);
6859 if (phone != null) {
6860 phone.setDataRoamingEnabled(isEnabled);
6861 }
6862 } finally {
6863 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006864 }
6865 }
6866
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006867 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006868 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006869 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6870 mApp, subId, "isManualNetworkSelectionAllowed");
6871
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006872 boolean isAllowed = true;
6873 final long identity = Binder.clearCallingIdentity();
6874 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006875 Phone phone = getPhone(subId);
6876 if (phone != null) {
6877 isAllowed = phone.isCspPlmnEnabled();
6878 }
6879 } finally {
6880 Binder.restoreCallingIdentity(identity);
6881 }
6882 return isAllowed;
6883 }
6884
6885 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006886 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006887 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006888 try {
6889 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006890 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006891 } catch (SecurityException e) {
6892 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6893 // has carrier privileges on an active UICC
6894 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6895 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006896 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006897 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006898 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006899
6900 final long identity = Binder.clearCallingIdentity();
6901 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006902 UiccController uiccController = UiccController.getInstance();
6903 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006904 if (hasReadPermission) {
6905 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006906 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006907
6908 // Remove private info if the caller doesn't have access
6909 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6910 for (UiccCardInfo cardInfo : cardInfos) {
6911 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6912 // is available
6913 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6914 if (card == null || card.getUiccProfile() == null) {
6915 // assume no access if the card or profile is unavailable
6916 filteredInfos.add(cardInfo.getUnprivileged());
6917 continue;
6918 }
6919 UiccProfile profile = card.getUiccProfile();
6920 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6921 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6922 filteredInfos.add(cardInfo);
6923 } else {
6924 filteredInfos.add(cardInfo.getUnprivileged());
6925 }
6926 }
6927 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006928 } finally {
6929 Binder.restoreCallingIdentity(identity);
6930 }
6931 }
6932
6933 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006934 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006935 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006937 final long identity = Binder.clearCallingIdentity();
6938 try {
6939 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6940 if (slots == null) {
6941 Rlog.i(LOG_TAG, "slots is null.");
6942 return null;
6943 }
6944
6945 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6946 for (int i = 0; i < slots.length; i++) {
6947 UiccSlot slot = slots[i];
6948 if (slot == null) {
6949 continue;
6950 }
6951
Jordan Liu7be7e652019-05-06 18:55:02 +00006952 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006953 UiccCard card = slot.getUiccCard();
6954 if (card != null) {
6955 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006956 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006957 cardId = slot.getEid();
6958 if (TextUtils.isEmpty(cardId)) {
6959 cardId = slot.getIccId();
6960 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006961 }
6962
Jordan Liu857451f2019-05-09 16:35:35 -07006963 if (cardId != null) {
6964 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6965 // if cardId is an EID, it's all digits so this is fine
6966 cardId = IccUtils.stripTrailingFs(cardId);
6967 }
6968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006969 int cardState = 0;
6970 switch (slot.getCardState()) {
6971 case CARDSTATE_ABSENT:
6972 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6973 break;
6974 case CARDSTATE_PRESENT:
6975 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6976 break;
6977 case CARDSTATE_ERROR:
6978 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6979 break;
6980 case CARDSTATE_RESTRICTED:
6981 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6982 break;
6983 default:
6984 break;
6985
6986 }
6987
6988 infos[i] = new UiccSlotInfo(
6989 slot.isActive(),
6990 slot.isEuicc(),
6991 cardId,
6992 cardState,
6993 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006994 slot.isExtendedApduSupported(),
6995 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996 }
6997 return infos;
6998 } finally {
6999 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007000 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007001 }
7002
7003 @Override
7004 public boolean switchSlots(int[] physicalSlots) {
7005 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007006
7007 final long identity = Binder.clearCallingIdentity();
7008 try {
7009 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7010 } finally {
7011 Binder.restoreCallingIdentity(identity);
7012 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007013 }
Jack Yu4c988042018-02-27 15:30:01 -08007014
7015 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007016 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007017 final long identity = Binder.clearCallingIdentity();
7018 try {
7019 return UiccController.getInstance().getCardIdForDefaultEuicc();
7020 } finally {
7021 Binder.restoreCallingIdentity(identity);
7022 }
7023 }
7024
7025 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007026 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7027 enforceModifyPermission();
7028 final Phone phone = getPhone(subId);
7029 if (phone == null) {
7030 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7031 return;
7032 }
7033
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034 final long identity = Binder.clearCallingIdentity();
7035 try {
7036 phone.setRadioIndicationUpdateMode(filters, mode);
7037 } finally {
7038 Binder.restoreCallingIdentity(identity);
7039 }
Jack Yu4c988042018-02-27 15:30:01 -08007040 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007041
7042 /**
goneil47ffb6e2018-04-06 15:40:58 -07007043 * A test API to reload the UICC profile.
7044 *
7045 * <p>Requires that the calling app has permission
7046 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7047 * @hide
7048 */
7049 @Override
7050 public void refreshUiccProfile(int subId) {
7051 enforceModifyPermission();
7052
7053 final long identity = Binder.clearCallingIdentity();
7054 try {
7055 Phone phone = getPhone(subId);
7056 if (phone == null) {
7057 return;
7058 }
7059 UiccCard uiccCard = phone.getUiccCard();
7060 if (uiccCard == null) {
7061 return;
7062 }
7063 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7064 if (uiccProfile == null) {
7065 return;
7066 }
7067 uiccProfile.refresh();
7068 } finally {
7069 Binder.restoreCallingIdentity(identity);
7070 }
7071 }
7072
7073 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007074 * Returns false if the mobile data is disabled by default, otherwise return true.
7075 */
7076 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007077 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007078 }
7079
7080 /**
7081 * Returns true if the data roaming is enabled by default, i.e the system property
7082 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7083 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7084 */
7085 private boolean getDefaultDataRoamingEnabled(int subId) {
7086 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007087 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007088 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007089 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7090 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7091 return isDataRoamingEnabled;
7092 }
7093
7094 /**
7095 * Returns the default network type for the given {@code subId}, if the default network type is
7096 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7097 */
7098 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007099 List<Integer> list = TelephonyProperties.default_network();
7100 int phoneId = mSubscriptionController.getPhoneId(subId);
7101 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7102 return list.get(phoneId);
7103 }
7104 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007105 }
fionaxua13278b2018-03-21 00:08:13 -07007106
7107 @Override
7108 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007109 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007110 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111
7112 final long identity = Binder.clearCallingIdentity();
7113 try {
7114 final Phone phone = getPhone(subId);
7115 if (phone == null) {
7116 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7117 return;
7118 }
chen xueaba88a2019-03-15 13:15:10 -07007119 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7120 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121 } finally {
7122 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007123 }
fionaxua13278b2018-03-21 00:08:13 -07007124 }
7125
7126 @Override
7127 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007128 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007129
7130 final long identity = Binder.clearCallingIdentity();
7131 try {
7132 final Phone phone = getPhone(subId);
7133 if (phone == null) {
7134 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7135 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7136 }
7137 return phone.getCarrierIdListVersion();
7138 } finally {
7139 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007140 }
fionaxua13278b2018-03-21 00:08:13 -07007141 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007142
7143 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007144 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7145 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007146 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007147 mApp, subId, callingPackage, callingFeatureId,
7148 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007149 return -1;
7150 }
7151
7152 final long identity = Binder.clearCallingIdentity();
7153 try {
7154 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7155 } finally {
7156 Binder.restoreCallingIdentity(identity);
7157 }
7158 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007159
7160 @Override
7161 public int getCdmaRoamingMode(int subId) {
7162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7163 mApp, subId, "getCdmaRoamingMode");
7164
7165 final long identity = Binder.clearCallingIdentity();
7166 try {
7167 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7168 } finally {
7169 Binder.restoreCallingIdentity(identity);
7170 }
7171 }
7172
7173 @Override
7174 public boolean setCdmaRoamingMode(int subId, int mode) {
7175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7176 mApp, subId, "setCdmaRoamingMode");
7177
7178 final long identity = Binder.clearCallingIdentity();
7179 try {
7180 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7181 } finally {
7182 Binder.restoreCallingIdentity(identity);
7183 }
7184 }
7185
7186 @Override
7187 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7189 mApp, subId, "setCdmaSubscriptionMode");
7190
7191 final long identity = Binder.clearCallingIdentity();
7192 try {
7193 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7194 } finally {
7195 Binder.restoreCallingIdentity(identity);
7196 }
7197 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007198
sqianc5eccab2018-10-19 18:46:41 -07007199 @Override
sqian8c685422019-02-22 15:55:18 -08007200 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007201 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007202 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007203 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7204 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007205 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7206 }
7207 final long identity = Binder.clearCallingIdentity();
7208 try {
sqian854d44b2018-12-12 16:48:18 -08007209 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7210 for (Phone phone: PhoneFactory.getPhones()) {
7211 if (phone.getEmergencyNumberTracker() != null
7212 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7213 emergencyNumberListInternal.put(
7214 phone.getSubId(),
7215 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7216 }
sqian11b7a0e2018-12-05 18:48:28 -08007217 }
sqian854d44b2018-12-12 16:48:18 -08007218 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007219 } finally {
7220 Binder.restoreCallingIdentity(identity);
7221 }
sqianc5eccab2018-10-19 18:46:41 -07007222 }
7223
7224 @Override
sqian8c685422019-02-22 15:55:18 -08007225 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007226 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007227 if (!exactMatch) {
7228 TelephonyPermissions
7229 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007230 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007231 }
7232 final long identity = Binder.clearCallingIdentity();
7233 try {
sqian854d44b2018-12-12 16:48:18 -08007234 for (Phone phone: PhoneFactory.getPhones()) {
7235 if (phone.getEmergencyNumberTracker() != null
7236 && phone.getEmergencyNumberTracker() != null) {
7237 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7238 number, exactMatch)) {
7239 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007240 }
7241 }
sqian11b7a0e2018-12-05 18:48:28 -08007242 }
7243 return false;
7244 } finally {
7245 Binder.restoreCallingIdentity(identity);
7246 }
7247 }
7248
sqianf4ca7ed2019-01-15 18:32:07 -08007249 /**
7250 * Update emergency number list for test mode.
7251 */
7252 @Override
7253 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7254 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7255 "updateEmergencyNumberListTestMode");
7256
7257 final long identity = Binder.clearCallingIdentity();
7258 try {
7259 for (Phone phone: PhoneFactory.getPhones()) {
7260 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7261 if (tracker != null) {
7262 tracker.executeEmergencyNumberTestModeCommand(action, num);
7263 }
7264 }
7265 } finally {
7266 Binder.restoreCallingIdentity(identity);
7267 }
7268 }
7269
7270 /**
7271 * Get the full emergency number list for test mode.
7272 */
7273 @Override
7274 public List<String> getEmergencyNumberListTestMode() {
7275 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7276 "getEmergencyNumberListTestMode");
7277
7278 final long identity = Binder.clearCallingIdentity();
7279 try {
7280 Set<String> emergencyNumbers = new HashSet<>();
7281 for (Phone phone: PhoneFactory.getPhones()) {
7282 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7283 if (tracker != null) {
7284 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7285 emergencyNumbers.add(num.getNumber());
7286 }
7287 }
7288 }
7289 return new ArrayList<>(emergencyNumbers);
7290 } finally {
7291 Binder.restoreCallingIdentity(identity);
7292 }
7293 }
7294
chen xud6b45bd2018-10-30 22:27:10 -07007295 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007296 public int getEmergencyNumberDbVersion(int subId) {
7297 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7298
7299 final long identity = Binder.clearCallingIdentity();
7300 try {
7301 final Phone phone = getPhone(subId);
7302 if (phone == null) {
7303 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7304 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7305 }
7306 return phone.getEmergencyNumberDbVersion();
7307 } finally {
7308 Binder.restoreCallingIdentity(identity);
7309 }
7310 }
7311
7312 @Override
7313 public void notifyOtaEmergencyNumberDbInstalled() {
7314 enforceModifyPermission();
7315
7316 final long identity = Binder.clearCallingIdentity();
7317 try {
7318 for (Phone phone: PhoneFactory.getPhones()) {
7319 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7320 if (tracker != null) {
7321 tracker.updateOtaEmergencyNumberDatabase();
7322 }
7323 }
7324 } finally {
7325 Binder.restoreCallingIdentity(identity);
7326 }
7327 }
7328
7329 @Override
7330 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7331 enforceActiveEmergencySessionPermission();
7332
7333 final long identity = Binder.clearCallingIdentity();
7334 try {
7335 for (Phone phone: PhoneFactory.getPhones()) {
7336 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7337 if (tracker != null) {
7338 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7339 }
7340 }
7341 } finally {
7342 Binder.restoreCallingIdentity(identity);
7343 }
7344 }
7345
7346 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007347 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7348 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7349 Phone phone = getPhone(subId);
7350 if (phone == null) {
7351 return null;
7352 }
7353 final long identity = Binder.clearCallingIdentity();
7354 try {
7355 UiccProfile profile = UiccController.getInstance()
7356 .getUiccProfileForPhone(phone.getPhoneId());
7357 if (profile != null) {
7358 return profile.getCertsFromCarrierPrivilegeAccessRules();
7359 }
7360 } finally {
7361 Binder.restoreCallingIdentity(identity);
7362 }
7363 return null;
7364 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007365
7366 /**
7367 * Enable or disable a modem stack.
7368 */
7369 @Override
7370 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7371 enforceModifyPermission();
7372
7373 final long identity = Binder.clearCallingIdentity();
7374 try {
7375 Phone phone = PhoneFactory.getPhone(slotIndex);
7376 if (phone == null) {
7377 return false;
7378 } else {
7379 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7380 }
7381 } finally {
7382 Binder.restoreCallingIdentity(identity);
7383 }
7384 }
Michelecea4cf22018-12-21 15:00:11 -08007385
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007386 /**
7387 * Whether a modem stack is enabled or not.
7388 */
7389 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007390 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7391 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007392 Phone phone = PhoneFactory.getPhone(slotIndex);
7393 if (phone == null) return false;
7394
7395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007396 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7397 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007398 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7399 }
7400
7401 final long identity = Binder.clearCallingIdentity();
7402 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007403 try {
7404 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7405 } catch (NoSuchElementException ex) {
7406 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7407 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007408 } finally {
7409 Binder.restoreCallingIdentity(identity);
7410 }
7411 }
7412
Michelecea4cf22018-12-21 15:00:11 -08007413 @Override
Michele0ea7d782019-03-19 14:58:42 -07007414 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007415 enforceModifyPermission();
7416
7417 final long identity = Binder.clearCallingIdentity();
7418 try {
7419 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007420 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007421 .commit();
7422 } finally {
7423 Binder.restoreCallingIdentity(identity);
7424 }
7425 }
7426
7427 @Override
Michele0ea7d782019-03-19 14:58:42 -07007428 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007429 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007430 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007431 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7432 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007433 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007434 }
Michelecea4cf22018-12-21 15:00:11 -08007435
7436 final long identity = Binder.clearCallingIdentity();
7437 try {
Michele0ea7d782019-03-19 14:58:42 -07007438 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007439 } finally {
7440 Binder.restoreCallingIdentity(identity);
7441 }
7442 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007443
Michele0ea7d782019-03-19 14:58:42 -07007444 @TelephonyManager.IsMultiSimSupportedResult
7445 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007446 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7447 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7448 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007449 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7450 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007451 }
7452 // Check if the hardware supports multisim functionality. If usage of multisim is not
7453 // supported by the modem, indicate that it is restricted.
7454 PhoneCapability staticCapability =
7455 mPhoneConfigurationManager.getStaticPhoneCapability();
7456 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007457 loge("isMultiSimSupportedInternal: no static configuration available");
7458 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007459 }
7460 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007461 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7462 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007463 }
7464 // Check if support of multiple SIMs is restricted by carrier
7465 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007466 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007467 }
7468
Michele0ea7d782019-03-19 14:58:42 -07007469 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007470 }
7471
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007472 /**
7473 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007474 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7475 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7476 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007477 * @param numOfSims number of active sims we want to switch to
7478 */
7479 @Override
7480 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007481 if (numOfSims == 1) {
7482 enforceModifyPermission();
7483 } else {
7484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7485 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7486 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007487 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007488
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007489 try {
Michele30b57b22019-03-01 12:01:14 -08007490 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007491 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007492 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7493 return;
7494 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007495 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7496 } finally {
7497 Binder.restoreCallingIdentity(identity);
7498 }
7499 }
7500
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007501 @Override
7502 public boolean isApplicationOnUicc(int subId, int appType) {
7503 enforceReadPrivilegedPermission("isApplicationOnUicc");
7504 Phone phone = getPhone(subId);
7505 if (phone == null) {
7506 return false;
7507 }
7508 final long identity = Binder.clearCallingIdentity();
7509 try {
7510 UiccCard uiccCard = phone.getUiccCard();
7511 if (uiccCard == null) {
7512 return false;
7513 }
7514 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7515 if (uiccProfile == null) {
7516 return false;
7517 }
7518 if (TelephonyManager.APPTYPE_SIM <= appType
7519 && appType <= TelephonyManager.APPTYPE_ISIM) {
7520 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7521 }
7522 return false;
7523 } finally {
7524 Binder.restoreCallingIdentity(identity);
7525 }
7526 }
7527
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007528 /**
chen xub4baa772019-04-03 10:23:41 -07007529 * Get whether making changes to modem configurations will trigger reboot.
7530 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007531 */
7532 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007533 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7534 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007535 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007536 mApp, subId, callingPackage, callingFeatureId,
7537 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007538 return false;
7539 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007540 final long identity = Binder.clearCallingIdentity();
7541 try {
7542 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7543 } finally {
7544 Binder.restoreCallingIdentity(identity);
7545 }
7546 }
7547
Nathan Harold29f5f052019-02-15 13:41:57 -08007548 private void updateModemStateMetrics() {
7549 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7550 // TODO: check the state for each modem if the api is ready.
7551 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7552 }
7553
Pengquan Meng3889a572019-01-23 11:16:29 -08007554 @Override
7555 public int[] getSlotsMapping() {
7556 enforceReadPrivilegedPermission("getSlotsMapping");
7557
7558 final long identity = Binder.clearCallingIdentity();
7559 try {
7560 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7561 // All logical slots should have a mapping to a physical slot.
7562 int[] logicalSlotsMapping = new int[phoneCount];
7563 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7564 for (int i = 0; i < slotInfos.length; i++) {
7565 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7566 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7567 }
7568 }
7569 return logicalSlotsMapping;
7570 } finally {
7571 Binder.restoreCallingIdentity(identity);
7572 }
7573 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007574
7575 /**
7576 * Get the IRadio HAL Version
7577 */
7578 @Override
7579 public int getRadioHalVersion() {
7580 Phone phone = getDefaultPhone();
7581 if (phone == null) return -1;
7582 HalVersion hv = phone.getHalVersion();
7583 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7584 return hv.major * 100 + hv.minor;
7585 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007586
7587 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007588 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7589 * corresponding network requests on a subId.
7590 *
7591 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007592 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007593 * 2) APN is un-metered for this subscription, or
7594 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007595 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007596 *
7597 * @return whether data is allowed for a apn type.
7598 *
7599 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007600 */
7601 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007602 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007603 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7604 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007605
7606 // Now that all security checks passes, perform the operation as ourselves.
7607 final long identity = Binder.clearCallingIdentity();
7608 try {
7609 Phone phone = getPhone(subId);
7610 if (phone == null) return false;
7611
Jack Yu41407ee2019-05-13 16:54:09 -07007612 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007613 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7614 } finally {
7615 Binder.restoreCallingIdentity(identity);
7616 }
7617 }
7618
7619 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007620 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007621 enforceReadPrivilegedPermission("isApnMetered");
7622
7623 // Now that all security checks passes, perform the operation as ourselves.
7624 final long identity = Binder.clearCallingIdentity();
7625 try {
7626 Phone phone = getPhone(subId);
7627 if (phone == null) return true; // By default return true.
7628
Jack Yu41407ee2019-05-13 16:54:09 -07007629 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007630 } finally {
7631 Binder.restoreCallingIdentity(identity);
7632 }
7633 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007634
7635 @Override
7636 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7637 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7638 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7639 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7640 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7641 }
7642 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7643 Intent intent = new Intent();
7644 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7645 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7646 // Bring up choose default SMS subscription dialog right now
7647 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7648 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7649 mApp.startActivity(intent);
7650 }
chen xud5ca2d52019-05-28 15:20:57 -07007651
7652 @Override
7653 public String getMmsUAProfUrl(int subId) {
7654 //TODO investigate if this API should require proper permission check in R b/133791609
7655 final long identity = Binder.clearCallingIdentity();
7656 try {
7657 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7658 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7659 } finally {
7660 Binder.restoreCallingIdentity(identity);
7661 }
7662 }
7663
7664 @Override
7665 public String getMmsUserAgent(int subId) {
7666 //TODO investigate if this API should require proper permission check in R b/133791609
7667 final long identity = Binder.clearCallingIdentity();
7668 try {
7669 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7670 .getString(com.android.internal.R.string.config_mms_user_agent);
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
7673 }
7674 }
Jack Yub07d4972019-05-28 16:12:25 -07007675
7676 @Override
7677 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7678 enforceModifyPermission();
7679
7680 // Now that all security checks passes, perform the operation as ourselves.
7681 final long identity = Binder.clearCallingIdentity();
7682 try {
7683 Phone phone = getPhone(subId);
7684 if (phone == null) return false;
7685
7686 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7687 } finally {
7688 Binder.restoreCallingIdentity(identity);
7689 }
7690 }
7691
7692 @Override
7693 public boolean isDataAllowedInVoiceCall(int subId) {
7694 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7695
7696 // Now that all security checks passes, perform the operation as ourselves.
7697 final long identity = Binder.clearCallingIdentity();
7698 try {
7699 Phone phone = getPhone(subId);
7700 if (phone == null) return false;
7701
7702 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7703 } finally {
7704 Binder.restoreCallingIdentity(identity);
7705 }
7706 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007707
changbettyd5c246e2019-12-24 15:40:37 +08007708 @Override
7709 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
7710 enforceModifyPermission();
7711
7712 // Now that all security checks passes, perform the operation as ourselves.
7713 final long identity = Binder.clearCallingIdentity();
7714 try {
7715 Phone phone = getPhone(subId);
7716 if (phone == null) return false;
7717
7718 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
7719 } finally {
7720 Binder.restoreCallingIdentity(identity);
7721 }
7722 }
7723
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007724 /**
7725 * Updates whether conference event pacakge handling is enabled.
7726 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7727 * otherwise.
7728 */
7729 @Override
7730 public void setCepEnabled(boolean isCepEnabled) {
7731 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7732
7733 final long identity = Binder.clearCallingIdentity();
7734 try {
7735 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7736 for (Phone phone : PhoneFactory.getPhones()) {
7737 Phone defaultPhone = phone.getImsPhone();
7738 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7739 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7740 ImsPhoneCallTracker imsPhoneCallTracker =
7741 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7742 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7743 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7744 + imsPhone.getMsisdn());
7745 }
7746 }
7747 } finally {
7748 Binder.restoreCallingIdentity(identity);
7749 }
7750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007751}