blob: 3a091caa9e4c264d6ed6a3e8bbd728ae3cf21de6 [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;
Stuart Scott981d8582015-04-21 14:09:50 -0700280 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private AppOpsManager mAppOps;
282 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800283 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700285 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286
Derek Tan97ebb422014-09-05 16:55:38 -0700287 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
288 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800289 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800290 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700291
Michelecea4cf22018-12-21 15:00:11 -0800292 // String to store multi SIM allowed
293 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
294
Derek Tan740e1672017-06-27 14:56:27 -0700295 // The AID of ISD-R.
296 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
297
yinxub1bed742017-04-17 11:45:04 -0700298 private NetworkScanRequestTracker mNetworkScanRequestTracker;
299
David Kelly5e06a7f2018-03-12 14:10:59 +0000300 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
301 private static final int MANUFACTURER_CODE_LENGTH = 8;
302
Derek Tan89e89d42014-07-08 17:00:10 -0700303 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700304 * Experiment flag to enable erase modem config on reset network, default value is false
305 */
306 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
307 "reset_network_erase_modem_config_enabled";
308
309 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700310 * A request object to use for transmitting data to an ICC.
311 */
312 private static final class IccAPDUArgument {
313 public int channel, cla, command, p1, p2, p3;
314 public String data;
315
316 public IccAPDUArgument(int channel, int cla, int command,
317 int p1, int p2, int p3, String data) {
318 this.channel = channel;
319 this.cla = cla;
320 this.command = command;
321 this.p1 = p1;
322 this.p2 = p2;
323 this.p3 = p3;
324 this.data = data;
325 }
326 }
327
328 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700329 * A request object to use for transmitting data to an ICC.
330 */
331 private static final class ManualNetworkSelectionArgument {
332 public OperatorInfo operatorInfo;
333 public boolean persistSelection;
334
335 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
336 this.operatorInfo = operatorInfo;
337 this.persistSelection = persistSelection;
338 }
339 }
340
341 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
343 * request after sending. The main thread will notify the request when it is complete.
344 */
345 private static final class MainThreadRequest {
346 /** The argument to use for the request */
347 public Object argument;
348 /** The result of the request that is run on the main thread */
349 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800350 // The subscriber id that this request applies to. Defaults to
351 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
352 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353
Nathan Harold92bed182018-10-12 18:16:49 -0700354 // In cases where subId is unavailable, the caller needs to specify the phone.
355 public Phone phone;
356
vagdeviaf9a5b92018-08-15 16:01:53 -0700357 public WorkSource workSource;
358
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 public MainThreadRequest(Object argument) {
360 this.argument = argument;
361 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800362
Nathan Harold92bed182018-10-12 18:16:49 -0700363 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
364 this.argument = argument;
365 if (phone != null) {
366 this.phone = phone;
367 }
368 this.workSource = workSource;
369 }
370
vagdeviaf9a5b92018-08-15 16:01:53 -0700371 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800372 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800373 if (subId != null) {
374 this.subId = subId;
375 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700376 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 }
379
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800380 private static final class IncomingThirdPartyCallArgs {
381 public final ComponentName component;
382 public final String callId;
383 public final String callerDisplayName;
384
385 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
386 String callerDisplayName) {
387 this.component = component;
388 this.callId = callId;
389 this.callerDisplayName = callerDisplayName;
390 }
391 }
392
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 /**
394 * A handler that processes messages on the main thread in the phone process. Since many
395 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
396 * inbound binder threads to the main thread in the phone process. The Binder thread
397 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
398 * on, which will be notified when the operation completes and will contain the result of the
399 * request.
400 *
401 * <p>If a MainThreadRequest object is provided in the msg.obj field,
402 * note that request.result must be set to something non-null for the calling thread to
403 * unblock.
404 */
405 private final class MainThreadHandler extends Handler {
406 @Override
407 public void handleMessage(Message msg) {
408 MainThreadRequest request;
409 Message onCompleted;
410 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800411 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800413 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414
415 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700416 case CMD_HANDLE_USSD_REQUEST: {
417 request = (MainThreadRequest) msg.obj;
418 final Phone phone = getPhoneFromRequest(request);
419 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
420 String ussdRequest = ussdObject.first;
421 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700422
Pengquan Menga1bb6272018-09-06 09:59:22 -0700423 if (!isUssdApiAllowed(request.subId)) {
424 // Carrier does not support use of this API, return failure.
425 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
426 UssdResponse response = new UssdResponse(ussdRequest, null);
427 Bundle returnData = new Bundle();
428 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
429 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700430
Pengquan Menga1bb6272018-09-06 09:59:22 -0700431 request.result = true;
432 notifyRequester(request);
433 return;
434 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700435
Pengquan Menga1bb6272018-09-06 09:59:22 -0700436 try {
437 request.result = phone != null
438 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
439 } catch (CallStateException cse) {
440 request.result = false;
441 }
442 // Wake up the requesting thread
443 notifyRequester(request);
444 break;
pkanwar32d516d2016-10-14 19:37:38 -0700445 }
446
Yorke Lee716f67e2015-06-17 15:39:16 -0700447 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700449 final Phone phone = getPhoneFromRequest(request);
450 request.result = phone != null ?
451 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
452 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700453 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800461 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700462 if (uiccCard == null) {
463 loge("iccTransmitApduLogicalChannel: No UICC");
464 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
468 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700469 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 iccArgument.channel, iccArgument.cla, iccArgument.command,
471 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700473 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 break;
475
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 ar = (AsyncResult) msg.obj;
478 request = (MainThreadRequest) ar.userObj;
479 if (ar.exception == null && ar.result != null) {
480 request.result = ar.result;
481 } else {
482 request.result = new IccIoResult(0x6F, 0, (byte[])null);
483 if (ar.result == null) {
484 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800485 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700486 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800487 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 } else {
489 loge("iccTransmitApduLogicalChannel: Unknown exception");
490 }
491 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700493 break;
494
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
496 request = (MainThreadRequest) msg.obj;
497 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800498 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 if (uiccCard == null) {
500 loge("iccTransmitApduBasicChannel: No UICC");
501 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 } else {
504 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
505 request);
506 uiccCard.iccTransmitApduBasicChannel(
507 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
508 iccArgument.p3, iccArgument.data, onCompleted);
509 }
510 break;
511
512 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
513 ar = (AsyncResult) msg.obj;
514 request = (MainThreadRequest) ar.userObj;
515 if (ar.exception == null && ar.result != null) {
516 request.result = ar.result;
517 } else {
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
519 if (ar.result == null) {
520 loge("iccTransmitApduBasicChannel: Empty response");
521 } else if (ar.exception instanceof CommandException) {
522 loge("iccTransmitApduBasicChannel: CommandException: " +
523 ar.exception);
524 } else {
525 loge("iccTransmitApduBasicChannel: Unknown exception");
526 }
527 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 break;
530
531 case CMD_EXCHANGE_SIM_IO:
532 request = (MainThreadRequest) msg.obj;
533 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800534 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 if (uiccCard == null) {
536 loge("iccExchangeSimIO: No UICC");
537 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700538 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 } else {
540 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
541 request);
542 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
543 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
544 iccArgument.data, onCompleted);
545 }
546 break;
547
548 case EVENT_EXCHANGE_SIM_IO_DONE:
549 ar = (AsyncResult) msg.obj;
550 request = (MainThreadRequest) ar.userObj;
551 if (ar.exception == null && ar.result != null) {
552 request.result = ar.result;
553 } else {
554 request.result = new IccIoResult(0x6f, 0, (byte[])null);
555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 break;
558
Derek Tan4d5e5c12014-02-04 11:54:58 -0800559 case CMD_SEND_ENVELOPE:
560 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800561 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 if (uiccCard == null) {
563 loge("sendEnvelopeWithStatus: No UICC");
564 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 } else {
567 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
568 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
569 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800570 break;
571
572 case EVENT_SEND_ENVELOPE_DONE:
573 ar = (AsyncResult) msg.obj;
574 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700575 if (ar.exception == null && ar.result != null) {
576 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
579 if (ar.result == null) {
580 loge("sendEnvelopeWithStatus: Empty response");
581 } else if (ar.exception instanceof CommandException) {
582 loge("sendEnvelopeWithStatus: CommandException: " +
583 ar.exception);
584 } else {
585 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
586 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800587 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800589 break;
590
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 case CMD_OPEN_CHANNEL:
592 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800593 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800594 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 if (uiccCard == null) {
596 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800597 request.result = new IccOpenLogicalChannelResponse(-1,
598 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 } else {
601 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800602 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
603 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 break;
606
607 case EVENT_OPEN_CHANNEL_DONE:
608 ar = (AsyncResult) msg.obj;
609 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 int[] result = (int[]) ar.result;
613 int channelId = result[0];
614 byte[] selectResponse = null;
615 if (result.length > 1) {
616 selectResponse = new byte[result.length - 1];
617 for (int i = 1; i < result.length; ++i) {
618 selectResponse[i - 1] = (byte) result[i];
619 }
620 }
621 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 if (ar.result == null) {
625 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 if (ar.exception != null) {
628 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
629 }
630
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700631 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700632 if (ar.exception instanceof CommandException) {
633 CommandException.Error error =
634 ((CommandException) (ar.exception)).getCommandError();
635 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700636 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700637 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700638 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 }
640 }
641 openChannelResp = new IccOpenLogicalChannelResponse(
642 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700644 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 break;
647
648 case CMD_CLOSE_CHANNEL:
649 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800650 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 if (uiccCard == null) {
652 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900653 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
657 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
658 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 break;
660
661 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800662 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
663 break;
664
665 case CMD_NV_READ_ITEM:
666 request = (MainThreadRequest) msg.obj;
667 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800668 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
669 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800670 break;
671
672 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 ar = (AsyncResult) msg.obj;
674 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800675 if (ar.exception == null && ar.result != null) {
676 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800678 request.result = "";
679 if (ar.result == null) {
680 loge("nvReadItem: Empty response");
681 } else if (ar.exception instanceof CommandException) {
682 loge("nvReadItem: CommandException: " +
683 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800685 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 }
687 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700688 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 break;
690
Jake Hambye994d462014-02-03 13:10:13 -0800691 case CMD_NV_WRITE_ITEM:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
694 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800695 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700696 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800697 break;
698
699 case EVENT_NV_WRITE_ITEM_DONE:
700 handleNullReturnEvent(msg, "nvWriteItem");
701 break;
702
703 case CMD_NV_WRITE_CDMA_PRL:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800706 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800707 break;
708
709 case EVENT_NV_WRITE_CDMA_PRL_DONE:
710 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
711 break;
712
chen xu6dac5ab2018-10-26 17:39:23 -0700713 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800714 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700715 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800716 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800717 break;
718
chen xu6dac5ab2018-10-26 17:39:23 -0700719 case EVENT_RESET_MODEM_CONFIG_DONE:
720 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800721 break;
722
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 case CMD_GET_PREFERRED_NETWORK_TYPE:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700726 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 break;
728
729 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
730 ar = (AsyncResult) msg.obj;
731 request = (MainThreadRequest) ar.userObj;
732 if (ar.exception == null && ar.result != null) {
733 request.result = ar.result; // Integer
734 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800735 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800736 if (ar.result == null) {
737 loge("getPreferredNetworkType: Empty response");
738 } else if (ar.exception instanceof CommandException) {
739 loge("getPreferredNetworkType: CommandException: " +
740 ar.exception);
741 } else {
742 loge("getPreferredNetworkType: Unknown exception");
743 }
744 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800746 break;
747
748 case CMD_SET_PREFERRED_NETWORK_TYPE:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
751 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700752 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800753 break;
754
755 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
756 handleNullReturnEvent(msg, "setPreferredNetworkType");
757 break;
758
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000759 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
760 request = (MainThreadRequest)msg.obj;
761 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800762 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000763 break;
764
765 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
766 ar = (AsyncResult)msg.obj;
767 request = (MainThreadRequest)ar.userObj;
768 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000770 break;
771
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800772 case CMD_SET_VOICEMAIL_NUMBER:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
775 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800776 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
777 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800778 break;
779
780 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
781 handleNullReturnEvent(msg, "setVoicemailNumber");
782 break;
783
Stuart Scott54788802015-03-30 13:18:01 -0700784 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
785 request = (MainThreadRequest) msg.obj;
786 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
787 request);
788 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
789 break;
790
791 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
792 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
793 break;
794
Shishir Agrawal302c8692015-06-19 13:49:39 -0700795 case CMD_PERFORM_NETWORK_SCAN:
796 request = (MainThreadRequest) msg.obj;
797 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
798 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
799 break;
800
801 case EVENT_PERFORM_NETWORK_SCAN_DONE:
802 ar = (AsyncResult) msg.obj;
803 request = (MainThreadRequest) ar.userObj;
804 CellNetworkScanResult cellScanResult;
805 if (ar.exception == null && ar.result != null) {
806 cellScanResult = new CellNetworkScanResult(
807 CellNetworkScanResult.STATUS_SUCCESS,
808 (List<OperatorInfo>) ar.result);
809 } else {
810 if (ar.result == null) {
811 loge("getCellNetworkScanResults: Empty response");
812 }
813 if (ar.exception != null) {
814 loge("getCellNetworkScanResults: Exception: " + ar.exception);
815 }
816 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
817 if (ar.exception instanceof CommandException) {
818 CommandException.Error error =
819 ((CommandException) (ar.exception)).getCommandError();
820 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
821 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
822 } else if (error == CommandException.Error.GENERIC_FAILURE) {
823 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
824 }
825 }
826 cellScanResult = new CellNetworkScanResult(errorCode, null);
827 }
828 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700829 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 break;
831
832 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
833 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700834 ManualNetworkSelectionArgument selArg =
835 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700836 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
837 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700838 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
839 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 break;
841
842 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700843 ar = (AsyncResult) msg.obj;
844 request = (MainThreadRequest) ar.userObj;
845 if (ar.exception == null) {
846 request.result = true;
847 } else {
848 request.result = false;
849 loge("setNetworkSelectionModeManual " + ar.exception);
850 }
851 notifyRequester(request);
852 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700853 break;
854
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700855 case CMD_GET_MODEM_ACTIVITY_INFO:
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700858 if (defaultPhone != null) {
859 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
860 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700861 break;
862
863 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
864 ar = (AsyncResult) msg.obj;
865 request = (MainThreadRequest) ar.userObj;
866 if (ar.exception == null && ar.result != null) {
867 request.result = ar.result;
868 } else {
869 if (ar.result == null) {
870 loge("queryModemActivityInfo: Empty response");
871 } else if (ar.exception instanceof CommandException) {
872 loge("queryModemActivityInfo: CommandException: " +
873 ar.exception);
874 } else {
875 loge("queryModemActivityInfo: Unknown exception");
876 }
877 }
Amit Mahajand4766222016-01-28 15:28:28 -0800878 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
879 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800880 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800881 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700882 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700883 break;
884
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 case CMD_SET_ALLOWED_CARRIERS:
886 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800887 CarrierRestrictionRules argument =
888 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800890 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 break;
892
893 case EVENT_SET_ALLOWED_CARRIERS_DONE:
894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result;
898 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800899 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
900 if (ar.exception instanceof CommandException) {
901 loge("setAllowedCarriers: CommandException: " + ar.exception);
902 CommandException.Error error =
903 ((CommandException) (ar.exception)).getCommandError();
904 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
905 request.result =
906 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
907 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700908 } else {
909 loge("setAllowedCarriers: Unknown exception");
910 }
911 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700912 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700913 break;
914
915 case CMD_GET_ALLOWED_CARRIERS:
916 request = (MainThreadRequest) msg.obj;
917 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800918 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700919 break;
920
921 case EVENT_GET_ALLOWED_CARRIERS_DONE:
922 ar = (AsyncResult) msg.obj;
923 request = (MainThreadRequest) ar.userObj;
924 if (ar.exception == null && ar.result != null) {
925 request.result = ar.result;
926 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800927 request.result = new IllegalStateException(
928 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700929 if (ar.result == null) {
930 loge("getAllowedCarriers: Empty response");
931 } else if (ar.exception instanceof CommandException) {
932 loge("getAllowedCarriers: CommandException: " +
933 ar.exception);
934 } else {
935 loge("getAllowedCarriers: Unknown exception");
936 }
937 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700938 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700939 break;
940
Nathan Haroldb3014052017-01-25 15:57:32 -0800941 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
942 ar = (AsyncResult) msg.obj;
943 request = (MainThreadRequest) ar.userObj;
944 if (ar.exception == null && ar.result != null) {
945 request.result = ar.result;
946 } else {
947 request.result = new IllegalArgumentException(
948 "Failed to retrieve Forbidden Plmns");
949 if (ar.result == null) {
950 loge("getForbiddenPlmns: Empty response");
951 } else {
952 loge("getForbiddenPlmns: Unknown exception");
953 }
954 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700955 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800956 break;
957
958 case CMD_GET_FORBIDDEN_PLMNS:
959 request = (MainThreadRequest) msg.obj;
960 uiccCard = getUiccCardFromRequest(request);
961 if (uiccCard == null) {
962 loge("getForbiddenPlmns() UiccCard is null");
963 request.result = new IllegalArgumentException(
964 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700965 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800966 break;
967 }
968 Integer appType = (Integer) request.argument;
969 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
970 if (uiccApp == null) {
971 loge("getForbiddenPlmns() no app with specified type -- "
972 + appType);
973 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700974 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800975 break;
976 } else {
977 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
978 + " specified type -- " + appType);
979 }
980 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
981 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
982 onCompleted);
983 break;
984
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000985 case CMD_SWITCH_SLOTS:
986 request = (MainThreadRequest) msg.obj;
987 int[] physicalSlots = (int[]) request.argument;
988 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
989 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
990 break;
991
992 case EVENT_SWITCH_SLOTS_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700996 notifyRequester(request);
997 break;
998 case CMD_GET_NETWORK_SELECTION_MODE:
999 request = (MainThreadRequest) msg.obj;
1000 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1001 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1002 break;
1003
1004 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1005 ar = (AsyncResult) msg.obj;
1006 request = (MainThreadRequest) ar.userObj;
1007 if (ar.exception != null) {
1008 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1009 } else {
1010 int mode = ((int[]) ar.result)[0];
1011 if (mode == 0) {
1012 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1013 } else {
1014 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1015 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001016 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001017 notifyRequester(request);
1018 break;
1019 case CMD_GET_CDMA_ROAMING_MODE:
1020 request = (MainThreadRequest) msg.obj;
1021 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1022 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1023 break;
1024 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception != null) {
1028 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1029 } else {
1030 request.result = ((int[]) ar.result)[0];
1031 }
1032 notifyRequester(request);
1033 break;
1034 case CMD_SET_CDMA_ROAMING_MODE:
1035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1037 int mode = (int) request.argument;
1038 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1039 break;
1040 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 request.result = ar.exception == null;
1044 notifyRequester(request);
1045 break;
1046 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1049 int subscriptionMode = (int) request.argument;
1050 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1051 break;
1052 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1053 ar = (AsyncResult) msg.obj;
1054 request = (MainThreadRequest) ar.userObj;
1055 request.result = ar.exception == null;
1056 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001057 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001058 case CMD_GET_ALL_CELL_INFO:
1059 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001061 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 case EVENT_GET_ALL_CELL_INFO_DONE:
1064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001066 // If a timeout occurs, the response will be null
1067 request.result = (ar.exception == null && ar.result != null)
1068 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001069 synchronized (request) {
1070 request.notifyAll();
1071 }
1072 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001073 case CMD_REQUEST_CELL_INFO_UPDATE:
1074 request = (MainThreadRequest) msg.obj;
1075 request.phone.requestCellInfoUpdate(request.workSource,
1076 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1077 break;
1078 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1079 ar = (AsyncResult) msg.obj;
1080 request = (MainThreadRequest) ar.userObj;
1081 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1082 try {
1083 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001085 cb.onError(
1086 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1087 ar.exception.getClass().getName(),
1088 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001089 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001090 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001091 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 } else {
1093 // use the result as returned
1094 cb.onCellInfo((List<CellInfo>) ar.result);
1095 }
1096 } catch (RemoteException re) {
1097 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1098 }
1099 break;
1100 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001101 request = (MainThreadRequest) msg.obj;
1102 WorkSource ws = (WorkSource) request.argument;
1103 Phone phone = getPhoneFromRequest(request);
1104 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1105 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001106 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001107 ar = (AsyncResult) msg.obj;
1108 request = (MainThreadRequest) ar.userObj;
1109 if (ar.exception == null) {
1110 request.result = ar.result;
1111 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001112 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001113 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1114 ? new CdmaCellLocation() : new GsmCellLocation();
1115 }
1116
1117 synchronized (request) {
1118 request.notifyAll();
1119 }
1120 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001121 case CMD_MODEM_REBOOT:
1122 request = (MainThreadRequest) msg.obj;
1123 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001124 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001125 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001126 case EVENT_CMD_MODEM_REBOOT_DONE:
1127 handleNullReturnEvent(msg, "rebootModem");
1128 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001129 case CMD_REQUEST_ENABLE_MODEM:
1130 request = (MainThreadRequest) msg.obj;
1131 boolean enable = (boolean) request.argument;
1132 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001133 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001134 PhoneConfigurationManager.getInstance()
1135 .enablePhone(request.phone, enable, onCompleted);
1136 break;
1137 case EVENT_ENABLE_MODEM_DONE:
1138 ar = (AsyncResult) msg.obj;
1139 request = (MainThreadRequest) ar.userObj;
1140 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001141 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001142 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001143 if ((boolean) request.result) {
1144 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1145 updateModemStateMetrics();
1146 } else {
1147 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1148 + ar.exception);
1149 }
1150 notifyRequester(request);
1151 break;
1152 case CMD_GET_MODEM_STATUS:
1153 request = (MainThreadRequest) msg.obj;
1154 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1155 PhoneConfigurationManager.getInstance()
1156 .getPhoneStatusFromModem(request.phone, onCompleted);
1157 break;
1158 case EVENT_GET_MODEM_STATUS_DONE:
1159 ar = (AsyncResult) msg.obj;
1160 request = (MainThreadRequest) ar.userObj;
1161 int id = request.phone.getPhoneId();
1162 if (ar.exception == null && ar.result != null) {
1163 request.result = ar.result;
1164 //update the cache as modem status has changed
1165 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1166 (boolean) request.result);
1167 } else {
1168 // Return true if modem status cannot be retrieved. For most cases,
1169 // modem status is on. And for older version modems, GET_MODEM_STATUS
1170 // and disable modem are not supported. Modem is always on.
1171 // TODO: this should be fixed in R to support a third
1172 // status UNKNOWN b/131631629
1173 request.result = true;
1174 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1175 + ar.exception);
1176 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001177 notifyRequester(request);
1178 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001179 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1180 ar = (AsyncResult) msg.obj;
1181 request = (MainThreadRequest) ar.userObj;
1182 if (ar.exception == null && ar.result != null) {
1183 request.result = ar.result;
1184 } else {
1185 request.result = -1;
1186 loge("Failed to set Forbidden Plmns");
1187 if (ar.result == null) {
1188 loge("setForbidenPlmns: Empty response");
1189 } else if (ar.exception != null) {
1190 loge("setForbiddenPlmns: Exception: " + ar.exception);
1191 request.result = -1;
1192 } else {
1193 loge("setForbiddenPlmns: Unknown exception");
1194 }
1195 }
1196 notifyRequester(request);
1197 break;
1198 case CMD_SET_FORBIDDEN_PLMNS:
1199 request = (MainThreadRequest) msg.obj;
1200 uiccCard = getUiccCardFromRequest(request);
1201 if (uiccCard == null) {
1202 loge("setForbiddenPlmns: UiccCard is null");
1203 request.result = -1;
1204 notifyRequester(request);
1205 break;
1206 }
1207 Pair<Integer, List<String>> setFplmnsArgs =
1208 (Pair<Integer, List<String>>) request.argument;
1209 appType = setFplmnsArgs.first;
1210 List<String> fplmns = setFplmnsArgs.second;
1211 uiccApp = uiccCard.getApplicationByType(appType);
1212 if (uiccApp == null) {
1213 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1214 request.result = -1;
1215 loge("Failed to get UICC App");
1216 notifyRequester(request);
1217 } else {
1218 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1219 ((SIMRecords) uiccApp.getIccRecords())
1220 .setForbiddenPlmns(onCompleted, fplmns);
1221 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001222 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001223 case CMD_ERASE_MODEM_CONFIG:
1224 request = (MainThreadRequest) msg.obj;
1225 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1226 defaultPhone.eraseModemConfig(onCompleted);
1227 break;
1228 case EVENT_ERASE_MODEM_CONFIG_DONE:
1229 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001230 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 default:
1232 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1233 break;
1234 }
1235 }
Jake Hambye994d462014-02-03 13:10:13 -08001236
Pengquan Menga1bb6272018-09-06 09:59:22 -07001237 private void notifyRequester(MainThreadRequest request) {
1238 synchronized (request) {
1239 request.notifyAll();
1240 }
1241 }
1242
Jake Hambye994d462014-02-03 13:10:13 -08001243 private void handleNullReturnEvent(Message msg, String command) {
1244 AsyncResult ar = (AsyncResult) msg.obj;
1245 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1246 if (ar.exception == null) {
1247 request.result = true;
1248 } else {
1249 request.result = false;
1250 if (ar.exception instanceof CommandException) {
1251 loge(command + ": CommandException: " + ar.exception);
1252 } else {
1253 loge(command + ": Unknown exception");
1254 }
1255 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001256 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 }
1259
1260 /**
1261 * Posts the specified command to be executed on the main thread,
1262 * waits for the request to complete, and returns the result.
1263 * @see #sendRequestAsync
1264 */
1265 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001266 return sendRequest(
1267 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001268 }
1269
1270 /**
1271 * Posts the specified command to be executed on the main thread,
1272 * waits for the request to complete, and returns the result.
1273 * @see #sendRequestAsync
1274 */
1275 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1276 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001277 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001278 }
1279
1280 /**
1281 * Posts the specified command to be executed on the main thread,
1282 * waits for the request to complete, and returns the result.
1283 * @see #sendRequestAsync
1284 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001285 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001286 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001287 }
1288
1289 /**
1290 * Posts the specified command to be executed on the main thread,
1291 * waits for the request to complete, and returns the result.
1292 * @see #sendRequestAsync
1293 */
Nathan Harold92bed182018-10-12 18:16:49 -07001294 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1295 return sendRequest(command, argument, subId, null, workSource);
1296 }
1297
1298 /**
1299 * Posts the specified command to be executed on the main thread,
1300 * waits for the request to complete, and returns the result.
1301 * @see #sendRequestAsync
1302 */
1303 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1304 return sendRequest(
1305 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1306 }
1307
1308 /**
1309 * Posts the specified command to be executed on the main thread,
1310 * waits for the request to complete, and returns the result.
1311 * @see #sendRequestAsync
1312 */
1313 private Object sendRequest(
1314 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1316 throw new RuntimeException("This method will deadlock if called from the main thread.");
1317 }
1318
Nathan Harold92bed182018-10-12 18:16:49 -07001319 MainThreadRequest request = null;
1320 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1321 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1322 } else if (phone != null) {
1323 request = new MainThreadRequest(argument, phone, workSource);
1324 } else {
1325 request = new MainThreadRequest(argument, subId, workSource);
1326 }
1327
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 Message msg = mMainThreadHandler.obtainMessage(command, request);
1329 msg.sendToTarget();
1330
1331 // Wait for the request to complete
1332 synchronized (request) {
1333 while (request.result == null) {
1334 try {
1335 request.wait();
1336 } catch (InterruptedException e) {
1337 // Do nothing, go back and wait until the request is complete
1338 }
1339 }
1340 }
1341 return request.result;
1342 }
1343
1344 /**
1345 * Asynchronous ("fire and forget") version of sendRequest():
1346 * Posts the specified command to be executed on the main thread, and
1347 * returns immediately.
1348 * @see #sendRequest
1349 */
1350 private void sendRequestAsync(int command) {
1351 mMainThreadHandler.sendEmptyMessage(command);
1352 }
1353
1354 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001355 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001356 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001357 */
1358 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 sendRequestAsync(command, argument, null, null);
1360 }
1361
1362 /**
1363 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1364 * @see {@link #sendRequest(int,Object)}
1365 */
1366 private void sendRequestAsync(
1367 int command, Object argument, Phone phone, WorkSource workSource) {
1368 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001369 Message msg = mMainThreadHandler.obtainMessage(command, request);
1370 msg.sendToTarget();
1371 }
1372
1373 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 * Initialize the singleton PhoneInterfaceManager instance.
1375 * This is only done once, at startup, from PhoneApp.onCreate().
1376 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001377 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 synchronized (PhoneInterfaceManager.class) {
1379 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001380 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 } else {
1382 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1383 }
1384 return sInstance;
1385 }
1386 }
1387
1388 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001389 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001390 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001392 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1394 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001395 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001396 mTelephonySharedPreferences =
1397 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001398 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001399 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001400
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001401 publish();
1402 }
1403
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001404 private Phone getDefaultPhone() {
1405 Phone thePhone = getPhone(getDefaultSubscription());
1406 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1407 }
1408
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001409 private void publish() {
1410 if (DBG) log("publish: " + this);
1411
1412 ServiceManager.addService("phone", this);
1413 }
1414
Stuart Scott584921c2015-01-15 17:10:34 -08001415 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001416 if (request.phone != null) {
1417 return request.phone;
1418 } else {
1419 return getPhoneFromSubId(request.subId);
1420 }
1421 }
1422
1423 private Phone getPhoneFromSubId(int subId) {
1424 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1425 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001426 }
1427
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001428 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1429 Phone phone = getPhoneFromRequest(request);
1430 return phone == null ? null :
1431 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1432 }
1433
Wink Saville36469e72014-06-11 15:17:00 -07001434 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001435 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001436 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001438
Naina Nallurid63128d2019-09-17 14:10:30 -07001439 private void sendEraseModemConfig(Phone phone) {
1440 if (phone != null) {
1441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1442 mApp, phone.getSubId(), "eraseModemConfig");
1443 final long identity = Binder.clearCallingIdentity();
1444 try {
1445 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1446 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1447 } finally {
1448 Binder.restoreCallingIdentity(identity);
1449 }
1450 }
1451 }
1452
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001453 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001455 }
1456
Wink Savilleb564aae2014-10-23 10:18:09 -07001457 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458 if (DBG) log("dial: " + number);
1459 // No permission check needed here: This is just a wrapper around the
1460 // ACTION_DIAL intent, which is available to any app since it puts up
1461 // the UI before it does anything.
1462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001463 final long identity = Binder.clearCallingIdentity();
1464 try {
1465 String url = createTelUrl(number);
1466 if (url == null) {
1467 return;
1468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001470 // PENDING: should we just silently fail if phone is offhook or ringing?
1471 PhoneConstants.State state = mCM.getState(subId);
1472 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1473 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1474 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1475 mApp.startActivity(intent);
1476 }
1477 } finally {
1478 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479 }
1480 }
1481
1482 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001483 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001484 }
1485
Wink Savilleb564aae2014-10-23 10:18:09 -07001486 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001487 if (DBG) log("call: " + number);
1488
1489 // This is just a wrapper around the ACTION_CALL intent, but we still
1490 // need to do a permission check since we're calling startActivity()
1491 // from the context of the phone app.
1492 enforceCallPermission();
1493
Jordan Liu1617b712019-07-10 15:06:26 -07001494 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001495 != AppOpsManager.MODE_ALLOWED) {
1496 return;
1497 }
1498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001499 final long identity = Binder.clearCallingIdentity();
1500 try {
1501 String url = createTelUrl(number);
1502 if (url == null) {
1503 return;
1504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001506 boolean isValid = false;
1507 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1508 if (slist != null) {
1509 for (SubscriptionInfo subInfoRecord : slist) {
1510 if (subInfoRecord.getSubscriptionId() == subId) {
1511 isValid = true;
1512 break;
1513 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001514 }
Wink Saville08874612014-08-31 19:19:58 -07001515 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001516 if (!isValid) {
1517 return;
1518 }
Wink Saville08874612014-08-31 19:19:58 -07001519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001520 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1521 intent.putExtra(SUBSCRIPTION_KEY, subId);
1522 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1523 mApp.startActivity(intent);
1524 } finally {
1525 Binder.restoreCallingIdentity(identity);
1526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527 }
1528
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001530 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001531 }
1532
Wink Savilleb564aae2014-10-23 10:18:09 -07001533 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001534 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001535 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1536 }
1537
1538 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001539 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001540 }
1541
Wink Savilleb564aae2014-10-23 10:18:09 -07001542 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001543 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001544 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1545 }
1546
1547 /** {@hide} */
1548 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001549 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001550 }
1551
Wink Savilleb564aae2014-10-23 10:18:09 -07001552 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001554
1555 final long identity = Binder.clearCallingIdentity();
1556 try {
1557 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1558 checkSimPin.start();
1559 return checkSimPin.unlockSim(null, pin);
1560 } finally {
1561 Binder.restoreCallingIdentity(identity);
1562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 }
1564
Wink Saville9de0f752013-10-22 19:04:03 -07001565 /** {@hide} */
1566 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001567 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001568 }
1569
Wink Savilleb564aae2014-10-23 10:18:09 -07001570 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001572
1573 final long identity = Binder.clearCallingIdentity();
1574 try {
1575 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1576 checkSimPuk.start();
1577 return checkSimPuk.unlockSim(puk, pin);
1578 } finally {
1579 Binder.restoreCallingIdentity(identity);
1580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 }
1582
1583 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001584 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001585 * a synchronous one.
1586 */
1587 private static class UnlockSim extends Thread {
1588
1589 private final IccCard mSimCard;
1590
1591 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001592 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1593 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594
1595 // For replies from SimCard interface
1596 private Handler mHandler;
1597
1598 // For async handler to identify request type
1599 private static final int SUPPLY_PIN_COMPLETE = 100;
1600
1601 public UnlockSim(IccCard simCard) {
1602 mSimCard = simCard;
1603 }
1604
1605 @Override
1606 public void run() {
1607 Looper.prepare();
1608 synchronized (UnlockSim.this) {
1609 mHandler = new Handler() {
1610 @Override
1611 public void handleMessage(Message msg) {
1612 AsyncResult ar = (AsyncResult) msg.obj;
1613 switch (msg.what) {
1614 case SUPPLY_PIN_COMPLETE:
1615 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1616 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001617 mRetryCount = msg.arg1;
1618 if (ar.exception != null) {
1619 if (ar.exception instanceof CommandException &&
1620 ((CommandException)(ar.exception)).getCommandError()
1621 == CommandException.Error.PASSWORD_INCORRECT) {
1622 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1623 } else {
1624 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1625 }
1626 } else {
1627 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 mDone = true;
1630 UnlockSim.this.notifyAll();
1631 }
1632 break;
1633 }
1634 }
1635 };
1636 UnlockSim.this.notifyAll();
1637 }
1638 Looper.loop();
1639 }
1640
1641 /*
1642 * Use PIN or PUK to unlock SIM card
1643 *
1644 * If PUK is null, unlock SIM card with PIN
1645 *
1646 * If PUK is not null, unlock SIM card with PUK and set PIN code
1647 */
Wink Saville9de0f752013-10-22 19:04:03 -07001648 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649
1650 while (mHandler == null) {
1651 try {
1652 wait();
1653 } catch (InterruptedException e) {
1654 Thread.currentThread().interrupt();
1655 }
1656 }
1657 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1658
1659 if (puk == null) {
1660 mSimCard.supplyPin(pin, callback);
1661 } else {
1662 mSimCard.supplyPuk(puk, pin, callback);
1663 }
1664
1665 while (!mDone) {
1666 try {
1667 Log.d(LOG_TAG, "wait for done");
1668 wait();
1669 } catch (InterruptedException e) {
1670 // Restore the interrupted status
1671 Thread.currentThread().interrupt();
1672 }
1673 }
1674 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001675 int[] resultArray = new int[2];
1676 resultArray[0] = mResult;
1677 resultArray[1] = mRetryCount;
1678 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 }
1680 }
1681
1682 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001683 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001684
1685 }
1686
Wink Savilleb564aae2014-10-23 10:18:09 -07001687 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 // No permission check needed here: this call is harmless, and it's
1689 // needed for the ServiceState.requestStateUpdate() call (which is
1690 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001691 final long identity = Binder.clearCallingIdentity();
1692 try {
1693 final Phone phone = getPhone(subId);
1694 if (phone != null) {
1695 phone.updateServiceLocation();
1696 }
1697 } finally {
1698 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001700 }
1701
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001702 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001703 @Override
1704 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001705 return isRadioOnWithFeature(callingPackage, null);
1706 }
1707
1708
1709 @Override
1710 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1711 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1712 callingFeatureId);
1713 }
1714
1715 @Deprecated
1716 @Override
1717 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1718 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001719 }
1720
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001721 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001722 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1723 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001725 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001726 return false;
1727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001728
1729 final long identity = Binder.clearCallingIdentity();
1730 try {
1731 return isRadioOnForSubscriber(subId);
1732 } finally {
1733 Binder.restoreCallingIdentity(identity);
1734 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001735 }
1736
1737 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001738 final long identity = Binder.clearCallingIdentity();
1739 try {
1740 final Phone phone = getPhone(subId);
1741 if (phone != null) {
1742 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1743 } else {
1744 return false;
1745 }
1746 } finally {
1747 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 }
1750
1751 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001752 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753 }
Wink Saville36469e72014-06-11 15:17:00 -07001754
Wink Savilleb564aae2014-10-23 10:18:09 -07001755 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001757
1758 final long identity = Binder.clearCallingIdentity();
1759 try {
1760 final Phone phone = getPhone(subId);
1761 if (phone != null) {
1762 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1763 }
1764 } finally {
1765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001766 }
Wink Saville36469e72014-06-11 15:17:00 -07001767 }
1768
1769 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001770 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001771 }
1772
Wink Savilleb564aae2014-10-23 10:18:09 -07001773 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001774 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001775
1776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 final Phone phone = getPhone(subId);
1779 if (phone == null) {
1780 return false;
1781 }
1782 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1783 toggleRadioOnOffForSubscriber(subId);
1784 }
1785 return true;
1786 } finally {
1787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
Wink Saville36469e72014-06-11 15:17:00 -07001790
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001791 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001792 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001793 /*
1794 * If any of the Radios are available, it will need to be
1795 * shutdown. So return true if any Radio is available.
1796 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 final long identity = Binder.clearCallingIdentity();
1798 try {
1799 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1800 Phone phone = PhoneFactory.getPhone(i);
1801 if (phone != null && phone.isRadioAvailable()) return true;
1802 }
1803 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1804 return false;
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001807 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001808 }
1809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001810 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001811 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001812 enforceModifyPermission();
1813
1814 final long identity = Binder.clearCallingIdentity();
1815 try {
1816 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1817 logv("Shutting down Phone " + i);
1818 shutdownRadioUsingPhoneId(i);
1819 }
1820 } finally {
1821 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001822 }
1823 }
1824
1825 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001826 Phone phone = PhoneFactory.getPhone(phoneId);
1827 if (phone != null && phone.isRadioAvailable()) {
1828 phone.shutdownRadio();
1829 }
1830 }
1831
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834
1835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1838 if (defaultPhone != null) {
1839 defaultPhone.setRadioPower(turnOn);
1840 return true;
1841 } else {
1842 loge("There's no default phone.");
1843 return false;
1844 }
1845 } finally {
1846 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001847 }
Wink Saville36469e72014-06-11 15:17:00 -07001848 }
1849
Wink Savilleb564aae2014-10-23 10:18:09 -07001850 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001852
1853 final long identity = Binder.clearCallingIdentity();
1854 try {
1855 final Phone phone = getPhone(subId);
1856 if (phone != null) {
1857 phone.setRadioPower(turnOn);
1858 return true;
1859 } else {
1860 return false;
1861 }
1862 } finally {
1863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001865 }
1866
Wink Saville36469e72014-06-11 15:17:00 -07001867 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001868 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 public boolean enableDataConnectivity() {
1870 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001871
1872 final long identity = Binder.clearCallingIdentity();
1873 try {
1874 int subId = mSubscriptionController.getDefaultDataSubId();
1875 final Phone phone = getPhone(subId);
1876 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001877 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001878 return true;
1879 } else {
1880 return false;
1881 }
1882 } finally {
1883 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 }
1886
Wink Saville36469e72014-06-11 15:17:00 -07001887 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 public boolean disableDataConnectivity() {
1890 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001891
1892 final long identity = Binder.clearCallingIdentity();
1893 try {
1894 int subId = mSubscriptionController.getDefaultDataSubId();
1895 final Phone phone = getPhone(subId);
1896 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001897 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898 return true;
1899 } else {
1900 return false;
1901 }
1902 } finally {
1903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001908 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001909 final long identity = Binder.clearCallingIdentity();
1910 try {
1911 final Phone phone = getPhone(subId);
1912 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001913 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001914 } else {
1915 return false;
1916 }
1917 } finally {
1918 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 }
1921
1922 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001923 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001924 }
1925
pkanwarae03a6b2016-11-06 20:37:09 -08001926 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001927 enforceCallPermission();
1928
1929 final long identity = Binder.clearCallingIdentity();
1930 try {
1931 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1932 return;
1933 }
1934 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1935 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1936 } finally {
1937 Binder.restoreCallingIdentity(identity);
1938 }
pkanwar32d516d2016-10-14 19:37:38 -07001939 };
1940
Wink Savilleb564aae2014-10-23 10:18:09 -07001941 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001943
1944 final long identity = Binder.clearCallingIdentity();
1945 try {
1946 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1947 return false;
1948 }
1949 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1950 } finally {
1951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001956 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001957 }
1958
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001959 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001960 final long identity = Binder.clearCallingIdentity();
1961 try {
1962 Phone phone = PhoneFactory.getPhone(slotIndex);
1963 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1964 PhoneConstantConversions.convertCallState(phone.getState());
1965 } finally {
1966 Binder.restoreCallingIdentity(identity);
1967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 }
1969
Sanket Padawe356d7632015-06-22 14:03:32 -07001970 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001971 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001972 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1973 }
1974
1975 @Override
1976 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001977 final long identity = Binder.clearCallingIdentity();
1978 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001979 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001980 if (phone != null) {
1981 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1982 } else {
1983 return PhoneConstantConversions.convertDataState(
1984 PhoneConstants.DataState.DISCONNECTED);
1985 }
1986 } finally {
1987 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990
Sanket Padawe356d7632015-06-22 14:03:32 -07001991 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001992 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001993 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1994 }
1995
1996 @Override
1997 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001998 final long identity = Binder.clearCallingIdentity();
1999 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002000 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002001 if (phone != null) {
2002 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2003 } else {
2004 return TelephonyManager.DATA_ACTIVITY_NONE;
2005 }
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010
2011 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002012 public Bundle getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002013 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002014 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002015
2016 LocationAccessPolicy.LocationPermissionResult locationResult =
2017 LocationAccessPolicy.checkLocationPermission(mApp,
2018 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2019 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002020 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002021 .setCallingPid(Binder.getCallingPid())
2022 .setCallingUid(Binder.getCallingUid())
2023 .setMethod("getCellLocation")
2024 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2025 .build());
2026 switch (locationResult) {
2027 case DENIED_HARD:
2028 throw new SecurityException("Not allowed to access cell location");
2029 case DENIED_SOFT:
2030 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 }
2032
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002033 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002034 final long identity = Binder.clearCallingIdentity();
2035 try {
2036 if (DBG_LOC) log("getCellLocation: is active user");
2037 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002038 int subId = mSubscriptionController.getDefaultDataSubId();
2039 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2040 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002041 return data;
2042 } finally {
2043 Binder.restoreCallingIdentity(identity);
2044 }
Svetoslav64fad262015-04-14 14:35:21 -07002045 }
2046
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002048 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2049 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002050 if (!TextUtils.isEmpty(callingPackage)) {
2051 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002052 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2053 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002054 return "";
2055 }
2056 }
2057
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002058 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2059 // registered cell info, so return a NULL country instead.
2060 final long identity = Binder.clearCallingIdentity();
2061 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002062 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2063 // Get default phone in this case.
2064 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2065 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002066 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002067 // Todo: fix this when we can get the actual cellular network info when the device
2068 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002069 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002070 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2071 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002072 return "";
2073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002074 Phone phone = PhoneFactory.getPhone(phoneId);
2075 if (phone != null) {
2076 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002077 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 if (sst != null) {
2079 LocaleTracker lt = sst.getLocaleTracker();
2080 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002081 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2082 return lt.getCurrentCountry();
2083 } else if (emergencyNumberTracker != null) {
2084 return emergencyNumberTracker.getEmergencyCountryIso();
2085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002086 }
2087 }
2088 }
2089 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002090 } finally {
2091 Binder.restoreCallingIdentity(identity);
2092 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002093 }
2094
2095 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002096 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002097 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002098 }
2099
Sanket Padawe356d7632015-06-22 14:03:32 -07002100 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002101 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 mApp.enforceCallingOrSelfPermission(
2103 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002104
2105 final long identity = Binder.clearCallingIdentity();
2106 try {
2107 final Phone phone = getPhone(subId);
2108 if (phone != null) {
2109 phone.enableLocationUpdates();
2110 }
2111 } finally {
2112 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 }
2115
2116 @Override
2117 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002118 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002119 }
2120
Sanket Padawe356d7632015-06-22 14:03:32 -07002121 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002122 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 mApp.enforceCallingOrSelfPermission(
2124 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002125
2126 final long identity = Binder.clearCallingIdentity();
2127 try {
2128 final Phone phone = getPhone(subId);
2129 if (phone != null) {
2130 phone.disableLocationUpdates();
2131 }
2132 } finally {
2133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 }
2136
Nathan Harold31d7ff32018-10-15 20:20:30 -07002137 /**
2138 * Returns the target SDK version number for a given package name.
2139 *
Nathan Haroldec184742019-07-10 17:04:16 -07002140 * This call MUST be invoked before clearing the calling UID.
2141 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002142 * @return target SDK if the package is found or INT_MAX.
2143 */
2144 private int getTargetSdk(String packageName) {
2145 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002146 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002147 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002148 if (ai != null) return ai.targetSdkVersion;
2149 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002150 loge("Failed to get package info for pkg="
2151 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002152 }
2153 return Integer.MAX_VALUE;
2154 }
2155
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 @Override
2157 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002158 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2159 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002160 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002161 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2162 throw new SecurityException(
2163 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2164 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002165
Jordan Liu1617b712019-07-10 15:06:26 -07002166 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2168 return null;
2169 }
Svetoslav64fad262015-04-14 14:35:21 -07002170
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002171 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002173 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002174 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175
Nathan Haroldf180aac2018-06-01 18:43:55 -07002176 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2177 for (CellInfo ci : info) {
2178 if (ci instanceof CellInfoGsm) {
2179 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2180 } else if (ci instanceof CellInfoWcdma) {
2181 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002184 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002187 private List<CellInfo> getCachedCellInfo() {
2188 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2189 for (Phone phone : PhoneFactory.getPhones()) {
2190 List<CellInfo> info = phone.getAllCellInfo();
2191 if (info != null) cellInfos.addAll(info);
2192 }
2193 return cellInfos;
2194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195
2196 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002197 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002198 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002199 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002200
2201 LocationAccessPolicy.LocationPermissionResult locationResult =
2202 LocationAccessPolicy.checkLocationPermission(mApp,
2203 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2204 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002205 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002206 .setCallingPid(Binder.getCallingPid())
2207 .setCallingUid(Binder.getCallingUid())
2208 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002209 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002210 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2211 .build());
2212 switch (locationResult) {
2213 case DENIED_HARD:
2214 throw new SecurityException("Not allowed to access cell info");
2215 case DENIED_SOFT:
2216 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002219 final int targetSdk = getTargetSdk(callingPackage);
2220 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2221 return getCachedCellInfo();
2222 }
2223
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002224 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002225 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002226 final long identity = Binder.clearCallingIdentity();
2227 try {
2228 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2229 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002230 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002231 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002232 if (info != null) cellInfos.addAll(info);
2233 }
2234 return cellInfos;
2235 } finally {
2236 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 }
2238 }
2239
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002240 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002241 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2242 String callingFeatureId) {
2243 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2244 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002245 }
2246
2247 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002248 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2249 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002250 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002251 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002252 }
2253
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002254 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2255 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002256 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002257 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002258
2259 LocationAccessPolicy.LocationPermissionResult locationResult =
2260 LocationAccessPolicy.checkLocationPermission(mApp,
2261 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2262 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002263 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002264 .setCallingPid(Binder.getCallingPid())
2265 .setCallingUid(Binder.getCallingUid())
2266 .setMethod("requestCellInfoUpdate")
2267 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2268 .build());
2269 switch (locationResult) {
2270 case DENIED_HARD:
2271 throw new SecurityException("Not allowed to access cell info");
2272 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002273 try {
2274 cb.onCellInfo(new ArrayList<CellInfo>());
2275 } catch (RemoteException re) {
2276 // Drop without consequences
2277 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002278 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002279 }
2280
Nathan Harolda939a962019-05-09 10:13:47 -07002281
2282 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002283 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2284
2285 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2286 }
2287
2288 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002290 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002291 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292
2293 final long identity = Binder.clearCallingIdentity();
2294 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002295 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002296 } finally {
2297 Binder.restoreCallingIdentity(identity);
2298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 }
2300
Shishir Agrawala9f32182016-04-12 12:00:16 -07002301 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002302 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002303 Phone phone = PhoneFactory.getPhone(slotIndex);
2304 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002305 return null;
2306 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002307 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002308 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002309 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002310 return null;
2311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002312
2313 final long identity = Binder.clearCallingIdentity();
2314 try {
2315 return phone.getImei();
2316 } finally {
2317 Binder.restoreCallingIdentity(identity);
2318 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002319 }
2320
2321 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002322 public String getTypeAllocationCodeForSlot(int slotIndex) {
2323 Phone phone = PhoneFactory.getPhone(slotIndex);
2324 String tac = null;
2325 if (phone != null) {
2326 String imei = phone.getImei();
2327 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2328 }
2329 return tac;
2330 }
2331
2332 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002333 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002334 Phone phone = PhoneFactory.getPhone(slotIndex);
2335 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002336 return null;
2337 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002338
Jeff Davidson913390f2018-02-23 17:11:49 -08002339 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002340 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002341 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002342 return null;
2343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344
2345 final long identity = Binder.clearCallingIdentity();
2346 try {
2347 return phone.getMeid();
2348 } finally {
2349 Binder.restoreCallingIdentity(identity);
2350 }
Jack Yu2af8d712017-03-15 17:14:14 -07002351 }
2352
2353 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002354 public String getManufacturerCodeForSlot(int slotIndex) {
2355 Phone phone = PhoneFactory.getPhone(slotIndex);
2356 String manufacturerCode = null;
2357 if (phone != null) {
2358 String meid = phone.getMeid();
2359 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2360 }
2361 return manufacturerCode;
2362 }
2363
2364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002365 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2366 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002367 Phone phone = PhoneFactory.getPhone(slotIndex);
2368 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002369 return null;
2370 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002371 int subId = phone.getSubId();
2372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002373 mApp, subId, callingPackage, callingFeatureId,
2374 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002375 return null;
2376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377
2378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 return phone.getDeviceSvn();
2381 } finally {
2382 Binder.restoreCallingIdentity(identity);
2383 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002384 }
2385
fionaxu43304da2017-11-27 22:51:16 -08002386 @Override
2387 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 final Phone phone = getPhone(subId);
2391 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2392 } finally {
2393 Binder.restoreCallingIdentity(identity);
2394 }
fionaxu43304da2017-11-27 22:51:16 -08002395 }
2396
2397 @Override
2398 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002399 final long identity = Binder.clearCallingIdentity();
2400 try {
2401 final Phone phone = getPhone(subId);
2402 return phone == null ? null : phone.getCarrierName();
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
2405 }
fionaxu43304da2017-11-27 22:51:16 -08002406 }
2407
calvinpanffe225e2018-11-01 19:43:06 +08002408 @Override
chen xu0026ca62019-03-06 15:28:50 -08002409 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002410 final long identity = Binder.clearCallingIdentity();
2411 try {
2412 final Phone phone = getPhone(subId);
2413 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002414 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002415 } finally {
2416 Binder.restoreCallingIdentity(identity);
2417 }
2418 }
2419
2420 @Override
chen xu0026ca62019-03-06 15:28:50 -08002421 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002422 final long identity = Binder.clearCallingIdentity();
2423 try {
2424 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002425 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
2429 }
2430
chen xu651eec72018-11-11 19:03:44 -08002431 @Override
chen xu864e11c2018-12-06 22:10:03 -08002432 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2433 if (!isSubscriptionMccMnc) {
2434 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2435 }
chen xu651eec72018-11-11 19:03:44 -08002436 final Phone phone = PhoneFactory.getPhone(slotIndex);
2437 if (phone == null) {
2438 return TelephonyManager.UNKNOWN_CARRIER_ID;
2439 }
2440 final long identity = Binder.clearCallingIdentity();
2441 try {
2442 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
2445 }
2446 }
2447
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 //
2449 // Internal helper methods.
2450 //
2451
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002452 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2454 *
2455 * @throws SecurityException if the caller does not have the required permission
2456 */
2457 private void enforceModifyPermission() {
2458 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2459 }
2460
Shuo Qian3b6ee772019-11-13 17:43:31 -08002461 private void enforceActiveEmergencySessionPermission() {
2462 mApp.enforceCallingOrSelfPermission(
2463 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2464 }
2465
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 /**
2467 * Make sure the caller has the CALL_PHONE permission.
2468 *
2469 * @throws SecurityException if the caller does not have the required permission
2470 */
2471 private void enforceCallPermission() {
2472 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2473 }
2474
paulhu5a773602019-08-23 19:17:33 +08002475 private void enforceSettingsPermission() {
2476 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002477 }
2478
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 private String createTelUrl(String number) {
2480 if (TextUtils.isEmpty(number)) {
2481 return null;
2482 }
2483
Jake Hambye994d462014-02-03 13:10:13 -08002484 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
Ihab Awadf9e92732013-12-05 18:02:52 -08002487 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2489 }
2490
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002491 private static void logv(String msg) {
2492 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2493 }
2494
Ihab Awadf9e92732013-12-05 18:02:52 -08002495 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2497 }
2498
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002499 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002501 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002502 }
2503
Sanket Padawe356d7632015-06-22 14:03:32 -07002504 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002505 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 final Phone phone = PhoneFactory.getPhone(slotIndex);
2509 if (phone == null) {
2510 return PhoneConstants.PHONE_TYPE_NONE;
2511 } else {
2512 return phone.getPhoneType();
2513 }
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
2519 /**
2520 * Returns the CDMA ERI icon index to display
2521 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002522 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002523 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2524 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2525 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002526 }
2527
Sanket Padawe356d7632015-06-22 14:03:32 -07002528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002529 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2530 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002532 mApp, subId, callingPackage, callingFeatureId,
2533 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002534 return -1;
2535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002536
2537 final long identity = Binder.clearCallingIdentity();
2538 try {
2539 final Phone phone = getPhone(subId);
2540 if (phone != null) {
2541 return phone.getCdmaEriIconIndex();
2542 } else {
2543 return -1;
2544 }
2545 } finally {
2546 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002548 }
2549
2550 /**
2551 * Returns the CDMA ERI icon mode,
2552 * 0 - ON
2553 * 1 - FLASHING
2554 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002555 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002556 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2557 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2558 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002559 }
2560
Sanket Padawe356d7632015-06-22 14:03:32 -07002561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002562 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2563 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002565 mApp, subId, callingPackage, callingFeatureId,
2566 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002567 return -1;
2568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 final Phone phone = getPhone(subId);
2573 if (phone != null) {
2574 return phone.getCdmaEriIconMode();
2575 } else {
2576 return -1;
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 }
2582
2583 /**
2584 * Returns the CDMA ERI text,
2585 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002586 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002587 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2588 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2589 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002590 }
2591
Sanket Padawe356d7632015-06-22 14:03:32 -07002592 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002593 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2594 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002596 mApp, subId, callingPackage, callingFeatureId,
2597 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002598 return null;
2599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600
2601 final long identity = Binder.clearCallingIdentity();
2602 try {
2603 final Phone phone = getPhone(subId);
2604 if (phone != null) {
2605 return phone.getCdmaEriText();
2606 } else {
2607 return null;
2608 }
2609 } finally {
2610 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 }
2613
2614 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002615 * Returns the CDMA MDN.
2616 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002617 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002618 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2620 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621
2622 final long identity = Binder.clearCallingIdentity();
2623 try {
2624 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002625 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 return phone.getLine1Number();
2627 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002628 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629 return null;
2630 }
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002633 }
2634 }
2635
2636 /**
2637 * Returns the CDMA MIN.
2638 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002639 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002640 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2642 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643
2644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 final Phone phone = getPhone(subId);
2647 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2648 return phone.getCdmaMin();
2649 } else {
2650 return null;
2651 }
2652 } finally {
2653 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002654 }
2655 }
2656
Hall Liud892bec2018-11-30 14:51:45 -08002657 @Override
2658 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2659 INumberVerificationCallback callback, String callingPackage) {
2660 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2661 != PERMISSION_GRANTED) {
2662 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2663 }
2664 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2665
2666 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2667 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2668 throw new SecurityException("Calling package must be configured in the device config");
2669 }
2670
2671 if (range == null) {
2672 throw new NullPointerException("Range must be non-null");
2673 }
2674
2675 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002676 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002677
2678 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2679 }
2680
Junda Liuca05d5d2014-08-14 22:36:34 -07002681 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 * Returns true if CDMA provisioning needs to run.
2683 */
2684 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685 final long identity = Binder.clearCallingIdentity();
2686 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002687 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 } finally {
2689 Binder.restoreCallingIdentity(identity);
2690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 }
2692
2693 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002694 * Sets the voice mail number of a given subId.
2695 */
2696 @Override
2697 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002698 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2699 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700
2701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2704 new Pair<String, String>(alphaTag, number), new Integer(subId));
2705 return success;
2706 } finally {
2707 Binder.restoreCallingIdentity(identity);
2708 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002709 }
2710
Ta-wei Yen87c49842016-05-13 21:19:52 -07002711 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002712 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2713 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002714 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2715 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002716 if (!TextUtils.equals(callingPackage, systemDialer)) {
2717 throw new SecurityException("caller must be system dialer");
2718 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719
2720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2723 if (phoneAccountHandle == null) {
2724 return null;
2725 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002726 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 } finally {
2728 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002729 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002730 }
2731
2732 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002733 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2734 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002735 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002737 mApp, subId, callingPackage, callingFeatureId,
2738 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002739 return null;
2740 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002742 final long identity = Binder.clearCallingIdentity();
2743 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002744 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002745 } finally {
2746 Binder.restoreCallingIdentity(identity);
2747 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002748 }
2749
2750 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002751 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2752 VisualVoicemailSmsFilterSettings settings) {
2753 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754
2755 final long identity = Binder.clearCallingIdentity();
2756 try {
2757 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002758 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759 } finally {
2760 Binder.restoreCallingIdentity(identity);
2761 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002762 }
2763
2764 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002765 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2766 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767
2768 final long identity = Binder.clearCallingIdentity();
2769 try {
2770 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002771 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 } finally {
2773 Binder.restoreCallingIdentity(identity);
2774 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002775 }
2776
2777 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002778 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2779 String callingPackage, int subId) {
2780 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002785 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 } finally {
2787 Binder.restoreCallingIdentity(identity);
2788 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002789 }
2790
2791 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002792 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002793 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002794
2795 final long identity = Binder.clearCallingIdentity();
2796 try {
2797 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002798 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799 } finally {
2800 Binder.restoreCallingIdentity(identity);
2801 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002802 }
2803
2804 @Override
2805 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2806 String number, int port, String text, PendingIntent sentIntent) {
2807 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002808 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002809 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002810 SmsController smsController = PhoneFactory.getSmsController();
2811 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2812 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002813 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002814
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002815 /**
fionaxu0152e512016-11-14 13:36:14 -08002816 * Sets the voice activation state of a given subId.
2817 */
2818 @Override
2819 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2821 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822
2823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 final Phone phone = getPhone(subId);
2826 if (phone != null) {
2827 phone.setVoiceActivationState(activationState);
2828 } else {
2829 loge("setVoiceActivationState fails with invalid subId: " + subId);
2830 }
2831 } finally {
2832 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002833 }
2834 }
2835
2836 /**
2837 * Sets the data activation state of a given subId.
2838 */
2839 @Override
2840 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2842 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002843
2844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 final Phone phone = getPhone(subId);
2847 if (phone != null) {
2848 phone.setDataActivationState(activationState);
2849 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002850 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 }
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002854 }
2855 }
2856
2857 /**
2858 * Returns the voice activation state of a given subId.
2859 */
2860 @Override
2861 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002862 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863
fionaxu0152e512016-11-14 13:36:14 -08002864 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 if (phone != null) {
2868 return phone.getVoiceActivationState();
2869 } else {
2870 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2871 }
2872 } finally {
2873 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002874 }
2875 }
2876
2877 /**
2878 * Returns the data activation state of a given subId.
2879 */
2880 @Override
2881 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002882 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002883
fionaxu0152e512016-11-14 13:36:14 -08002884 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 if (phone != null) {
2888 return phone.getDataActivationState();
2889 } else {
2890 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2891 }
2892 } finally {
2893 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002894 }
2895 }
2896
2897 /**
Wink Saville36469e72014-06-11 15:17:00 -07002898 * Returns the unread count of voicemails for a subId
2899 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002900 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002901 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2902 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002904 mApp, subId, callingPackage, callingFeatureId,
2905 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002906 return 0;
2907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908 final long identity = Binder.clearCallingIdentity();
2909 try {
2910 final Phone phone = getPhone(subId);
2911 if (phone != null) {
2912 return phone.getVoiceMessageCount();
2913 } else {
2914 return 0;
2915 }
2916 } finally {
2917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002919 }
2920
2921 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002922 * returns true, if the device is in a state where both voice and data
2923 * are supported simultaneously. This can change based on location or network condition.
2924 */
2925 @Override
2926 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 final Phone phone = getPhone(subId);
2930 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2931 } finally {
2932 Binder.restoreCallingIdentity(identity);
2933 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002934 }
2935
2936 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002937 * Send the dialer code if called from the current default dialer or the caller has
2938 * carrier privilege.
2939 * @param inputCode The dialer code to send
2940 */
2941 @Override
2942 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002943 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002944 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002945 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2946 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002947 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002948 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002949 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002954 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002955 } finally {
2956 Binder.restoreCallingIdentity(identity);
2957 }
fionaxu235cc5e2017-03-06 22:25:57 -08002958 }
2959
Pengquan Menga1bb6272018-09-06 09:59:22 -07002960 @Override
2961 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002962 if (!isActiveSubscription(subId)) {
2963 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2964 }
2965
Pengquan Menga1bb6272018-09-06 09:59:22 -07002966 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2967 }
2968
Brad Ebinger35c841c2018-10-01 10:40:55 -07002969 @Override
Sarah Chin0605abf2019-12-06 10:24:18 -08002970 public PhoneCapability getPhoneCapability(int subId, String callingPackage,
2971 String callingFeatureId) {
2972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2973 mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) {
2974 return null;
2975 }
2976 final long identity = Binder.clearCallingIdentity();
2977 try {
2978 return mPhoneConfigurationManager.getStaticPhoneCapability();
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002985 public boolean isInEmergencySmsMode() {
2986 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 for (Phone phone : PhoneFactory.getPhones()) {
2990 if (phone.isInEmergencySmsMode()) {
2991 return true;
2992 }
2993 }
2994 } finally {
2995 Binder.restoreCallingIdentity(identity);
2996 }
2997 return false;
2998 }
2999
3000 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003001 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3002 throws RemoteException {
3003 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003004 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3005 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3006 "IMS not available on device.");
3007 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003008 final long token = Binder.clearCallingIdentity();
3009 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003011 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003012 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003013 } catch (ImsException e) {
3014 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003015 } finally {
3016 Binder.restoreCallingIdentity(token);
3017 }
3018 }
3019
3020 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003021 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
3022 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003023 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3024 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3025 }
Meng Wangafbc5852019-09-19 17:37:13 -07003026 final long token = Binder.clearCallingIdentity();
3027 try {
3028 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3029 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3030 .removeRegistrationCallbackForSubscription(c, subId);
3031 } catch (ImsException e) {
3032 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3033 + "is inactive, ignoring unregister.");
3034 // If the subscription is no longer active, just return, since the callback
3035 // will already have been removed internally.
3036 } finally {
3037 Binder.restoreCallingIdentity(token);
3038 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003039 }
3040
Brad Ebingera34a6c22019-10-22 17:36:18 -07003041 /**
3042 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3043 */
3044 @Override
3045 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3046 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3047 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3048 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3049 "IMS not available on device.");
3050 }
3051 final long token = Binder.clearCallingIdentity();
3052 try {
3053 Phone phone = getPhone(subId);
3054 if (phone == null) {
3055 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3056 + subId + "'");
3057 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3058 }
3059 phone.getImsRegistrationState(regState -> {
3060 try {
3061 consumer.accept((regState == null)
3062 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3063 } catch (RemoteException e) {
3064 // Ignore if the remote process is no longer available to call back.
3065 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3066 }
3067 });
3068 } finally {
3069 Binder.restoreCallingIdentity(token);
3070 }
3071 }
3072
3073 /**
3074 * Get the transport type for the IMS service registration state.
3075 */
3076 @Override
3077 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3078 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3079 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3080 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3081 "IMS not available on device.");
3082 }
3083 final long token = Binder.clearCallingIdentity();
3084 try {
3085 Phone phone = getPhone(subId);
3086 if (phone == null) {
3087 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3088 + subId + "'");
3089 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3090 }
3091 phone.getImsRegistrationTech(regTech -> {
3092 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3093 int regTechConverted = (regTech == null)
3094 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3095 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3096 regTechConverted);
3097 try {
3098 consumer.accept(regTechConverted);
3099 } catch (RemoteException e) {
3100 // Ignore if the remote process is no longer available to call back.
3101 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3102 }
3103 });
3104 } finally {
3105 Binder.restoreCallingIdentity(token);
3106 }
3107 }
3108
Brad Ebinger35c841c2018-10-01 10:40:55 -07003109 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003110 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3111 throws RemoteException {
3112 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003113 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3114 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3115 "IMS not available on device.");
3116 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003117 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3118 final long token = Binder.clearCallingIdentity();
3119 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003120 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003121 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003122 } catch (ImsException e) {
3123 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003124 } finally {
3125 Binder.restoreCallingIdentity(token);
3126 }
3127 }
3128
3129 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003130 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3131 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003132 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3133 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3134 }
Meng Wangafbc5852019-09-19 17:37:13 -07003135
3136 final long token = Binder.clearCallingIdentity();
3137 try {
3138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3139 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003140 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003141 } catch (ImsException e) {
3142 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3143 + "is inactive, ignoring unregister.");
3144 // If the subscription is no longer active, just return, since the callback
3145 // will already have been removed internally.
3146 } finally {
3147 Binder.restoreCallingIdentity(token);
3148 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003149 }
3150
3151 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003152 public boolean isCapable(int subId, int capability, int regTech) {
3153 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003154 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3155 final long token = Binder.clearCallingIdentity();
3156 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003157 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003158 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003159 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003160 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3161 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003162 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003163 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3164 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003165 } finally {
3166 Binder.restoreCallingIdentity(token);
3167 }
3168 }
3169
3170 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003171 public boolean isAvailable(int subId, int capability, int regTech) {
3172 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003173 final long token = Binder.clearCallingIdentity();
3174 try {
3175 Phone phone = getPhone(subId);
3176 if (phone == null) return false;
3177 return phone.isImsCapabilityAvailable(capability, regTech);
3178 } finally {
3179 Binder.restoreCallingIdentity(token);
3180 }
3181 }
3182
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003183 /**
3184 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3185 * subscription.
3186 * @param subId The subscription to use to check the configuration.
3187 * @param callback The callback that will be used to send the result.
3188 * @param capability The MmTelFeature capability that will be used to send the result.
3189 * @param transportType The transport type of the MmTelFeature capability.
3190 */
3191 @Override
3192 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3193 int transportType) {
3194 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3195 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3196 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3197 "IMS not available on device.");
3198 }
3199 final long token = Binder.clearCallingIdentity();
3200 try {
3201 int slotId = getSlotIndex(subId);
3202 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3203 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3204 + subId + "'");
3205 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3206 }
3207 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3208 transportType, aBoolean -> {
3209 try {
3210 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3211 } catch (RemoteException e) {
3212 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3213 + "running. Ignore");
3214 }
3215 });
3216 } finally {
3217 Binder.restoreCallingIdentity(token);
3218 }
3219 }
3220
Brad Ebinger35c841c2018-10-01 10:40:55 -07003221 @Override
3222 public boolean isAdvancedCallingSettingEnabled(int subId) {
3223 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3224 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3225 final long token = Binder.clearCallingIdentity();
3226 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003227 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003228 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003229 } catch (ImsException e) {
3230 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003231 } finally {
3232 Binder.restoreCallingIdentity(token);
3233 }
3234 }
3235
3236 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003237 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003239 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003243 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003245 } catch (ImsException e) {
3246 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003247 } finally {
3248 Binder.restoreCallingIdentity(identity);
3249 }
3250 }
3251
3252 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003253 public boolean isVtSettingEnabled(int subId) {
3254 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 final long identity = Binder.clearCallingIdentity();
3256 try {
3257 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003258 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3259 } catch (ImsException e) {
3260 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003261 } finally {
3262 Binder.restoreCallingIdentity(identity);
3263 }
3264 }
3265
3266 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003267 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003269 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 final long identity = Binder.clearCallingIdentity();
3271 try {
3272 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003273 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003274 } catch (ImsException e) {
3275 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003276 } finally {
3277 Binder.restoreCallingIdentity(identity);
3278 }
3279 }
3280
3281 @Override
3282 public boolean isVoWiFiSettingEnabled(int subId) {
3283 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3284 final long identity = Binder.clearCallingIdentity();
3285 try {
3286 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003287 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003288 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003289 } catch (ImsException e) {
3290 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003291 } finally {
3292 Binder.restoreCallingIdentity(identity);
3293 }
3294 }
3295
3296 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003297 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003299 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003300 final long identity = Binder.clearCallingIdentity();
3301 try {
3302 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003303 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003304 } catch (ImsException e) {
3305 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003306 } finally {
3307 Binder.restoreCallingIdentity(identity);
3308 }
3309 }
3310
3311 @Override
3312 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3313 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003317 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003318 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003319 } catch (ImsException e) {
3320 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
3324 }
3325
3326 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003327 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003329 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003330 final long identity = Binder.clearCallingIdentity();
3331 try {
3332 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003333 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003334 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003335 } catch (ImsException e) {
3336 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003337 } finally {
3338 Binder.restoreCallingIdentity(identity);
3339 }
3340 }
3341
3342 @Override
3343 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3345 "setVoWiFiNonPersistent");
3346 final long identity = Binder.clearCallingIdentity();
3347 try {
3348 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003349 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003350 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003351 } catch (ImsException e) {
3352 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003353 } finally {
3354 Binder.restoreCallingIdentity(identity);
3355 }
3356 }
3357
3358 @Override
3359 public int getVoWiFiModeSetting(int subId) {
3360 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3361 final long identity = Binder.clearCallingIdentity();
3362 try {
3363 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003364 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003366 } catch (ImsException e) {
3367 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003368 } finally {
3369 Binder.restoreCallingIdentity(identity);
3370 }
3371 }
3372
3373 @Override
3374 public void setVoWiFiModeSetting(int subId, int mode) {
3375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3376 "setVoWiFiModeSetting");
3377 final long identity = Binder.clearCallingIdentity();
3378 try {
3379 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003380 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003382 } catch (ImsException e) {
3383 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003384 } finally {
3385 Binder.restoreCallingIdentity(identity);
3386 }
3387 }
3388
3389 @Override
3390 public int getVoWiFiRoamingModeSetting(int subId) {
3391 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3392 final long identity = Binder.clearCallingIdentity();
3393 try {
3394 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003395 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003396 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003397 } catch (ImsException e) {
3398 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
3402 }
3403
3404 @Override
3405 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3407 "setVoWiFiRoamingModeSetting");
3408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003411 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003412 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003413 } catch (ImsException e) {
3414 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003415 } finally {
3416 Binder.restoreCallingIdentity(identity);
3417 }
3418 }
3419
3420 @Override
3421 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3423 "setRttCapabilityEnabled");
3424 final long identity = Binder.clearCallingIdentity();
3425 try {
3426 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003427 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3428 } catch (ImsException e) {
3429 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003430 } finally {
3431 Binder.restoreCallingIdentity(identity);
3432 }
3433 }
3434
3435 @Override
3436 public boolean isTtyOverVolteEnabled(int subId) {
3437 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003441 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003442 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003443 } catch (ImsException e) {
3444 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003445 } finally {
3446 Binder.restoreCallingIdentity(identity);
3447 }
3448 }
3449
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003450 @Override
3451 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3452 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3453 final long identity = Binder.clearCallingIdentity();
3454 try {
3455 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003456 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003457 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003458 } catch (ImsException e) {
3459 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003460 } finally {
3461 Binder.restoreCallingIdentity(identity);
3462 }
3463 }
3464
3465 @Override
3466 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3467 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3468 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003469 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3470 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3471 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003472 try {
3473 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003474 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003475 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003476 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003477 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3478 + "is inactive, ignoring unregister.");
3479 // If the subscription is no longer active, just return, since the callback will already
3480 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003481 } finally {
3482 Binder.restoreCallingIdentity(identity);
3483 }
3484 }
3485
3486 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003487 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3488 boolean isProvisioned) {
3489 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3490 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3491 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3492 }
3493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3494 "setProvisioningStatusForCapability");
3495 final long identity = Binder.clearCallingIdentity();
3496 try {
3497 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3498 Phone phone = getPhone(subId);
3499 if (phone == null) {
3500 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3501 + subId);
3502 return;
3503 }
3504 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3505 return;
3506 }
3507
3508 // this capability requires provisioning, route to the correct API.
3509 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3510 switch (capability) {
3511 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3512 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3513 ims.setVolteProvisioned(isProvisioned);
3514 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3515 ims.setWfcProvisioned(isProvisioned);
3516 }
3517 break;
3518 }
3519 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3520 // There is currently no difference in VT provisioning type.
3521 ims.setVtProvisioned(isProvisioned);
3522 break;
3523 }
3524 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3525 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3526 // change the capability of the feature instead if needed.
3527 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3528 == isProvisioned) {
3529 // No change in provisioning.
3530 return;
3531 }
3532 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3533 try {
3534 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003535 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003536 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3537 + ", Exception" + e.getMessage());
3538 }
3539 break;
3540 }
3541 default: {
3542 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3543 + capability + "', which does not require provisioning.");
3544 }
3545 }
3546
3547 } finally {
3548 Binder.restoreCallingIdentity(identity);
3549 }
3550 }
3551
3552 @Override
3553 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3554 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3555 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3556 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3557 }
3558 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3559 final long identity = Binder.clearCallingIdentity();
3560 try {
3561 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3562 Phone phone = getPhone(subId);
3563 if (phone == null) {
3564 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3565 + subId);
3566 // We will fail with "true" as the provisioning status because this is the default
3567 // if we do not require provisioning.
3568 return true;
3569 }
3570
3571 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3572 return true;
3573 }
3574
3575 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3576 switch (capability) {
3577 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3578 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3579 return ims.isVolteProvisionedOnDevice();
3580 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3581 return ims.isWfcProvisionedOnDevice();
3582 }
3583 // This should never happen, since we are checking tech above to make sure it
3584 // is either LTE or IWLAN.
3585 throw new IllegalArgumentException("Invalid radio technology for voice "
3586 + "capability.");
3587 }
3588 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3589 // There is currently no difference in VT provisioning type.
3590 return ims.isVtProvisionedOnDevice();
3591 }
3592 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3593 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3594 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3595 }
3596 default: {
3597 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3598 + capability + "', which does not require provisioning.");
3599 }
3600 }
3601
3602 } finally {
3603 Binder.restoreCallingIdentity(identity);
3604 }
3605 }
3606
3607 @Override
3608 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3609 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3610 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3611 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3612 }
3613 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3614 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3615 return (provisionedBits & capability) > 0;
3616 }
3617
3618 @Override
3619 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3620 boolean isProvisioned) {
3621 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3622 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3623 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3624 }
3625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3626 "setProvisioningStatusForCapability");
3627 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3628 // If the current provisioning status for capability already matches isProvisioned,
3629 // do nothing.
3630 if (((provisionedBits & capability) > 0) == isProvisioned) {
3631 return;
3632 }
3633 if (isProvisioned) {
3634 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3635 } else {
3636 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3637 }
3638 }
3639
3640 /**
3641 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3642 * technology. The bitfield should mirror the bitfield defined by
3643 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3644 */
3645 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3646 String key = getMmTelProvisioningKey(subId, tech);
3647 // Default is no capabilities are provisioned.
3648 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3649 }
3650
3651 /**
3652 * Sets the MmTel capability provisioning bitfield (defined by
3653 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3654 * technology specified.
3655 *
3656 * Note: This is a synchronous command and should not be called on UI thread.
3657 */
3658 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3659 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3660 String key = getMmTelProvisioningKey(subId, tech);
3661 editor.putInt(key, newField);
3662 editor.commit();
3663 }
3664
3665 private static String getMmTelProvisioningKey(int subId, int tech) {
3666 // resulting key is provision_ims_mmtel_{subId}_{tech}
3667 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3668 }
3669
3670 /**
3671 * Query CarrierConfig to see if the specified capability requires provisioning for the
3672 * carrier associated with the subscription id.
3673 */
3674 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3675 int capability) {
3676 CarrierConfigManager configManager = new CarrierConfigManager(context);
3677 PersistableBundle c = configManager.getConfigForSubId(subId);
3678 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003679 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003680 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3681 false);
3682 boolean requireVoiceVtProvisioning = c.getBoolean(
3683 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3684
3685 // First check to make sure that the capability requires provisioning.
3686 switch (capability) {
3687 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3688 // intentional fallthrough
3689 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3690 if (requireVoiceVtProvisioning) {
3691 // Voice and Video requires provisioning
3692 return true;
3693 }
3694 break;
3695 }
3696 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3697 if (requireUtProvisioning) {
3698 // UT requires provisioning
3699 return true;
3700 }
3701 break;
3702 }
3703 }
3704 return false;
3705 }
3706
3707 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003708 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003709 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3710 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3711 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003712 enforceReadPrivilegedPermission("getImsProvisioningInt");
3713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003716 int slotId = getSlotIndex(subId);
3717 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3718 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3719 + subId + "' for key:" + key);
3720 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3721 }
3722 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003723 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003724 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3725 + subId + "' for key:" + key);
3726 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
3730 }
3731
3732 @Override
3733 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003734 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3735 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3736 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003737 enforceReadPrivilegedPermission("getImsProvisioningString");
3738 final long identity = Binder.clearCallingIdentity();
3739 try {
3740 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003741 int slotId = getSlotIndex(subId);
3742 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3743 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3744 + subId + "' for key:" + key);
3745 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3746 }
3747 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003748 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003749 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3750 + subId + "' for key:" + key);
3751 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003752 } finally {
3753 Binder.restoreCallingIdentity(identity);
3754 }
3755 }
3756
3757 @Override
3758 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3760 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3761 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3763 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003764 final long identity = Binder.clearCallingIdentity();
3765 try {
3766 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003767 int slotId = getSlotIndex(subId);
3768 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3769 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3770 + subId + "' for key:" + key);
3771 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3772 }
3773 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003774 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003775 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3776 + "' for key:" + key);
3777 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003778 } finally {
3779 Binder.restoreCallingIdentity(identity);
3780 }
3781 }
3782
3783 @Override
3784 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003785 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3786 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3787 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3789 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003790 final long identity = Binder.clearCallingIdentity();
3791 try {
3792 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003793 int slotId = getSlotIndex(subId);
3794 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3795 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3796 + subId + "' for key:" + key);
3797 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3798 }
3799 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003800 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003801 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3802 + "' for key:" + key);
3803 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003804 } finally {
3805 Binder.restoreCallingIdentity(identity);
3806 }
3807 }
3808
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003809 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003810 int slotId = SubscriptionManager.getSlotIndex(subId);
3811 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003812 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3813 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003814 }
3815 return slotId;
3816 }
3817
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003818 private int getSlotIndex(int subId) {
3819 int slotId = SubscriptionManager.getSlotIndex(subId);
3820 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3821 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3822 }
3823 return slotId;
3824 }
3825
Wink Saville36469e72014-06-11 15:17:00 -07003826 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003827 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003828 */
3829 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003830 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3831 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003832 final int targetSdk = getTargetSdk(callingPackage);
3833 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003834 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003835 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003836 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003837 mApp, subId, callingPackage, callingFeatureId,
3838 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003839 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3840 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003842 final long identity = Binder.clearCallingIdentity();
3843 try {
3844 final Phone phone = getPhone(subId);
3845 if (phone != null) {
3846 return phone.getServiceState().getDataNetworkType();
3847 } else {
3848 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3849 }
3850 } finally {
3851 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003852 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003853 }
3854
3855 /**
3856 * Returns the data network type
3857 */
3858 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003859 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3860 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3861 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003862 }
3863
3864 /**
3865 * Returns the data network type for a subId
3866 */
3867 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003868 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3869 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003870 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003871 mApp, subId, callingPackage, callingFeatureId,
3872 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003873 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3874 }
3875
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003876 final long identity = Binder.clearCallingIdentity();
3877 try {
3878 final Phone phone = getPhone(subId);
3879 if (phone != null) {
3880 return phone.getServiceState().getDataNetworkType();
3881 } else {
3882 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3883 }
3884 } finally {
3885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003887 }
3888
3889 /**
Wink Saville36469e72014-06-11 15:17:00 -07003890 * Returns the Voice network type for a subId
3891 */
3892 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003893 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3894 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003896 mApp, subId, callingPackage, callingFeatureId,
3897 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003898 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3899 }
3900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003901 final long identity = Binder.clearCallingIdentity();
3902 try {
3903 final Phone phone = getPhone(subId);
3904 if (phone != null) {
3905 return phone.getServiceState().getVoiceNetworkType();
3906 } else {
3907 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3908 }
3909 } finally {
3910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003912 }
3913
3914 /**
3915 * @return true if a ICC card is present
3916 */
3917 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003918 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003919 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3920 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003921 }
3922
3923 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003924 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003925 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003926 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003927 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 final Phone phone = PhoneFactory.getPhone(slotIndex);
3931 if (phone != null) {
3932 return phone.getIccCard().hasIccCard();
3933 } else {
3934 return false;
3935 }
3936 } finally {
3937 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003939 }
3940
3941 /**
3942 * Return if the current radio is LTE on CDMA. This
3943 * is a tri-state return value as for a period of time
3944 * the mode may be unknown.
3945 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003946 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003947 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003948 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003949 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003950 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003951 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3952 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3953 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003954 }
3955
Sanket Padawe356d7632015-06-22 14:03:32 -07003956 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003957 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3958 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003959 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003960 mApp, subId, callingPackage, callingFeatureId,
3961 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003962 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3963 }
3964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003965 final long identity = Binder.clearCallingIdentity();
3966 try {
3967 final Phone phone = getPhone(subId);
3968 if (phone == null) {
3969 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3970 } else {
3971 return phone.getLteOnCdmaMode();
3972 }
3973 } finally {
3974 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003975 }
Wink Saville36469e72014-06-11 15:17:00 -07003976 }
3977
Wink Saville36469e72014-06-11 15:17:00 -07003978 /**
3979 * {@hide}
3980 * Returns Default subId, 0 in the case of single standby.
3981 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003982 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003983 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003984 }
3985
Shishir Agrawala9f32182016-04-12 12:00:16 -07003986 private int getSlotForDefaultSubscription() {
3987 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3988 }
3989
Wink Savilleb564aae2014-10-23 10:18:09 -07003990 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003991 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003992 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003993
Pengquan Menge92a50d2018-09-21 15:54:48 -07003994 private boolean isActiveSubscription(int subId) {
3995 return mSubscriptionController.isActiveSubId(subId);
3996 }
3997
Ihab Awadf2177b72013-11-25 13:33:23 -08003998 /**
3999 * @see android.telephony.TelephonyManager.WifiCallingChoices
4000 */
4001 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004002 final long identity = Binder.clearCallingIdentity();
4003 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004004 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4006 getWhenToMakeWifiCallsDefaultPreference());
4007 } finally {
4008 Binder.restoreCallingIdentity(identity);
4009 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004010 }
4011
4012 /**
4013 * @see android.telephony.TelephonyManager.WifiCallingChoices
4014 */
4015 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004019 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4021 } finally {
4022 Binder.restoreCallingIdentity(identity);
4023 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004024 }
4025
Sailesh Nepald1e68152013-12-12 19:08:02 -08004026 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004027 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004028 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004029 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004030
Jordan Liu4c733742019-02-28 12:03:40 -08004031 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4032 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4033 if (phoneId == -1) {
4034 throw new IllegalArgumentException("Given slot index: " + slotIndex
4035 + " does not correspond to an active phone");
4036 }
4037 return PhoneFactory.getPhone(phoneId);
4038 }
4039
Shishir Agrawal566b7612013-10-28 14:41:00 -07004040 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004041 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4042 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4044 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004046 if (DBG) {
4047 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4048 }
4049 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4050 p2);
4051 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004052
Jordan Liu4c733742019-02-28 12:03:40 -08004053
4054 @Override
4055 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4056 int slotIndex, String callingPackage, String aid, int p2) {
4057 enforceModifyPermission();
4058 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4059 if (DBG) {
4060 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4061 }
4062 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4063 callingPackage, aid, p2);
4064 }
4065
4066 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4067 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 if (TextUtils.equals(ISDR_AID, aid)) {
4071 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004072 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4073 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004074 if (bestComponent == null
4075 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4076 loge("The calling package is not allowed to access ISD-R.");
4077 throw new SecurityException(
4078 "The calling package is not allowed to access ISD-R.");
4079 }
Derek Tan740e1672017-06-27 14:56:27 -07004080 }
Derek Tan740e1672017-06-27 14:56:27 -07004081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004083 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4084 null /* workSource */);
4085 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086 return response;
4087 } finally {
4088 Binder.restoreCallingIdentity(identity);
4089 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004090 }
4091
4092 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004093 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4095 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004096 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4097 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4098 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004099
Jordan Liu4c733742019-02-28 12:03:40 -08004100 @Override
4101 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4102 enforceModifyPermission();
4103 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4104 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4105 channel);
4106 }
4107
4108 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004109 final long identity = Binder.clearCallingIdentity();
4110 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004111 if (channel < 0) {
4112 return false;
4113 }
Jordan Liu4c733742019-02-28 12:03:40 -08004114 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4115 null /* workSource */);
4116 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117 return success;
4118 } finally {
4119 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004120 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004121 }
4122
4123 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004124 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004125 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4127 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004128 if (DBG) {
4129 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4130 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4131 + p3 + " data=" + data);
4132 }
4133 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4134 command, p1, p2, p3, data);
4135 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004136
Jordan Liu4c733742019-02-28 12:03:40 -08004137 @Override
4138 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4139 int command, int p1, int p2, int p3, String data) {
4140 enforceModifyPermission();
4141 if (DBG) {
4142 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4143 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4144 + p3 + " data=" + data);
4145 }
4146 return iccTransmitApduLogicalChannelWithPermission(
4147 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4148 data);
4149 }
4150
4151 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4152 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004153 final long identity = Binder.clearCallingIdentity();
4154 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004155 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004156 return "";
4157 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004159 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004160 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4161 null /* workSource */);
4162 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004164 // Append the returned status code to the end of the response payload.
4165 String s = Integer.toHexString(
4166 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4167 if (response.payload != null) {
4168 s = IccUtils.bytesToHexString(response.payload) + s;
4169 }
4170 return s;
4171 } finally {
4172 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004173 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004174 }
Jake Hambye994d462014-02-03 13:10:13 -08004175
Evan Charltonc66da362014-05-16 14:06:40 -07004176 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004177 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4178 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4180 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004181 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004182 if (DBG) {
4183 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4184 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4185 }
4186 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4187 cla, command, p1, p2, p3, data);
4188 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004189
Jordan Liu4c733742019-02-28 12:03:40 -08004190 @Override
4191 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4192 int command, int p1, int p2, int p3, String data) {
4193 enforceModifyPermission();
4194 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4195 if (DBG) {
4196 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4197 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4198 + " data=" + data);
4199 }
4200
4201 return iccTransmitApduBasicChannelWithPermission(
4202 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4203 p2, p3, data);
4204 }
4205
4206 // open APDU basic channel assuming the caller has sufficient permissions
4207 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4208 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004209 final long identity = Binder.clearCallingIdentity();
4210 try {
4211 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4212 && TextUtils.equals(ISDR_AID, data)) {
4213 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004214 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4215 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004216 if (bestComponent == null
4217 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4218 loge("The calling package is not allowed to select ISD-R.");
4219 throw new SecurityException(
4220 "The calling package is not allowed to select ISD-R.");
4221 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004222 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004224 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004225 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4226 null /* workSource */);
4227 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004229 // Append the returned status code to the end of the response payload.
4230 String s = Integer.toHexString(
4231 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4232 if (response.payload != null) {
4233 s = IccUtils.bytesToHexString(response.payload) + s;
4234 }
4235 return s;
4236 } finally {
4237 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004238 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004239 }
4240
4241 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004242 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004243 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4245 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004246
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004247 final long identity = Binder.clearCallingIdentity();
4248 try {
4249 if (DBG) {
4250 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4251 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4252 }
4253
4254 IccIoResult response =
4255 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4256 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4257 subId);
4258
4259 if (DBG) {
4260 log("Exchange SIM_IO [R]" + response);
4261 }
4262
4263 byte[] result = null;
4264 int length = 2;
4265 if (response.payload != null) {
4266 length = 2 + response.payload.length;
4267 result = new byte[length];
4268 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4269 } else {
4270 result = new byte[length];
4271 }
4272
4273 result[length - 1] = (byte) response.sw2;
4274 result[length - 2] = (byte) response.sw1;
4275 return result;
4276 } finally {
4277 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004278 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004279 }
4280
Nathan Haroldb3014052017-01-25 15:57:32 -08004281 /**
4282 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4283 * on a particular subscription
4284 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004285 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4286 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004288 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004289 return null;
4290 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004291
4292 final long identity = Binder.clearCallingIdentity();
4293 try {
4294 if (appType != TelephonyManager.APPTYPE_USIM
4295 && appType != TelephonyManager.APPTYPE_SIM) {
4296 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4297 return null;
4298 }
4299 Object response = sendRequest(
4300 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4301 if (response instanceof String[]) {
4302 return (String[]) response;
4303 }
yincheng zhao2737e882019-09-06 17:06:54 -07004304 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004305 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004306 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307 } finally {
4308 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004309 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004310 }
4311
yincheng zhao2737e882019-09-06 17:06:54 -07004312 /**
4313 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4314 * subscription.
4315 *
4316 * @param subId the id of the subscription.
4317 * @param appType the uicc app type, must be USIM or SIM.
4318 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4319 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004320 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004321 * @return number of fplmns that is successfully written to the SIM.
4322 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004323 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4324 String callingFeatureId) {
4325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4326 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004327 if (DBG) logv("no permissions for setForbiddenplmns");
4328 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4329 }
4330 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4331 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4332 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4333 }
4334 if (fplmns == null) {
4335 throw new IllegalArgumentException("Fplmn List provided is null");
4336 }
4337 for (String fplmn : fplmns) {
4338 if (!CellIdentity.isValidPlmn(fplmn)) {
4339 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4340 }
4341 }
4342 final long identity = Binder.clearCallingIdentity();
4343 try {
4344 Object response = sendRequest(
4345 CMD_SET_FORBIDDEN_PLMNS,
4346 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4347 subId);
4348 return (int) response;
4349 } finally {
4350 Binder.restoreCallingIdentity(identity);
4351 }
4352 }
4353
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004354 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004355 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4357 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004359 final long identity = Binder.clearCallingIdentity();
4360 try {
4361 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4362 if (response.payload == null) {
4363 return "";
4364 }
Evan Charltonc66da362014-05-16 14:06:40 -07004365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366 // Append the returned status code to the end of the response payload.
4367 String s = Integer.toHexString(
4368 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4369 s = IccUtils.bytesToHexString(response.payload) + s;
4370 return s;
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
4373 }
Evan Charltonc66da362014-05-16 14:06:40 -07004374 }
4375
Jake Hambye994d462014-02-03 13:10:13 -08004376 /**
4377 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4378 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4379 *
4380 * @param itemID the ID of the item to read
4381 * @return the NV item as a String, or null on error.
4382 */
4383 @Override
4384 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004385 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4387 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004388
4389 final long identity = Binder.clearCallingIdentity();
4390 try {
4391 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004392 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4394 return value;
4395 } finally {
4396 Binder.restoreCallingIdentity(identity);
4397 }
Jake Hambye994d462014-02-03 13:10:13 -08004398 }
4399
4400 /**
4401 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4402 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4403 *
4404 * @param itemID the ID of the item to read
4405 * @param itemValue the value to write, as a String
4406 * @return true on success; false on any failure
4407 */
4408 @Override
4409 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004410 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4412 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004413
4414 final long identity = Binder.clearCallingIdentity();
4415 try {
4416 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4417 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004418 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4420 return success;
4421 } finally {
4422 Binder.restoreCallingIdentity(identity);
4423 }
Jake Hambye994d462014-02-03 13:10:13 -08004424 }
4425
4426 /**
4427 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4428 * Used for device configuration by some CDMA operators.
4429 *
4430 * @param preferredRoamingList byte array containing the new PRL
4431 * @return true on success; false on any failure
4432 */
4433 @Override
4434 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4436 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004437
4438 final long identity = Binder.clearCallingIdentity();
4439 try {
4440 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4441 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4442 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4443 return success;
4444 } finally {
4445 Binder.restoreCallingIdentity(identity);
4446 }
Jake Hambye994d462014-02-03 13:10:13 -08004447 }
4448
4449 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004450 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004451 * Used for device configuration by some CDMA operators.
4452 *
chen xu6dac5ab2018-10-26 17:39:23 -07004453 * @param slotIndex - device slot.
4454 *
Jake Hambye994d462014-02-03 13:10:13 -08004455 * @return true on success; false on any failure
4456 */
4457 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004458 public boolean resetModemConfig(int slotIndex) {
4459 Phone phone = PhoneFactory.getPhone(slotIndex);
4460 if (phone != null) {
4461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4462 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004463
chen xu6dac5ab2018-10-26 17:39:23 -07004464 final long identity = Binder.clearCallingIdentity();
4465 try {
4466 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4467 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4468 return success;
4469 } finally {
4470 Binder.restoreCallingIdentity(identity);
4471 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 }
chen xu6dac5ab2018-10-26 17:39:23 -07004473 return false;
4474 }
4475
4476 /**
4477 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4478 *
4479 * @param slotIndex - device slot.
4480 *
4481 * @return true on success; false on any failure
4482 */
4483 @Override
4484 public boolean rebootModem(int slotIndex) {
4485 Phone phone = PhoneFactory.getPhone(slotIndex);
4486 if (phone != null) {
4487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4488 mApp, phone.getSubId(), "rebootModem");
4489
4490 final long identity = Binder.clearCallingIdentity();
4491 try {
4492 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4493 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4494 return success;
4495 } finally {
4496 Binder.restoreCallingIdentity(identity);
4497 }
4498 }
4499 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004500 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004501
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004502 public String[] getPcscfAddress(String apnType, String callingPackage,
4503 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004504 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004505 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4506 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004507 return new String[0];
4508 }
4509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004510 final long identity = Binder.clearCallingIdentity();
4511 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004512 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
Wink Saville36469e72014-06-11 15:17:00 -07004516 }
4517
Brad Ebinger51f743a2017-01-23 13:50:20 -08004518 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004519 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4520 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004521 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004522 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004523 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004524
4525 final long identity = Binder.clearCallingIdentity();
4526 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004527 ImsResolver resolver = PhoneFactory.getImsResolver();
4528 if (resolver == null) {
4529 // may happen if the device does not support IMS.
4530 return;
4531 }
4532 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533 } finally {
4534 Binder.restoreCallingIdentity(identity);
4535 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004536 }
4537
4538 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004539 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4540 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004541 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004542 public void disableIms(int slotId) {
4543 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004544
4545 final long identity = Binder.clearCallingIdentity();
4546 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004547 ImsResolver resolver = PhoneFactory.getImsResolver();
4548 if (resolver == null) {
4549 // may happen if the device does not support IMS.
4550 return;
4551 }
4552 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 } finally {
4554 Binder.restoreCallingIdentity(identity);
4555 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004556 }
4557
4558 /**
4559 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4560 * feature or {@link null} if the service is not available. If the feature is available, the
4561 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4562 */
4563 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004564 IImsServiceFeatureCallback callback) {
4565 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004566
4567 final long identity = Binder.clearCallingIdentity();
4568 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004569 ImsResolver resolver = PhoneFactory.getImsResolver();
4570 if (resolver == null) {
4571 // may happen if the device does not support IMS.
4572 return null;
4573 }
4574 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004578 }
4579
4580 /**
4581 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4582 * feature during emergency calling or {@link null} if the service is not available. If the
4583 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4584 * listener for feature updates.
4585 */
4586 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4587 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004588
4589 final long identity = Binder.clearCallingIdentity();
4590 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004591 ImsResolver resolver = PhoneFactory.getImsResolver();
4592 if (resolver == null) {
4593 // may happen if the device does not support IMS.
4594 return null;
4595 }
4596 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004600 }
4601
Brad Ebinger5f64b052017-12-14 14:26:15 -08004602 /**
4603 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004604 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004605 */
4606 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4607 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004608
4609 final long identity = Binder.clearCallingIdentity();
4610 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004611 ImsResolver resolver = PhoneFactory.getImsResolver();
4612 if (resolver == null) {
4613 // may happen if the device does not support IMS.
4614 return null;
4615 }
4616 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004617 } finally {
4618 Binder.restoreCallingIdentity(identity);
4619 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004620 }
4621
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004622 /**
4623 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004624 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004625 */
4626 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4627 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004628
4629 final long identity = Binder.clearCallingIdentity();
4630 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004631 ImsResolver resolver = PhoneFactory.getImsResolver();
4632 if (resolver == null) {
4633 // may happen if the device does not support IMS.
4634 return null;
4635 }
4636 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637 } finally {
4638 Binder.restoreCallingIdentity(identity);
4639 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004640 }
4641
Brad Ebinger884c07b2018-02-15 16:17:40 -08004642 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004643 * Sets the ImsService Package Name that Telephony will bind to.
4644 *
4645 * @param slotId the slot ID that the ImsService should bind for.
4646 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4647 * ImsService is the device default ImsService.
4648 * @param packageName The package name of the application that contains the ImsService to bind
4649 * to.
4650 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4651 * @hide
4652 */
4653 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004654 int[] subIds = SubscriptionManager.getSubId(slotId);
4655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4656 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4657 "setImsService");
4658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004659 final long identity = Binder.clearCallingIdentity();
4660 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004661 ImsResolver resolver = PhoneFactory.getImsResolver();
4662 if (resolver == null) {
4663 // may happen if the device does not support IMS.
4664 return false;
4665 }
4666 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4667 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004668 } finally {
4669 Binder.restoreCallingIdentity(identity);
4670 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004671 }
4672
4673 /**
4674 * Return the ImsService configuration.
4675 *
4676 * @param slotId The slot that the ImsService is associated with.
4677 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4678 * the device default.
4679 * @return the package name of the ImsService configuration.
4680 */
4681 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004682 int[] subIds = SubscriptionManager.getSubId(slotId);
4683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4684 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4685 "getImsService");
4686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004687 final long identity = Binder.clearCallingIdentity();
4688 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004689 ImsResolver resolver = PhoneFactory.getImsResolver();
4690 if (resolver == null) {
4691 // may happen if the device does not support IMS.
4692 return "";
4693 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004694 // TODO: change API to query RCS separately.
4695 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4696 ImsFeature.FEATURE_MMTEL);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004697 } finally {
4698 Binder.restoreCallingIdentity(identity);
4699 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004700 }
4701
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004702 /**
4703 * Get the MmTelFeature state associated with the requested subscription id.
4704 * @param subId The subscription that the MmTelFeature is associated with.
4705 * @param callback A callback with an integer containing the
4706 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4707 */
4708 @Override
4709 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4710 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4711 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4712 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4713 "IMS not available on device.");
4714 }
4715 final long token = Binder.clearCallingIdentity();
4716 try {
4717 int slotId = getSlotIndex(subId);
4718 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4719 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4720 + subId + "'");
4721 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4722 }
4723 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4724 try {
4725 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4726 } catch (RemoteException e) {
4727 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4728 + "Ignore");
4729 }
4730 });
4731 } finally {
4732 Binder.restoreCallingIdentity(token);
4733 }
4734 }
4735
Wink Saville36469e72014-06-11 15:17:00 -07004736 public void setImsRegistrationState(boolean registered) {
4737 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004738
4739 final long identity = Binder.clearCallingIdentity();
4740 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004741 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004742 } finally {
4743 Binder.restoreCallingIdentity(identity);
4744 }
Wink Saville36469e72014-06-11 15:17:00 -07004745 }
4746
4747 /**
Stuart Scott54788802015-03-30 13:18:01 -07004748 * Set the network selection mode to automatic.
4749 *
4750 */
4751 @Override
4752 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004753 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4754 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004755
Pengquan Menge92a50d2018-09-21 15:54:48 -07004756 if (!isActiveSubscription(subId)) {
4757 return;
4758 }
4759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004760 final long identity = Binder.clearCallingIdentity();
4761 try {
4762 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4763 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4764 } finally {
4765 Binder.restoreCallingIdentity(identity);
4766 }
Stuart Scott54788802015-03-30 13:18:01 -07004767 }
4768
Pengquan Mengea84e042018-09-20 14:57:26 -07004769 /**
4770 * Ask the radio to connect to the input network and change selection mode to manual.
4771 *
4772 * @param subId the id of the subscription.
4773 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4774 * the operator to attach to.
4775 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4776 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4777 * normal network selection next time.
4778 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004779 */
4780 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004781 public boolean setNetworkSelectionModeManual(
4782 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4784 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004785
4786 if (!isActiveSubscription(subId)) {
4787 return false;
4788 }
4789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004790 final long identity = Binder.clearCallingIdentity();
4791 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004792 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004793 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004794 if (DBG) {
4795 log("setNetworkSelectionModeManual: subId: " + subId
4796 + " operator: " + operatorInfo);
4797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4799 } finally {
4800 Binder.restoreCallingIdentity(identity);
4801 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004802 }
4803
4804 /**
4805 * Scans for available networks.
4806 */
4807 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004808 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4809 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4811 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004812 LocationAccessPolicy.LocationPermissionResult locationResult =
4813 LocationAccessPolicy.checkLocationPermission(mApp,
4814 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4815 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004816 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004817 .setCallingPid(Binder.getCallingPid())
4818 .setCallingUid(Binder.getCallingUid())
4819 .setMethod("getCellNetworkScanResults")
4820 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4821 .build());
4822 switch (locationResult) {
4823 case DENIED_HARD:
4824 throw new SecurityException("Not allowed to access scan results -- location");
4825 case DENIED_SOFT:
4826 return null;
4827 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004828
Pengquan Menga1bb6272018-09-06 09:59:22 -07004829 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004830 try {
4831 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004832 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004834 } finally {
4835 Binder.restoreCallingIdentity(identity);
4836 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004837 }
4838
4839 /**
yinxub1bed742017-04-17 11:45:04 -07004840 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004841 *
yinxub1bed742017-04-17 11:45:04 -07004842 * @param subId id of the subscription
4843 * @param request contains the radio access networks with bands/channels to scan
4844 * @param messenger callback messenger for scan results or errors
4845 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004846 * @return the id of the requested scan which can be used to stop the scan.
4847 */
4848 @Override
4849 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004850 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4852 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004853 LocationAccessPolicy.LocationPermissionResult locationResult =
4854 LocationAccessPolicy.checkLocationPermission(mApp,
4855 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4856 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004857 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004858 .setCallingPid(Binder.getCallingPid())
4859 .setCallingUid(Binder.getCallingUid())
4860 .setMethod("requestNetworkScan")
4861 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4862 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004863 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004864 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004865 if (e != null) {
4866 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4867 throw e;
4868 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004869 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004870 return TelephonyScanManager.INVALID_SCAN_ID;
4871 }
4872 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873 }
Hall Liu912dfd32019-04-25 14:02:26 -07004874 int callingUid = Binder.getCallingUid();
4875 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004876 final long identity = Binder.clearCallingIdentity();
4877 try {
4878 return mNetworkScanRequestTracker.startNetworkScan(
4879 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004880 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004881 } finally {
4882 Binder.restoreCallingIdentity(identity);
4883 }
yinxu504e1392017-04-12 16:03:22 -07004884 }
4885
Hall Liub2ac8ef2019-02-28 15:56:23 -08004886 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004887 NetworkScanRequest request, int subId) {
4888 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4889 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4890 boolean hasNetworkScanPermission =
4891 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4892 == PERMISSION_GRANTED;
4893
4894 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4895 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4896 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004897 }
4898
4899 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4900 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004901 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4902 return new SecurityException("Specific channels must not be"
4903 + " scanned without location access.");
4904 }
4905 }
4906 }
4907
Hall Liub2ac8ef2019-02-28 15:56:23 -08004908 return null;
4909 }
4910
yinxu504e1392017-04-12 16:03:22 -07004911 /**
4912 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004913 *
4914 * @param subId id of the subscription
4915 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004916 */
4917 @Override
4918 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4920 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921
Hall Liu912dfd32019-04-25 14:02:26 -07004922 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923 final long identity = Binder.clearCallingIdentity();
4924 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004925 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004926 } finally {
4927 Binder.restoreCallingIdentity(identity);
4928 }
yinxu504e1392017-04-12 16:03:22 -07004929 }
4930
4931 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004932 * Get the calculated preferred network type.
4933 * Used for debugging incorrect network type.
4934 *
4935 * @return the preferred network type, defined in RILConstants.java.
4936 */
4937 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004938 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004939 final Phone defaultPhone = getDefaultPhone();
4940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004941 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004942 return RILConstants.PREFERRED_NETWORK_MODE;
4943 }
4944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945 final long identity = Binder.clearCallingIdentity();
4946 try {
4947 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004948 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 } finally {
4950 Binder.restoreCallingIdentity(identity);
4951 }
Junda Liu84d15a22014-07-02 11:21:04 -07004952 }
4953
4954 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004955 * Get the preferred network type.
4956 * Used for device configuration by some CDMA operators.
4957 *
4958 * @return the preferred network type, defined in RILConstants.java.
4959 */
4960 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004961 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004962 TelephonyPermissions
4963 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4964 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965
4966 final long identity = Binder.clearCallingIdentity();
4967 try {
4968 if (DBG) log("getPreferredNetworkType");
4969 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4970 int networkType = (result != null ? result[0] : -1);
4971 if (DBG) log("getPreferredNetworkType: " + networkType);
4972 return networkType;
4973 } finally {
4974 Binder.restoreCallingIdentity(identity);
4975 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004976 }
4977
4978 /**
4979 * Set the preferred network type.
4980 * Used for device configuration by some CDMA operators.
4981 *
4982 * @param networkType the preferred network type, defined in RILConstants.java.
4983 * @return true on success; false on any failure.
4984 */
4985 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004986 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4988 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989
4990 final long identity = Binder.clearCallingIdentity();
4991 try {
4992 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4993 Boolean success = (Boolean) sendRequest(
4994 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4995 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4996 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004997 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4999 }
5000 return success;
5001 } finally {
5002 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005003 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005004 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005005
5006 /**
Miaoa84611c2019-03-15 09:21:10 +08005007 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005008 *
Miaoa84611c2019-03-15 09:21:10 +08005009 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005010 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005011 * @hide
5012 */
5013 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005014 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005015 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005017 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018 try {
Miaoa84611c2019-03-15 09:21:10 +08005019 if (phone != null) {
5020 return phone.hasMatchedTetherApnSetting();
5021 } else {
5022 return false;
5023 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024 } finally {
5025 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005026 }
Junda Liu475951f2014-11-07 16:45:03 -08005027 }
5028
5029 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005030 * Set mobile data enabled
5031 * Used by the user through settings etc to turn on/off mobile data
5032 *
5033 * @param enable {@code true} turn turn data on, else {@code false}
5034 */
5035 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005036 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5038 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005039
5040 final long identity = Binder.clearCallingIdentity();
5041 try {
5042 int phoneId = mSubscriptionController.getPhoneId(subId);
5043 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5044 Phone phone = PhoneFactory.getPhone(phoneId);
5045 if (phone != null) {
5046 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005047 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005048 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005049 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050 }
5051 } finally {
5052 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005053 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005054 }
5055
5056 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005057 * Get the user enabled state of Mobile Data.
5058 *
5059 * TODO: remove and use isUserDataEnabled.
5060 * This can't be removed now because some vendor codes
5061 * calls through ITelephony directly while they should
5062 * use TelephonyManager.
5063 *
5064 * @return true on enabled
5065 */
5066 @Override
5067 public boolean getDataEnabled(int subId) {
5068 return isUserDataEnabled(subId);
5069 }
5070
5071 /**
5072 * Get whether mobile data is enabled per user setting.
5073 *
5074 * There are other factors deciding whether mobile data is actually enabled, but they are
5075 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005076 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005077 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005078 *
5079 * @return {@code true} if data is enabled else {@code false}
5080 */
5081 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005082 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005083 try {
5084 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5085 null);
5086 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5088 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005089 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090
5091 final long identity = Binder.clearCallingIdentity();
5092 try {
5093 int phoneId = mSubscriptionController.getPhoneId(subId);
5094 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5095 Phone phone = PhoneFactory.getPhone(phoneId);
5096 if (phone != null) {
5097 boolean retVal = phone.isUserDataEnabled();
5098 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5099 return retVal;
5100 } else {
5101 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5102 return false;
5103 }
5104 } finally {
5105 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005106 }
5107 }
5108
5109 /**
5110 * Get whether mobile data is enabled.
5111 *
5112 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5113 * whether mobile data is actually enabled.
5114 *
5115 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5116 *
5117 * @return {@code true} if data is enabled else {@code false}
5118 */
5119 @Override
5120 public boolean isDataEnabled(int subId) {
5121 try {
5122 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5123 null);
5124 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5126 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128
5129 final long identity = Binder.clearCallingIdentity();
5130 try {
5131 int phoneId = mSubscriptionController.getPhoneId(subId);
5132 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5133 Phone phone = PhoneFactory.getPhone(phoneId);
5134 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005135 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005136 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5137 return retVal;
5138 } else {
5139 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5140 return false;
5141 }
5142 } finally {
5143 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005144 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005145 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005146
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005147 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5148 Phone phone) {
5149 //load access rules from carrier configs, and check those as well: b/139133814
5150 SubscriptionController subController = SubscriptionController.getInstance();
5151 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5152 || subController == null) return privilegeFromSim;
5153
5154 int uid = Binder.getCallingUid();
5155 PackageManager pkgMgr = phone.getContext().getPackageManager();
5156 String[] packages = pkgMgr.getPackagesForUid(uid);
5157
5158 final long identity = Binder.clearCallingIdentity();
5159 try {
5160 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5161 SubscriptionManager subManager = (SubscriptionManager)
5162 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5163 for (String pkg : packages) {
5164 if (subManager.canManageSubscription(subInfo, pkg)) {
5165 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5166 }
5167 }
5168 return privilegeFromSim;
5169 } finally {
5170 Binder.restoreCallingIdentity(identity);
5171 }
5172 }
5173
5174 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5175 String pkgName) {
5176 //load access rules from carrier configs, and check those as well: b/139133814
5177 SubscriptionController subController = SubscriptionController.getInstance();
5178 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5179 || subController == null) return privilegeFromSim;
5180
5181 final long identity = Binder.clearCallingIdentity();
5182 try {
5183 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5184 SubscriptionManager subManager = (SubscriptionManager)
5185 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5186 return subManager.canManageSubscription(subInfo, pkgName)
5187 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5188 } finally {
5189 Binder.restoreCallingIdentity(identity);
5190 }
5191 }
5192
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005193 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005194 public int getCarrierPrivilegeStatus(int subId) {
5195 final Phone phone = getPhone(subId);
5196 if (phone == null) {
5197 loge("getCarrierPrivilegeStatus: Invalid subId");
5198 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5199 }
5200 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005201 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005202 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005203 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5204 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005205
5206 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5207 card.getCarrierPrivilegeStatusForCurrentTransaction(
5208 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005209 }
Junda Liu29340342014-07-10 15:23:27 -07005210
5211 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005212 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005213 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005214 final Phone phone = getPhone(subId);
5215 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005216 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005217 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5218 }
5219 UiccProfile profile =
5220 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5221 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005222 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005223 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5224 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005225 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005226 profile.getCarrierPrivilegeStatusForUid(
5227 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005228 }
5229
5230 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005231 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5232 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005233 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005234 }
5235
5236 int phoneId = SubscriptionManager.getPhoneId(subId);
5237 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005238 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005239 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005240 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5241 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005242 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5243 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5244 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005245 }
5246
5247 @Override
5248 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005249 if (TextUtils.isEmpty(pkgName))
5250 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005251 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5252 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5253 UiccCard card = UiccController.getInstance().getUiccCard(i);
5254 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005255 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005256 continue;
5257 }
5258
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005259 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5260 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5261 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005262 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5263 break;
5264 }
5265 }
5266
5267 return result;
Junda Liu29340342014-07-10 15:23:27 -07005268 }
Derek Tan89e89d42014-07-08 17:00:10 -07005269
5270 @Override
Junda Liue64de782015-04-16 17:19:16 -07005271 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5272 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5273 loge("phoneId " + phoneId + " is not valid.");
5274 return null;
5275 }
5276 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005277 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005278 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005279 return null ;
5280 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005281 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005282 }
5283
Amith Yamasani6e118872016-02-19 12:53:51 -08005284 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005285 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005286 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005287 List<String> privilegedPackages = new ArrayList<>();
5288 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005289 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5290 // has UICC in that slot.
5291 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005292 if (card.hasCarrierPrivilegeRules()) {
5293 if (packages == null) {
5294 // Only check packages in user 0 for now
5295 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005296 PackageManager.MATCH_DISABLED_COMPONENTS
5297 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005298 | PackageManager.GET_SIGNING_CERTIFICATES,
5299 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005300 }
5301 for (int p = packages.size() - 1; p >= 0; p--) {
5302 PackageInfo pkgInfo = packages.get(p);
5303 if (pkgInfo != null && pkgInfo.packageName != null
5304 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005305 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005306 privilegedPackages.add(pkgInfo.packageName);
5307 }
5308 }
5309 }
5310 }
5311 return privilegedPackages;
5312 }
5313
chen xuf7e9fe82019-05-09 19:31:02 -07005314 @Override
5315 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005316 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5317
5318 final long identity = Binder.clearCallingIdentity();
5319
chen xuf7e9fe82019-05-09 19:31:02 -07005320 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005321 try {
5322 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5323 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5324 }
5325 } finally {
5326 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005327 }
5328 return privilegedPackages;
5329 }
5330
Wink Savilleb564aae2014-10-23 10:18:09 -07005331 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005332 final Phone phone = getPhone(subId);
5333 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005334 if (card == null) {
5335 loge("getIccId: No UICC");
5336 return null;
5337 }
5338 String iccId = card.getIccId();
5339 if (TextUtils.isEmpty(iccId)) {
5340 loge("getIccId: ICC ID is null or empty.");
5341 return null;
5342 }
5343 return iccId;
5344 }
5345
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005346 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005347 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5348 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005349 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005350 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 final long identity = Binder.clearCallingIdentity();
5353 try {
5354 final String iccId = getIccId(subId);
5355 final Phone phone = getPhone(subId);
5356 if (phone == null) {
5357 return false;
5358 }
5359 final String subscriberId = phone.getSubscriberId();
5360
5361 if (DBG_MERGE) {
5362 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5363 + subscriberId + " to " + number);
5364 }
5365
5366 if (TextUtils.isEmpty(iccId)) {
5367 return false;
5368 }
5369
5370 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5371
5372 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5373 if (alphaTag == null) {
5374 editor.remove(alphaTagPrefKey);
5375 } else {
5376 editor.putString(alphaTagPrefKey, alphaTag);
5377 }
5378
5379 // Record both the line number and IMSI for this ICCID, since we need to
5380 // track all merged IMSIs based on line number
5381 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5382 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5383 if (number == null) {
5384 editor.remove(numberPrefKey);
5385 editor.remove(subscriberPrefKey);
5386 } else {
5387 editor.putString(numberPrefKey, number);
5388 editor.putString(subscriberPrefKey, subscriberId);
5389 }
5390
5391 editor.commit();
5392 return true;
5393 } finally {
5394 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005395 }
Derek Tan7226c842014-07-02 17:42:23 -07005396 }
5397
5398 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005399 public String getLine1NumberForDisplay(int subId, String callingPackage,
5400 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005401 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005402 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005403 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005404 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005405 return null;
5406 }
Derek Tan97ebb422014-09-05 16:55:38 -07005407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 final long identity = Binder.clearCallingIdentity();
5409 try {
5410 String iccId = getIccId(subId);
5411 if (iccId != null) {
5412 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5413 if (DBG_MERGE) {
5414 log("getLine1NumberForDisplay returning "
5415 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5416 }
5417 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5420 return null;
5421 } finally {
5422 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005423 }
Derek Tan7226c842014-07-02 17:42:23 -07005424 }
5425
5426 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005427 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5428 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005430 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005431 return null;
5432 }
Derek Tan97ebb422014-09-05 16:55:38 -07005433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005434 final long identity = Binder.clearCallingIdentity();
5435 try {
5436 String iccId = getIccId(subId);
5437 if (iccId != null) {
5438 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5439 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5440 }
5441 return null;
5442 } finally {
5443 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005444 }
Derek Tan7226c842014-07-02 17:42:23 -07005445 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005446
5447 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005448 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5449 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005450 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5451 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005452 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005453 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005454 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005455 return null;
5456 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005457
Jordan Liub49b04b2019-05-06 14:45:15 -07005458 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5459 // the process, where TelephonyManager was instantiated.
5460 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005461 final long identity = Binder.clearCallingIdentity();
5462 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005463 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464 final TelephonyManager tele = TelephonyManager.from(context);
5465 final SubscriptionManager sub = SubscriptionManager.from(context);
5466
5467 // Figure out what subscribers are currently active
5468 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469
Jordan Liub49b04b2019-05-06 14:45:15 -07005470 // Only consider subs which match the current subId
5471 // This logic can be simplified. See b/131189269 for progress.
5472 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005473 activeSubscriberIds.add(tele.getSubscriberId(subId));
5474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475
5476 // First pass, find a number override for an active subscriber
5477 String mergeNumber = null;
5478 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5479 for (String key : prefs.keySet()) {
5480 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5481 final String subscriberId = (String) prefs.get(key);
5482 if (activeSubscriberIds.contains(subscriberId)) {
5483 final String iccId = key.substring(
5484 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5485 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5486 mergeNumber = (String) prefs.get(numberKey);
5487 if (DBG_MERGE) {
5488 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5489 + " for active subscriber " + subscriberId);
5490 }
5491 if (!TextUtils.isEmpty(mergeNumber)) {
5492 break;
5493 }
5494 }
5495 }
5496 }
5497
5498 // Shortcut when no active merged subscribers
5499 if (TextUtils.isEmpty(mergeNumber)) {
5500 return null;
5501 }
5502
5503 // Second pass, find all subscribers under that line override
5504 final ArraySet<String> result = new ArraySet<>();
5505 for (String key : prefs.keySet()) {
5506 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5507 final String number = (String) prefs.get(key);
5508 if (mergeNumber.equals(number)) {
5509 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5510 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5511 final String subscriberId = (String) prefs.get(subscriberKey);
5512 if (!TextUtils.isEmpty(subscriberId)) {
5513 result.add(subscriberId);
5514 }
5515 }
5516 }
5517 }
5518
5519 final String[] resultArray = result.toArray(new String[result.size()]);
5520 Arrays.sort(resultArray);
5521 if (DBG_MERGE) {
5522 Slog.d(LOG_TAG,
5523 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5524 }
5525 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005526 } finally {
5527 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005528 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005529 }
5530
5531 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005532 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5533 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5534
5535 final long identity = Binder.clearCallingIdentity();
5536 try {
5537 final TelephonyManager telephonyManager = mApp.getSystemService(
5538 TelephonyManager.class);
5539 String subscriberId = telephonyManager.getSubscriberId(subId);
5540 if (subscriberId == null) {
5541 if (DBG) {
5542 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5543 + subId);
5544 }
5545 return null;
5546 }
5547
5548 final SubscriptionInfo info = SubscriptionController.getInstance()
5549 .getSubscriptionInfo(subId);
5550 final ParcelUuid groupUuid = info.getGroupUuid();
5551 // If it doesn't belong to any group, return just subscriberId of itself.
5552 if (groupUuid == null) {
5553 return new String[]{subscriberId};
5554 }
5555
5556 // Get all subscriberIds from the group.
5557 final List<String> mergedSubscriberIds = new ArrayList<>();
5558 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005559 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5560 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005561 for (SubscriptionInfo subInfo : groupInfos) {
5562 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5563 if (subscriberId != null) {
5564 mergedSubscriberIds.add(subscriberId);
5565 }
5566 }
5567
5568 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5569 } finally {
5570 Binder.restoreCallingIdentity(identity);
5571
5572 }
5573 }
5574
5575 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005576 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005577 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005578 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579
5580 final long identity = Binder.clearCallingIdentity();
5581 try {
5582 final Phone phone = getPhone(subId);
5583 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5584 } finally {
5585 Binder.restoreCallingIdentity(identity);
5586 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005587 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005588
5589 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005590 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005591 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5592 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005593 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5594 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595
5596 final long identity = Binder.clearCallingIdentity();
5597 try {
5598 final Phone phone = getPhone(subId);
5599 if (phone == null) {
5600 return false;
5601 }
5602 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5603 cdmaNonRoamingList);
5604 } finally {
5605 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005606 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005607 }
5608
5609 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005610 @Deprecated
5611 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5612 enforceModifyPermission();
5613
5614 int returnValue = 0;
5615 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005616 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005617 if(result.exception == null) {
5618 if (result.result != null) {
5619 byte[] responseData = (byte[])(result.result);
5620 if(responseData.length > oemResp.length) {
5621 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5622 responseData.length + "bytes. Buffer Size is " +
5623 oemResp.length + "bytes.");
5624 }
5625 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5626 returnValue = responseData.length;
5627 }
5628 } else {
5629 CommandException ex = (CommandException) result.exception;
5630 returnValue = ex.getCommandError().ordinal();
5631 if(returnValue > 0) returnValue *= -1;
5632 }
5633 } catch (RuntimeException e) {
5634 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5635 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5636 if(returnValue > 0) returnValue *= -1;
5637 }
5638
5639 return returnValue;
5640 }
5641
5642 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005643 public void setRadioCapability(RadioAccessFamily[] rafs) {
5644 try {
5645 ProxyController.getInstance().setRadioCapability(rafs);
5646 } catch (RuntimeException e) {
5647 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5648 }
5649 }
5650
5651 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005652 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005653 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005654 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005655 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005656 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658 final long identity = Binder.clearCallingIdentity();
5659 try {
chen xub97461a2018-10-26 14:17:57 -07005660 TelephonyPermissions
5661 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5662 mApp, phone.getSubId(), "getRadioAccessFamily");
5663 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 } finally {
5665 Binder.restoreCallingIdentity(identity);
5666 }
chen xub97461a2018-10-26 14:17:57 -07005667 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005668 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005669
5670 @Override
5671 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005672 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005673 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674
5675 final long identity = Binder.clearCallingIdentity();
5676 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005677 ImsManager.getInstance(defaultPhone.getContext(),
5678 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 } finally {
5680 Binder.restoreCallingIdentity(identity);
5681 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005682 }
5683
5684 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005685 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005686 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005687 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5688 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005689 return false;
5690 }
Svet Ganovb320e182015-04-16 12:30:10 -07005691
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 final long identity = Binder.clearCallingIdentity();
5693 try {
5694 // Check the user preference and the system-level IMS setting. Even if the user has
5695 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5696 // In the long run, we may instead need to check if there exists a connection service
5697 // which can support video calling.
5698 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005699 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 return imsManager.isVtEnabledByPlatform()
5701 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5702 && imsManager.isVtEnabledByUser();
5703 } finally {
5704 Binder.restoreCallingIdentity(identity);
5705 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005706 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005707
Andrew Leea1239f22015-03-02 17:44:07 -08005708 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005709 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5710 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005712 mApp, subId, callingPackage, callingFeatureId,
5713 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714 return false;
5715 }
5716
5717 final long identity = Binder.clearCallingIdentity();
5718 try {
5719 CarrierConfigManager configManager =
5720 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005721 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
Andrew Leea1239f22015-03-02 17:44:07 -08005726 }
5727
5728 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005729 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005731 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 return false;
5733 }
5734
5735 final long identity = Binder.clearCallingIdentity();
5736 try {
5737 CarrierConfigManager configManager =
5738 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005739 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5741 } finally {
5742 Binder.restoreCallingIdentity(identity);
5743 }
Andrew Leea1239f22015-03-02 17:44:07 -08005744 }
5745
Andrew Lee9431b832015-03-09 18:46:45 -07005746 @Override
5747 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005748 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005749 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005750 }
5751
5752 @Override
5753 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 final long identity = Binder.clearCallingIdentity();
5755 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005756 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005757 } finally {
5758 Binder.restoreCallingIdentity(identity);
5759 }
Andrew Lee9431b832015-03-09 18:46:45 -07005760 }
5761
Hall Liuf6668912018-10-31 17:05:23 -07005762 /**
5763 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5764 * support for the feature and device firmware support.
5765 *
5766 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5767 */
5768 @Override
5769 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005771 final Phone phone = getPhone(subscriptionId);
5772 if (phone == null) {
5773 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5774 return false;
5775 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005777 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5779 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005780 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781 return isCarrierSupported && isDeviceSupported;
5782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
Hall Liu98187582018-01-22 19:15:32 -08005785 }
5786
Hall Liuf6668912018-10-31 17:05:23 -07005787 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005788 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5789 * RTT setting, will return true if the device and carrier both support RTT.
5790 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005791 */
5792 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 final long identity = Binder.clearCallingIdentity();
5794 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00005795 boolean isRttSupported = isRttSupported(subscriptionId);
5796 boolean isUserRttSettingOn = Settings.Secure.getInt(
5797 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5798 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5799 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5800 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801 } finally {
5802 Binder.restoreCallingIdentity(identity);
5803 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005804 }
5805
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005806 @Deprecated
5807 @Override
5808 public String getDeviceId(String callingPackage) {
5809 return getDeviceIdWithFeature(callingPackage, null);
5810 }
5811
Sanket Padawe7310cc72015-01-14 09:53:20 -08005812 /**
5813 * Returns the unique device ID of phone, for example, the IMEI for
5814 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5815 *
5816 * <p>Requires Permission:
5817 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5818 */
5819 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005820 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005821 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005822 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005823 return null;
5824 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005825 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005826 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005827 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005828 return null;
5829 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830
5831 final long identity = Binder.clearCallingIdentity();
5832 try {
5833 return phone.getDeviceId();
5834 } finally {
5835 Binder.restoreCallingIdentity(identity);
5836 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005837 }
5838
Ping Sunc67b7c22016-03-02 19:16:45 +08005839 /**
5840 * {@hide}
5841 * Returns the IMS Registration Status on a particular subid
5842 *
5843 * @param subId
5844 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005845 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005846 Phone phone = getPhone(subId);
5847 if (phone != null) {
5848 return phone.isImsRegistered();
5849 } else {
5850 return false;
5851 }
5852 }
5853
Santos Cordon7a1885b2015-02-03 11:15:19 -08005854 @Override
5855 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856 final long identity = Binder.clearCallingIdentity();
5857 try {
5858 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5859 } finally {
5860 Binder.restoreCallingIdentity(identity);
5861 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005862 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005863
Tyler Gunnf70ed162019-04-03 15:28:53 -07005864 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005865 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005866 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005867 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005868 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005869 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5870 }
5871 final long identity = Binder.clearCallingIdentity();
5872 try {
5873 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5874 } finally {
5875 Binder.restoreCallingIdentity(identity);
5876 }
5877 }
5878
5879 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005880 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5881 final long identity = Binder.clearCallingIdentity();
5882 try {
5883 Phone phone = getPhone(subscriptionId);
5884 if (phone == null) {
5885 return null;
5886 }
5887 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5888 } finally {
5889 Binder.restoreCallingIdentity(identity);
5890 }
5891 }
5892
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005893 /**
5894 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005895 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005896 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 final long identity = Binder.clearCallingIdentity();
5898 try {
5899 Phone phone = getPhone(subId);
5900 if (phone != null) {
5901 return phone.isWifiCallingEnabled();
5902 } else {
5903 return false;
5904 }
5905 } finally {
5906 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005907 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005908 }
5909
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005910 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005911 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005912 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005913 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914 final long identity = Binder.clearCallingIdentity();
5915 try {
5916 Phone phone = getPhone(subId);
5917 if (phone != null) {
5918 return phone.isVideoEnabled();
5919 } else {
5920 return false;
5921 }
5922 } finally {
5923 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005924 }
5925 }
5926
5927 /**
5928 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5929 * defined in {@link ImsRegistrationImplBase}.
5930 */
5931 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932 final long identity = Binder.clearCallingIdentity();
5933 try {
5934 Phone phone = getPhone(subId);
5935 if (phone != null) {
5936 return phone.getImsRegistrationTech();
5937 } else {
5938 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5939 }
5940 } finally {
5941 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005942 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005943 }
5944
Stuart Scott8eef64f2015-04-08 15:13:54 -07005945 @Override
5946 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08005947 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005948 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5949 return;
5950 }
5951
Svet Ganovcc087f82015-05-12 20:35:54 -07005952 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005953
Svet Ganovcc087f82015-05-12 20:35:54 -07005954 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005955 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5956 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005957 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005958 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005959 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005960 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5961 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005962 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005963 // There has been issues when Sms raw table somehow stores orphan
5964 // fragments. They lead to garbled message when new fragments come
5965 // in and combined with those stale ones. In case this happens again,
5966 // user can reset all network settings which will clean up this table.
5967 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005968 // Clean up IMS settings as well here.
5969 int slotId = getSlotIndex(subId);
5970 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5971 ImsManager.getInstance(mApp, slotId).factoryReset();
5972 }
Naina Nallurid63128d2019-09-17 14:10:30 -07005973
5974 // Erase modem config if erase modem on network setting is enabled.
5975 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5976 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5977 if (configValue != null && Boolean.parseBoolean(configValue)) {
5978 sendEraseModemConfig(getDefaultPhone());
5979 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005980 } finally {
5981 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005982 }
5983 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005984
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005985 private void cleanUpSmsRawTable(Context context) {
5986 ContentResolver resolver = context.getContentResolver();
5987 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5988 resolver.delete(uri, null, null);
5989 }
5990
Narayan Kamath1c496c22015-04-16 14:40:19 +01005991 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005992 public String getSimLocaleForSubscriber(int subId) {
5993 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5994 final Phone phone = getPhone(subId);
5995 if (phone == null) {
5996 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005997 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 final long identity = Binder.clearCallingIdentity();
6000 try {
chen xu5d3637b2019-01-21 23:31:38 -08006001 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006002 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006003 if (info == null) {
6004 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6005 return null;
6006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 // Try and fetch the locale from the carrier properties or from the SIM language
6008 // preferences (EF-PL and EF-LI)...
6009 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006011 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6012 if (localeFromDefaultSim != null) {
6013 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6014 if (DBG) log("Using locale from subId: " + subId + " locale: "
6015 + localeFromDefaultSim);
6016 return localeFromDefaultSim.toLanguageTag();
6017 } else {
6018 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 }
6020 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 // The SIM language preferences only store a language (e.g. fr = French), not an
6023 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6024 // the SIM and carrier preferences does not include a country we add the country
6025 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006026 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006028 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029 return mccLocale.toLanguageTag();
6030 }
6031
6032 if (DBG) log("No locale found - returning null");
6033 return null;
6034 } finally {
6035 Binder.restoreCallingIdentity(identity);
6036 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006037 }
6038
6039 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006040 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6041 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006042 }
6043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 /**
6045 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6046 */
6047 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006048 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6049 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006050 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006051
Chenjie Yu1ba97252018-01-11 18:16:20 -08006052 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006053 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006054
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006055 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006056 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6057 * representing the state of the modem.
6058 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006059 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6060 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006061 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006062 */
6063 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006064 public void requestModemActivityInfo(ResultReceiver result) {
6065 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006066 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067
6068 final long identity = Binder.clearCallingIdentity();
6069 try {
6070 ModemActivityInfo ret = null;
6071 synchronized (mLastModemActivityInfo) {
6072 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6073 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006074 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006075 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006077 int[] txTimeMs = info.getTransmitTimeMillis();
6078 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006080 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 }
6082 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006083 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6084 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 mLastModemActivityInfo.setIdleTimeMillis(
6086 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006087 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6088 mLastModemActivityInfo.setReceiveTimeMillis(
6089 info.getReceiveTimeMillis() + mLastModemActivityInfo
6090 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006091 }
Chen Xud78231e2019-09-10 18:49:52 -07006092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6094 mLastModemActivityInfo.getSleepTimeMillis(),
6095 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006096 mLastModemActivityInfo.getTransmitTimeMillis(),
6097 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006098 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099 Bundle bundle = new Bundle();
6100 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6101 result.send(0, bundle);
6102 } finally {
6103 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006104 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006105 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006106
Siddharth Rayb8114062018-06-17 15:02:38 -07006107 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6108 // less than total activity duration.
6109 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6110 if (info == null) {
6111 return false;
6112 }
6113 int activityDurationMs =
6114 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6115 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006116 int[] txTimeMs = info.getTransmitTimeMillis();
6117 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6118 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006119 }
6120 return (info.isValid()
6121 && (info.getSleepTimeMillis() <= activityDurationMs)
6122 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006123 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006124 && (totalTxTimeMs <= activityDurationMs));
6125 }
6126
Jack Yu85bd38a2015-11-09 11:34:32 -08006127 /**
6128 * {@hide}
6129 * Returns the service state information on specified subscription.
6130 */
6131 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006132 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6133 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006135 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006136 return null;
6137 }
6138
Hall Liuf19c44f2018-11-27 14:38:17 -08006139 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
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 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6149 .build());
6150
6151 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6152 LocationAccessPolicy.checkLocationPermission(mApp,
6153 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6154 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006155 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006156 .setCallingPid(Binder.getCallingPid())
6157 .setCallingUid(Binder.getCallingUid())
6158 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006159 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006160 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6161 .build());
6162 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6163 boolean hasFinePermission =
6164 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6165 boolean hasCoarsePermission =
6166 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 final long identity = Binder.clearCallingIdentity();
6169 try {
6170 final Phone phone = getPhone(subId);
6171 if (phone == null) {
6172 return null;
6173 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006174
Hall Liuf19c44f2018-11-27 14:38:17 -08006175 ServiceState ss = phone.getServiceState();
6176
6177 // Scrub out the location info in ServiceState depending on what level of access
6178 // the caller has.
6179 if (hasFinePermission) return ss;
6180 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6181 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182 } finally {
6183 Binder.restoreCallingIdentity(identity);
6184 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006185 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006186
6187 /**
6188 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6189 *
6190 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6191 * voicemail ringtone.
6192 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6193 * PhoneAccount.
6194 */
6195 @Override
6196 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006197 final long identity = Binder.clearCallingIdentity();
6198 try {
6199 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6200 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006201 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006202 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006203
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6205 } finally {
6206 Binder.restoreCallingIdentity(identity);
6207 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006208 }
6209
6210 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006211 * Sets the per-account voicemail ringtone.
6212 *
6213 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6214 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6215 *
6216 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6217 * voicemail ringtone.
6218 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6219 * PhoneAccount.
6220 */
6221 @Override
6222 public void setVoicemailRingtoneUri(String callingPackage,
6223 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006224 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006225 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006226 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6227 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6229 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6230 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232
6233 final long identity = Binder.clearCallingIdentity();
6234 try {
6235 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6236 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006237 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 }
6239 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6240 } finally {
6241 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006242 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006243 }
6244
6245 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006246 * Returns whether vibration is set for voicemail notification in Phone settings.
6247 *
6248 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6249 * voicemail vibration setting.
6250 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6251 */
6252 @Override
6253 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006254 final long identity = Binder.clearCallingIdentity();
6255 try {
6256 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6257 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006258 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006261 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6262 } finally {
6263 Binder.restoreCallingIdentity(identity);
6264 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006265 }
6266
Youhan Wange64578a2016-05-02 15:32:42 -07006267 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006268 * Sets the per-account voicemail vibration.
6269 *
6270 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6271 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6272 *
6273 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6274 * voicemail vibration setting.
6275 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6276 * specific PhoneAccount.
6277 */
6278 @Override
6279 public void setVoicemailVibrationEnabled(String callingPackage,
6280 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006281 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006282 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006283 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6284 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6286 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6287 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006288 }
6289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 final long identity = Binder.clearCallingIdentity();
6291 try {
6292 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6293 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006294 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006295 }
6296 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6297 } finally {
6298 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006299 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006300 }
6301
6302 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006303 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6304 *
6305 * @throws SecurityException if the caller does not have the required permission
6306 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006307 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006308 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006309 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006310 }
6311
6312 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006313 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6314 * permission.
6315 *
6316 * @throws SecurityException if the caller does not have the required permission
6317 */
6318 private void enforceSendSmsPermission() {
6319 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6320 }
6321
6322 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006323 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006324 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006325 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006326 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006327 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328 final long identity = Binder.clearCallingIdentity();
6329 try {
6330 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006331 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 if (componentName == null) {
6333 throw new SecurityException(
6334 "Caller not current active visual voicemail package[null]");
6335 }
6336 String vvmPackage = componentName.getPackageName();
6337 if (!callingPackage.equals(vvmPackage)) {
6338 throw new SecurityException("Caller not current active visual voicemail package["
6339 + vvmPackage + "]");
6340 }
6341 } finally {
6342 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006343 }
6344 }
6345
6346 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006347 * Return the application ID for the app type.
6348 *
6349 * @param subId the subscription ID that this request applies to.
6350 * @param appType the uicc app type.
6351 * @return Application ID for specificied app type, or null if no uicc.
6352 */
6353 @Override
6354 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006355 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006356 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006357
6358 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006359 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360 if (phone == null) {
6361 return null;
6362 }
6363 String aid = null;
6364 try {
6365 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6366 .getApplicationByType(appType).getAid();
6367 } catch (Exception e) {
6368 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6369 }
6370 return aid;
6371 } finally {
6372 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006373 }
Youhan Wange64578a2016-05-02 15:32:42 -07006374 }
6375
Youhan Wang4001d252016-05-11 10:29:41 -07006376 /**
6377 * Return the Electronic Serial Number.
6378 *
6379 * @param subId the subscription ID that this request applies to.
6380 * @return ESN or null if error.
6381 */
6382 @Override
6383 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006384 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006385 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386
6387 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006388 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389 if (phone == null) {
6390 return null;
6391 }
6392 String esn = null;
6393 try {
6394 esn = phone.getEsn();
6395 } catch (Exception e) {
6396 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6397 }
6398 return esn;
6399 } finally {
6400 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006401 }
Youhan Wang4001d252016-05-11 10:29:41 -07006402 }
6403
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006404 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006405 * Return the Preferred Roaming List Version.
6406 *
6407 * @param subId the subscription ID that this request applies to.
6408 * @return PRLVersion or null if error.
6409 */
6410 @Override
6411 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006412 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006413 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414
6415 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006416 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 if (phone == null) {
6418 return null;
6419 }
6420 String cdmaPrlVersion = null;
6421 try {
6422 cdmaPrlVersion = phone.getCdmaPrlVersion();
6423 } catch (Exception e) {
6424 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6425 }
6426 return cdmaPrlVersion;
6427 } finally {
6428 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006429 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006430 }
6431
6432 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006433 * Get snapshot of Telephony histograms
6434 * @return List of Telephony histograms
6435 * @hide
6436 */
6437 @Override
6438 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6440 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006441
6442 final long identity = Binder.clearCallingIdentity();
6443 try {
6444 return RIL.getTelephonyRILTimingHistograms();
6445 } finally {
6446 Binder.restoreCallingIdentity(identity);
6447 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006448 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006449
6450 /**
6451 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006452 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6453 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006454 * Require system privileges. In the future we may add this to carrier APIs.
6455 *
Michele Berionne482f8202018-11-27 18:57:59 -08006456 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006457 */
6458 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006459 @TelephonyManager.SetCarrierRestrictionResult
6460 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006461 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006462 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006463
Michele Berionne482f8202018-11-27 18:57:59 -08006464 if (carrierRestrictionRules == null) {
6465 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006466 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006468 final long identity = Binder.clearCallingIdentity();
6469 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006470 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006471 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 } finally {
6473 Binder.restoreCallingIdentity(identity);
6474 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006475 }
6476
6477 /**
6478 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006479 * Get the allowed carrier list and the excluded carrier list, including the priority between
6480 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006481 * Require system privileges. In the future we may add this to carrier APIs.
6482 *
Michele Berionne482f8202018-11-27 18:57:59 -08006483 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006484 */
6485 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006486 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006487 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006488 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489
6490 final long identity = Binder.clearCallingIdentity();
6491 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006492 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6493 if (response instanceof CarrierRestrictionRules) {
6494 return (CarrierRestrictionRules) response;
6495 }
6496 // Response is an Exception of some kind,
6497 // which is signalled to the user as a NULL retval
6498 return null;
6499 } catch (Exception e) {
6500 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6501 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006502 } finally {
6503 Binder.restoreCallingIdentity(identity);
6504 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006505 }
6506
fionaxu59545b42016-05-25 15:53:37 -07006507 /**
6508 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6509 * @param subId the subscription ID that this action applies to.
6510 * @param enabled control enable or disable metered apns.
6511 * {@hide}
6512 */
6513 @Override
6514 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6515 enforceModifyPermission();
6516 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006517
6518 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006519 if (phone == null) {
6520 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6521 return;
6522 }
6523 try {
6524 phone.carrierActionSetMeteredApnsEnabled(enabled);
6525 } catch (Exception e) {
6526 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006527 } finally {
6528 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006529 }
6530 }
6531
6532 /**
6533 * Action set from carrier signalling broadcast receivers to enable/disable radio
6534 * @param subId the subscription ID that this action applies to.
6535 * @param enabled control enable or disable radio.
6536 * {@hide}
6537 */
6538 @Override
6539 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6540 enforceModifyPermission();
6541 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542
6543 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006544 if (phone == null) {
6545 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6546 return;
6547 }
6548 try {
6549 phone.carrierActionSetRadioEnabled(enabled);
6550 } catch (Exception e) {
6551 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552 } finally {
6553 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006554 }
6555 }
6556
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006557 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006558 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6559 * network status based on which carrier apps could apply actions accordingly,
6560 * enable/disable default url handler for example.
6561 *
6562 * @param subId the subscription ID that this action applies to.
6563 * @param report control start/stop reporting the default network status.
6564 * {@hide}
6565 */
6566 @Override
6567 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6568 enforceModifyPermission();
6569 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570
6571 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006572 if (phone == null) {
6573 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6574 return;
6575 }
6576 try {
6577 phone.carrierActionReportDefaultNetworkStatus(report);
6578 } catch (Exception e) {
6579 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580 } finally {
6581 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006582 }
6583 }
6584
6585 /**
fionaxud9622282017-07-17 17:51:30 -07006586 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6587 * @param subId the subscription ID that this action applies to.
6588 * {@hide}
6589 */
6590 @Override
6591 public void carrierActionResetAll(int subId) {
6592 enforceModifyPermission();
6593 final Phone phone = getPhone(subId);
6594 if (phone == null) {
6595 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6596 return;
6597 }
6598 try {
6599 phone.carrierActionResetAll();
6600 } catch (Exception e) {
6601 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6602 }
6603 }
6604
6605 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006606 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6607 * bug report is being generated.
6608 */
6609 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006610 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006611 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6612 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006613 writer.println("Permission Denial: can't dump Phone from pid="
6614 + Binder.getCallingPid()
6615 + ", uid=" + Binder.getCallingUid()
6616 + "without permission "
6617 + android.Manifest.permission.DUMP);
6618 return;
6619 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006620 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006621 }
Jack Yueb89b242016-06-22 13:27:47 -07006622
Brad Ebingerdac2f002018-04-03 15:17:52 -07006623 @Override
6624 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6625 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6626 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006627 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6628 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006629 }
6630
Jack Yueb89b242016-06-22 13:27:47 -07006631 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006632 * Get aggregated video call data usage since boot.
6633 *
6634 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6635 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006636 * {@hide}
6637 */
6638 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006639 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006640 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6641 null);
6642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643 final long identity = Binder.clearCallingIdentity();
6644 try {
6645 // NetworkStatsService keeps tracking the active network interface and identity. It
6646 // records the delta with the corresponding network identity.
6647 // We just return the total video call data usage snapshot since boot.
6648 Phone phone = getPhone(subId);
6649 if (phone != null) {
6650 return phone.getVtDataUsage(perUidStats);
6651 }
6652 return null;
6653 } finally {
6654 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006655 }
Jack Yueb89b242016-06-22 13:27:47 -07006656 }
Jack Yu75ab2952016-07-08 14:29:33 -07006657
6658 /**
6659 * Policy control of data connection. Usually used when data limit is passed.
6660 * @param enabled True if enabling the data, otherwise disabling.
6661 * @param subId Subscription index
6662 * {@hide}
6663 */
6664 @Override
6665 public void setPolicyDataEnabled(boolean enabled, int subId) {
6666 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006667
6668 final long identity = Binder.clearCallingIdentity();
6669 try {
6670 Phone phone = getPhone(subId);
6671 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006672 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006673 }
6674 } finally {
6675 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006676 }
6677 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006678
6679 /**
6680 * Get Client request stats
6681 * @return List of Client Request Stats
6682 * @hide
6683 */
6684 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006685 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6686 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006687 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006688 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006689 return null;
6690 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006691 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693 final long identity = Binder.clearCallingIdentity();
6694 try {
6695 if (phone != null) {
6696 return phone.getClientRequestStats();
6697 }
6698
6699 return null;
6700 } finally {
6701 Binder.restoreCallingIdentity(identity);
6702 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006703 }
6704
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006705 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006706 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006707 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006708 }
Jack Yueb4124c2017-02-16 15:32:43 -08006709
6710 /**
Grace Chen70990072017-03-24 17:21:30 -07006711 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006712 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006713 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006714 * @param state State of SIM (power down, power up, pass through)
6715 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6716 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6717 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006718 *
6719 **/
6720 @Override
Grace Chen70990072017-03-24 17:21:30 -07006721 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006722 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006723 Phone phone = PhoneFactory.getPhone(slotIndex);
6724
vagdeviaf9a5b92018-08-15 16:01:53 -07006725 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006727 final long identity = Binder.clearCallingIdentity();
6728 try {
6729 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006730 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006731 }
6732 } finally {
6733 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006734 }
6735 }
Shuo Qiandd210312017-04-12 22:11:33 +00006736
Tyler Gunn65d45c22017-06-05 11:22:26 -07006737 private boolean isUssdApiAllowed(int subId) {
6738 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006739 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006740 if (configManager == null) {
6741 return false;
6742 }
6743 PersistableBundle pb = configManager.getConfigForSubId(subId);
6744 if (pb == null) {
6745 return false;
6746 }
6747 return pb.getBoolean(
6748 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6749 }
6750
Shuo Qiandd210312017-04-12 22:11:33 +00006751 /**
6752 * Check if phone is in emergency callback mode
6753 * @return true if phone is in emergency callback mode
6754 * @param subId sub id
6755 */
goneil9c5f4872017-12-05 14:07:56 -08006756 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006757 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006758 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006759 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760
6761 final long identity = Binder.clearCallingIdentity();
6762 try {
6763 if (phone != null) {
6764 return phone.isInEcm();
6765 } else {
6766 return false;
6767 }
6768 } finally {
6769 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006770 }
6771 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006772
6773 /**
6774 * Get the current signal strength information for the given subscription.
6775 * Because this information is not updated when the device is in a low power state
6776 * it should not be relied-upon to be current.
6777 * @param subId Subscription index
6778 * @return the most recent cached signal strength info from the modem
6779 */
6780 @Override
6781 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782 final long identity = Binder.clearCallingIdentity();
6783 try {
6784 Phone p = getPhone(subId);
6785 if (p == null) {
6786 return null;
6787 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006789 return p.getSignalStrength();
6790 } finally {
6791 Binder.restoreCallingIdentity(identity);
6792 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006793 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006794
Pengquan Meng77b7f132018-08-22 14:49:57 -07006795 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006796 * Get the current modem radio state for the given slot.
6797 * @param slotIndex slot index.
6798 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006799 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006800 * @return the current radio power state from the modem
6801 */
6802 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006803 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006804 Phone phone = PhoneFactory.getPhone(slotIndex);
6805 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006806 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6807 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006808 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6809 }
6810
6811 final long identity = Binder.clearCallingIdentity();
6812 try {
6813 return phone.getRadioPowerState();
6814 } finally {
6815 Binder.restoreCallingIdentity(identity);
6816 }
6817 }
6818 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6819 }
6820
6821 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006822 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6823 *
6824 * <p>Requires one of the following permissions:
6825 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6826 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6827 * privileges.
6828 *
6829 * @param subId subscription id
6830 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6831 * {@code false}.
6832 */
6833 @Override
6834 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006835 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6836 null /* message */);
6837
Pengquan Menga1bb6272018-09-06 09:59:22 -07006838 boolean isEnabled = false;
6839 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006840 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006841 Phone phone = getPhone(subId);
6842 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006843 } catch (Exception e) {
6844 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6845 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006846 } finally {
6847 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006848 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006849 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006850 }
6851
6852
6853 /**
6854 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6855 *
6856 * <p> Requires permission:
6857 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6858 * privileges.
6859 *
6860 * @param subId subscription id
6861 * @param isEnabled {@code true} means enable, {@code false} means disable.
6862 */
6863 @Override
6864 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6866 mApp, subId, "setDataRoamingEnabled");
6867
Pengquan Menga1bb6272018-09-06 09:59:22 -07006868 final long identity = Binder.clearCallingIdentity();
6869 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006870 Phone phone = getPhone(subId);
6871 if (phone != null) {
6872 phone.setDataRoamingEnabled(isEnabled);
6873 }
6874 } finally {
6875 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006876 }
6877 }
6878
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006879 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006880 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006881 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6882 mApp, subId, "isManualNetworkSelectionAllowed");
6883
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006884 boolean isAllowed = true;
6885 final long identity = Binder.clearCallingIdentity();
6886 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006887 Phone phone = getPhone(subId);
6888 if (phone != null) {
6889 isAllowed = phone.isCspPlmnEnabled();
6890 }
6891 } finally {
6892 Binder.restoreCallingIdentity(identity);
6893 }
6894 return isAllowed;
6895 }
6896
6897 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006898 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006899 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006900 try {
6901 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006902 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006903 } catch (SecurityException e) {
6904 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6905 // has carrier privileges on an active UICC
6906 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6907 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006908 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006909 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006910 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006911
6912 final long identity = Binder.clearCallingIdentity();
6913 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006914 UiccController uiccController = UiccController.getInstance();
6915 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006916 if (hasReadPermission) {
6917 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006918 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006919
6920 // Remove private info if the caller doesn't have access
6921 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6922 for (UiccCardInfo cardInfo : cardInfos) {
6923 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6924 // is available
6925 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6926 if (card == null || card.getUiccProfile() == null) {
6927 // assume no access if the card or profile is unavailable
6928 filteredInfos.add(cardInfo.getUnprivileged());
6929 continue;
6930 }
6931 UiccProfile profile = card.getUiccProfile();
6932 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6933 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6934 filteredInfos.add(cardInfo);
6935 } else {
6936 filteredInfos.add(cardInfo.getUnprivileged());
6937 }
6938 }
6939 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006940 } finally {
6941 Binder.restoreCallingIdentity(identity);
6942 }
6943 }
6944
6945 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006946 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006947 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006949 final long identity = Binder.clearCallingIdentity();
6950 try {
6951 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6952 if (slots == null) {
6953 Rlog.i(LOG_TAG, "slots is null.");
6954 return null;
6955 }
6956
6957 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6958 for (int i = 0; i < slots.length; i++) {
6959 UiccSlot slot = slots[i];
6960 if (slot == null) {
6961 continue;
6962 }
6963
Jordan Liu7be7e652019-05-06 18:55:02 +00006964 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965 UiccCard card = slot.getUiccCard();
6966 if (card != null) {
6967 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006968 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006969 cardId = slot.getEid();
6970 if (TextUtils.isEmpty(cardId)) {
6971 cardId = slot.getIccId();
6972 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006973 }
6974
Jordan Liu857451f2019-05-09 16:35:35 -07006975 if (cardId != null) {
6976 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6977 // if cardId is an EID, it's all digits so this is fine
6978 cardId = IccUtils.stripTrailingFs(cardId);
6979 }
6980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006981 int cardState = 0;
6982 switch (slot.getCardState()) {
6983 case CARDSTATE_ABSENT:
6984 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6985 break;
6986 case CARDSTATE_PRESENT:
6987 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6988 break;
6989 case CARDSTATE_ERROR:
6990 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6991 break;
6992 case CARDSTATE_RESTRICTED:
6993 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6994 break;
6995 default:
6996 break;
6997
6998 }
6999
7000 infos[i] = new UiccSlotInfo(
7001 slot.isActive(),
7002 slot.isEuicc(),
7003 cardId,
7004 cardState,
7005 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007006 slot.isExtendedApduSupported(),
7007 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 }
7009 return infos;
7010 } finally {
7011 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007012 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007013 }
7014
7015 @Override
7016 public boolean switchSlots(int[] physicalSlots) {
7017 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018
7019 final long identity = Binder.clearCallingIdentity();
7020 try {
7021 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7022 } finally {
7023 Binder.restoreCallingIdentity(identity);
7024 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007025 }
Jack Yu4c988042018-02-27 15:30:01 -08007026
7027 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007028 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007029 final long identity = Binder.clearCallingIdentity();
7030 try {
7031 return UiccController.getInstance().getCardIdForDefaultEuicc();
7032 } finally {
7033 Binder.restoreCallingIdentity(identity);
7034 }
7035 }
7036
7037 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007038 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7039 enforceModifyPermission();
7040 final Phone phone = getPhone(subId);
7041 if (phone == null) {
7042 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7043 return;
7044 }
7045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046 final long identity = Binder.clearCallingIdentity();
7047 try {
7048 phone.setRadioIndicationUpdateMode(filters, mode);
7049 } finally {
7050 Binder.restoreCallingIdentity(identity);
7051 }
Jack Yu4c988042018-02-27 15:30:01 -08007052 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007053
7054 /**
goneil47ffb6e2018-04-06 15:40:58 -07007055 * A test API to reload the UICC profile.
7056 *
7057 * <p>Requires that the calling app has permission
7058 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7059 * @hide
7060 */
7061 @Override
7062 public void refreshUiccProfile(int subId) {
7063 enforceModifyPermission();
7064
7065 final long identity = Binder.clearCallingIdentity();
7066 try {
7067 Phone phone = getPhone(subId);
7068 if (phone == null) {
7069 return;
7070 }
7071 UiccCard uiccCard = phone.getUiccCard();
7072 if (uiccCard == null) {
7073 return;
7074 }
7075 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7076 if (uiccProfile == null) {
7077 return;
7078 }
7079 uiccProfile.refresh();
7080 } finally {
7081 Binder.restoreCallingIdentity(identity);
7082 }
7083 }
7084
7085 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007086 * Returns false if the mobile data is disabled by default, otherwise return true.
7087 */
7088 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007089 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007090 }
7091
7092 /**
7093 * Returns true if the data roaming is enabled by default, i.e the system property
7094 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7095 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7096 */
7097 private boolean getDefaultDataRoamingEnabled(int subId) {
7098 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007099 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007100 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007101 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7102 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7103 return isDataRoamingEnabled;
7104 }
7105
7106 /**
7107 * Returns the default network type for the given {@code subId}, if the default network type is
7108 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7109 */
7110 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007111 List<Integer> list = TelephonyProperties.default_network();
7112 int phoneId = mSubscriptionController.getPhoneId(subId);
7113 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7114 return list.get(phoneId);
7115 }
7116 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007117 }
fionaxua13278b2018-03-21 00:08:13 -07007118
7119 @Override
7120 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007121 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007122 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007123
7124 final long identity = Binder.clearCallingIdentity();
7125 try {
7126 final Phone phone = getPhone(subId);
7127 if (phone == null) {
7128 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7129 return;
7130 }
chen xueaba88a2019-03-15 13:15:10 -07007131 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7132 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133 } finally {
7134 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007135 }
fionaxua13278b2018-03-21 00:08:13 -07007136 }
7137
7138 @Override
7139 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007140 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141
7142 final long identity = Binder.clearCallingIdentity();
7143 try {
7144 final Phone phone = getPhone(subId);
7145 if (phone == null) {
7146 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7147 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7148 }
7149 return phone.getCarrierIdListVersion();
7150 } finally {
7151 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007152 }
fionaxua13278b2018-03-21 00:08:13 -07007153 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007154
7155 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007156 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7157 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007159 mApp, subId, callingPackage, callingFeatureId,
7160 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007161 return -1;
7162 }
7163
7164 final long identity = Binder.clearCallingIdentity();
7165 try {
7166 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7167 } finally {
7168 Binder.restoreCallingIdentity(identity);
7169 }
7170 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007171
7172 @Override
7173 public int getCdmaRoamingMode(int subId) {
7174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7175 mApp, subId, "getCdmaRoamingMode");
7176
7177 final long identity = Binder.clearCallingIdentity();
7178 try {
7179 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
7182 }
7183 }
7184
7185 @Override
7186 public boolean setCdmaRoamingMode(int subId, int mode) {
7187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7188 mApp, subId, "setCdmaRoamingMode");
7189
7190 final long identity = Binder.clearCallingIdentity();
7191 try {
7192 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7193 } finally {
7194 Binder.restoreCallingIdentity(identity);
7195 }
7196 }
7197
7198 @Override
7199 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7201 mApp, subId, "setCdmaSubscriptionMode");
7202
7203 final long identity = Binder.clearCallingIdentity();
7204 try {
7205 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7206 } finally {
7207 Binder.restoreCallingIdentity(identity);
7208 }
7209 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007210
sqianc5eccab2018-10-19 18:46:41 -07007211 @Override
sqian8c685422019-02-22 15:55:18 -08007212 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007213 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007215 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7216 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007217 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7218 }
7219 final long identity = Binder.clearCallingIdentity();
7220 try {
sqian854d44b2018-12-12 16:48:18 -08007221 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7222 for (Phone phone: PhoneFactory.getPhones()) {
7223 if (phone.getEmergencyNumberTracker() != null
7224 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7225 emergencyNumberListInternal.put(
7226 phone.getSubId(),
7227 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7228 }
sqian11b7a0e2018-12-05 18:48:28 -08007229 }
sqian854d44b2018-12-12 16:48:18 -08007230 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007231 } finally {
7232 Binder.restoreCallingIdentity(identity);
7233 }
sqianc5eccab2018-10-19 18:46:41 -07007234 }
7235
7236 @Override
sqian8c685422019-02-22 15:55:18 -08007237 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007238 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007239 if (!exactMatch) {
7240 TelephonyPermissions
7241 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007242 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007243 }
7244 final long identity = Binder.clearCallingIdentity();
7245 try {
sqian854d44b2018-12-12 16:48:18 -08007246 for (Phone phone: PhoneFactory.getPhones()) {
7247 if (phone.getEmergencyNumberTracker() != null
7248 && phone.getEmergencyNumberTracker() != null) {
7249 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7250 number, exactMatch)) {
7251 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007252 }
7253 }
sqian11b7a0e2018-12-05 18:48:28 -08007254 }
7255 return false;
7256 } finally {
7257 Binder.restoreCallingIdentity(identity);
7258 }
7259 }
7260
sqianf4ca7ed2019-01-15 18:32:07 -08007261 /**
7262 * Update emergency number list for test mode.
7263 */
7264 @Override
7265 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7266 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7267 "updateEmergencyNumberListTestMode");
7268
7269 final long identity = Binder.clearCallingIdentity();
7270 try {
7271 for (Phone phone: PhoneFactory.getPhones()) {
7272 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7273 if (tracker != null) {
7274 tracker.executeEmergencyNumberTestModeCommand(action, num);
7275 }
7276 }
7277 } finally {
7278 Binder.restoreCallingIdentity(identity);
7279 }
7280 }
7281
7282 /**
7283 * Get the full emergency number list for test mode.
7284 */
7285 @Override
7286 public List<String> getEmergencyNumberListTestMode() {
7287 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7288 "getEmergencyNumberListTestMode");
7289
7290 final long identity = Binder.clearCallingIdentity();
7291 try {
7292 Set<String> emergencyNumbers = new HashSet<>();
7293 for (Phone phone: PhoneFactory.getPhones()) {
7294 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7295 if (tracker != null) {
7296 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7297 emergencyNumbers.add(num.getNumber());
7298 }
7299 }
7300 }
7301 return new ArrayList<>(emergencyNumbers);
7302 } finally {
7303 Binder.restoreCallingIdentity(identity);
7304 }
7305 }
7306
chen xud6b45bd2018-10-30 22:27:10 -07007307 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007308 public int getEmergencyNumberDbVersion(int subId) {
7309 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7310
7311 final long identity = Binder.clearCallingIdentity();
7312 try {
7313 final Phone phone = getPhone(subId);
7314 if (phone == null) {
7315 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7316 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7317 }
7318 return phone.getEmergencyNumberDbVersion();
7319 } finally {
7320 Binder.restoreCallingIdentity(identity);
7321 }
7322 }
7323
7324 @Override
7325 public void notifyOtaEmergencyNumberDbInstalled() {
7326 enforceModifyPermission();
7327
7328 final long identity = Binder.clearCallingIdentity();
7329 try {
7330 for (Phone phone: PhoneFactory.getPhones()) {
7331 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7332 if (tracker != null) {
7333 tracker.updateOtaEmergencyNumberDatabase();
7334 }
7335 }
7336 } finally {
7337 Binder.restoreCallingIdentity(identity);
7338 }
7339 }
7340
7341 @Override
7342 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7343 enforceActiveEmergencySessionPermission();
7344
7345 final long identity = Binder.clearCallingIdentity();
7346 try {
7347 for (Phone phone: PhoneFactory.getPhones()) {
7348 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7349 if (tracker != null) {
7350 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7351 }
7352 }
7353 } finally {
7354 Binder.restoreCallingIdentity(identity);
7355 }
7356 }
7357
7358 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007359 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7360 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7361 Phone phone = getPhone(subId);
7362 if (phone == null) {
7363 return null;
7364 }
7365 final long identity = Binder.clearCallingIdentity();
7366 try {
7367 UiccProfile profile = UiccController.getInstance()
7368 .getUiccProfileForPhone(phone.getPhoneId());
7369 if (profile != null) {
7370 return profile.getCertsFromCarrierPrivilegeAccessRules();
7371 }
7372 } finally {
7373 Binder.restoreCallingIdentity(identity);
7374 }
7375 return null;
7376 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007377
7378 /**
7379 * Enable or disable a modem stack.
7380 */
7381 @Override
7382 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7383 enforceModifyPermission();
7384
7385 final long identity = Binder.clearCallingIdentity();
7386 try {
7387 Phone phone = PhoneFactory.getPhone(slotIndex);
7388 if (phone == null) {
7389 return false;
7390 } else {
7391 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7392 }
7393 } finally {
7394 Binder.restoreCallingIdentity(identity);
7395 }
7396 }
Michelecea4cf22018-12-21 15:00:11 -08007397
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007398 /**
7399 * Whether a modem stack is enabled or not.
7400 */
7401 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007402 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7403 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007404 Phone phone = PhoneFactory.getPhone(slotIndex);
7405 if (phone == null) return false;
7406
7407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007408 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7409 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007410 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7411 }
7412
7413 final long identity = Binder.clearCallingIdentity();
7414 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007415 try {
7416 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7417 } catch (NoSuchElementException ex) {
7418 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7419 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007420 } finally {
7421 Binder.restoreCallingIdentity(identity);
7422 }
7423 }
7424
Michelecea4cf22018-12-21 15:00:11 -08007425 @Override
Michele0ea7d782019-03-19 14:58:42 -07007426 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007427 enforceModifyPermission();
7428
7429 final long identity = Binder.clearCallingIdentity();
7430 try {
7431 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007432 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007433 .commit();
7434 } finally {
7435 Binder.restoreCallingIdentity(identity);
7436 }
7437 }
7438
7439 @Override
Michele0ea7d782019-03-19 14:58:42 -07007440 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007441 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007443 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7444 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007445 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007446 }
Michelecea4cf22018-12-21 15:00:11 -08007447
7448 final long identity = Binder.clearCallingIdentity();
7449 try {
Michele0ea7d782019-03-19 14:58:42 -07007450 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007451 } finally {
7452 Binder.restoreCallingIdentity(identity);
7453 }
7454 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007455
Michele0ea7d782019-03-19 14:58:42 -07007456 @TelephonyManager.IsMultiSimSupportedResult
7457 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007458 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7459 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7460 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007461 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7462 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007463 }
7464 // Check if the hardware supports multisim functionality. If usage of multisim is not
7465 // supported by the modem, indicate that it is restricted.
7466 PhoneCapability staticCapability =
7467 mPhoneConfigurationManager.getStaticPhoneCapability();
7468 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007469 loge("isMultiSimSupportedInternal: no static configuration available");
7470 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007471 }
Sarah Chin0605abf2019-12-06 10:24:18 -08007472 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007473 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7474 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007475 }
7476 // Check if support of multiple SIMs is restricted by carrier
7477 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007478 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007479 }
7480
Michele0ea7d782019-03-19 14:58:42 -07007481 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007482 }
7483
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007484 /**
7485 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007486 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7487 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7488 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007489 * @param numOfSims number of active sims we want to switch to
7490 */
7491 @Override
7492 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007493 if (numOfSims == 1) {
7494 enforceModifyPermission();
7495 } else {
7496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7497 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7498 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007499 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007500
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007501 try {
Michele30b57b22019-03-01 12:01:14 -08007502 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007503 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007504 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7505 return;
7506 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007507 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7508 } finally {
7509 Binder.restoreCallingIdentity(identity);
7510 }
7511 }
7512
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007513 @Override
7514 public boolean isApplicationOnUicc(int subId, int appType) {
7515 enforceReadPrivilegedPermission("isApplicationOnUicc");
7516 Phone phone = getPhone(subId);
7517 if (phone == null) {
7518 return false;
7519 }
7520 final long identity = Binder.clearCallingIdentity();
7521 try {
7522 UiccCard uiccCard = phone.getUiccCard();
7523 if (uiccCard == null) {
7524 return false;
7525 }
7526 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7527 if (uiccProfile == null) {
7528 return false;
7529 }
7530 if (TelephonyManager.APPTYPE_SIM <= appType
7531 && appType <= TelephonyManager.APPTYPE_ISIM) {
7532 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7533 }
7534 return false;
7535 } finally {
7536 Binder.restoreCallingIdentity(identity);
7537 }
7538 }
7539
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007540 /**
chen xub4baa772019-04-03 10:23:41 -07007541 * Get whether making changes to modem configurations will trigger reboot.
7542 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007543 */
7544 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007545 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7546 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007548 mApp, subId, callingPackage, callingFeatureId,
7549 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007550 return false;
7551 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007552 final long identity = Binder.clearCallingIdentity();
7553 try {
7554 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7555 } finally {
7556 Binder.restoreCallingIdentity(identity);
7557 }
7558 }
7559
Nathan Harold29f5f052019-02-15 13:41:57 -08007560 private void updateModemStateMetrics() {
7561 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7562 // TODO: check the state for each modem if the api is ready.
7563 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7564 }
7565
Pengquan Meng3889a572019-01-23 11:16:29 -08007566 @Override
7567 public int[] getSlotsMapping() {
7568 enforceReadPrivilegedPermission("getSlotsMapping");
7569
7570 final long identity = Binder.clearCallingIdentity();
7571 try {
7572 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7573 // All logical slots should have a mapping to a physical slot.
7574 int[] logicalSlotsMapping = new int[phoneCount];
7575 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7576 for (int i = 0; i < slotInfos.length; i++) {
7577 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7578 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7579 }
7580 }
7581 return logicalSlotsMapping;
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
7584 }
7585 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007586
7587 /**
7588 * Get the IRadio HAL Version
7589 */
7590 @Override
7591 public int getRadioHalVersion() {
7592 Phone phone = getDefaultPhone();
7593 if (phone == null) return -1;
7594 HalVersion hv = phone.getHalVersion();
7595 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7596 return hv.major * 100 + hv.minor;
7597 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007598
7599 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007600 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7601 * corresponding network requests on a subId.
7602 *
7603 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007604 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007605 * 2) APN is un-metered for this subscription, or
7606 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7607 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7608 *
7609 * @return whether data is allowed for a apn type.
7610 *
7611 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007612 */
7613 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007614 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007615 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7616 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007617
7618 // Now that all security checks passes, perform the operation as ourselves.
7619 final long identity = Binder.clearCallingIdentity();
7620 try {
7621 Phone phone = getPhone(subId);
7622 if (phone == null) return false;
7623
Jack Yu41407ee2019-05-13 16:54:09 -07007624 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007625 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7626 } finally {
7627 Binder.restoreCallingIdentity(identity);
7628 }
7629 }
7630
7631 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007632 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007633 enforceReadPrivilegedPermission("isApnMetered");
7634
7635 // Now that all security checks passes, perform the operation as ourselves.
7636 final long identity = Binder.clearCallingIdentity();
7637 try {
7638 Phone phone = getPhone(subId);
7639 if (phone == null) return true; // By default return true.
7640
Jack Yu41407ee2019-05-13 16:54:09 -07007641 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007642 } finally {
7643 Binder.restoreCallingIdentity(identity);
7644 }
7645 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007646
7647 @Override
7648 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7649 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7650 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7651 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7652 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7653 }
7654 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7655 Intent intent = new Intent();
7656 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7657 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7658 // Bring up choose default SMS subscription dialog right now
7659 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7660 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7661 mApp.startActivity(intent);
7662 }
chen xud5ca2d52019-05-28 15:20:57 -07007663
7664 @Override
7665 public String getMmsUAProfUrl(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_profile_url);
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
7673 }
7674 }
7675
7676 @Override
7677 public String getMmsUserAgent(int subId) {
7678 //TODO investigate if this API should require proper permission check in R b/133791609
7679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7682 .getString(com.android.internal.R.string.config_mms_user_agent);
7683 } finally {
7684 Binder.restoreCallingIdentity(identity);
7685 }
7686 }
Jack Yub07d4972019-05-28 16:12:25 -07007687
7688 @Override
7689 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7690 enforceModifyPermission();
7691
7692 // Now that all security checks passes, perform the operation as ourselves.
7693 final long identity = Binder.clearCallingIdentity();
7694 try {
7695 Phone phone = getPhone(subId);
7696 if (phone == null) return false;
7697
7698 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7699 } finally {
7700 Binder.restoreCallingIdentity(identity);
7701 }
7702 }
7703
7704 @Override
7705 public boolean isDataAllowedInVoiceCall(int subId) {
7706 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7707
7708 // Now that all security checks passes, perform the operation as ourselves.
7709 final long identity = Binder.clearCallingIdentity();
7710 try {
7711 Phone phone = getPhone(subId);
7712 if (phone == null) return false;
7713
7714 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7715 } finally {
7716 Binder.restoreCallingIdentity(identity);
7717 }
7718 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007719
7720 /**
7721 * Updates whether conference event pacakge handling is enabled.
7722 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7723 * otherwise.
7724 */
7725 @Override
7726 public void setCepEnabled(boolean isCepEnabled) {
7727 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7728
7729 final long identity = Binder.clearCallingIdentity();
7730 try {
7731 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7732 for (Phone phone : PhoneFactory.getPhones()) {
7733 Phone defaultPhone = phone.getImsPhone();
7734 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7735 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7736 ImsPhoneCallTracker imsPhoneCallTracker =
7737 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7738 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7739 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7740 + imsPhone.getMsisdn());
7741 }
7742 }
7743 } finally {
7744 Binder.restoreCallingIdentity(identity);
7745 }
7746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007747}