blob: b9831de10f088fb33dde957c6cd6b65fe57567bb [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 }
Naina Nallurid63128d2019-09-17 14:10:30 -07001222 case CMD_ERASE_MODEM_CONFIG:
1223 request = (MainThreadRequest) msg.obj;
1224 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1225 defaultPhone.eraseModemConfig(onCompleted);
1226 break;
1227 case EVENT_ERASE_MODEM_CONFIG_DONE:
1228 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001229 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001230 default:
1231 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1232 break;
1233 }
1234 }
Jake Hambye994d462014-02-03 13:10:13 -08001235
Pengquan Menga1bb6272018-09-06 09:59:22 -07001236 private void notifyRequester(MainThreadRequest request) {
1237 synchronized (request) {
1238 request.notifyAll();
1239 }
1240 }
1241
Jake Hambye994d462014-02-03 13:10:13 -08001242 private void handleNullReturnEvent(Message msg, String command) {
1243 AsyncResult ar = (AsyncResult) msg.obj;
1244 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1245 if (ar.exception == null) {
1246 request.result = true;
1247 } else {
1248 request.result = false;
1249 if (ar.exception instanceof CommandException) {
1250 loge(command + ": CommandException: " + ar.exception);
1251 } else {
1252 loge(command + ": Unknown exception");
1253 }
1254 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001255 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001257 }
1258
1259 /**
1260 * Posts the specified command to be executed on the main thread,
1261 * waits for the request to complete, and returns the result.
1262 * @see #sendRequestAsync
1263 */
1264 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001265 return sendRequest(
1266 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001267 }
1268
1269 /**
1270 * Posts the specified command to be executed on the main thread,
1271 * waits for the request to complete, and returns the result.
1272 * @see #sendRequestAsync
1273 */
1274 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1275 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001276 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001277 }
1278
1279 /**
1280 * Posts the specified command to be executed on the main thread,
1281 * waits for the request to complete, and returns the result.
1282 * @see #sendRequestAsync
1283 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001284 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001285 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001286 }
1287
1288 /**
1289 * Posts the specified command to be executed on the main thread,
1290 * waits for the request to complete, and returns the result.
1291 * @see #sendRequestAsync
1292 */
Nathan Harold92bed182018-10-12 18:16:49 -07001293 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1294 return sendRequest(command, argument, subId, null, workSource);
1295 }
1296
1297 /**
1298 * Posts the specified command to be executed on the main thread,
1299 * waits for the request to complete, and returns the result.
1300 * @see #sendRequestAsync
1301 */
1302 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1303 return sendRequest(
1304 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1305 }
1306
1307 /**
1308 * Posts the specified command to be executed on the main thread,
1309 * waits for the request to complete, and returns the result.
1310 * @see #sendRequestAsync
1311 */
1312 private Object sendRequest(
1313 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1315 throw new RuntimeException("This method will deadlock if called from the main thread.");
1316 }
1317
Nathan Harold92bed182018-10-12 18:16:49 -07001318 MainThreadRequest request = null;
1319 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1320 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1321 } else if (phone != null) {
1322 request = new MainThreadRequest(argument, phone, workSource);
1323 } else {
1324 request = new MainThreadRequest(argument, subId, workSource);
1325 }
1326
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327 Message msg = mMainThreadHandler.obtainMessage(command, request);
1328 msg.sendToTarget();
1329
1330 // Wait for the request to complete
1331 synchronized (request) {
1332 while (request.result == null) {
1333 try {
1334 request.wait();
1335 } catch (InterruptedException e) {
1336 // Do nothing, go back and wait until the request is complete
1337 }
1338 }
1339 }
1340 return request.result;
1341 }
1342
1343 /**
1344 * Asynchronous ("fire and forget") version of sendRequest():
1345 * Posts the specified command to be executed on the main thread, and
1346 * returns immediately.
1347 * @see #sendRequest
1348 */
1349 private void sendRequestAsync(int command) {
1350 mMainThreadHandler.sendEmptyMessage(command);
1351 }
1352
1353 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001354 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001355 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001356 */
1357 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001358 sendRequestAsync(command, argument, null, null);
1359 }
1360
1361 /**
1362 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1363 * @see {@link #sendRequest(int,Object)}
1364 */
1365 private void sendRequestAsync(
1366 int command, Object argument, Phone phone, WorkSource workSource) {
1367 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001368 Message msg = mMainThreadHandler.obtainMessage(command, request);
1369 msg.sendToTarget();
1370 }
1371
1372 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001373 * Initialize the singleton PhoneInterfaceManager instance.
1374 * This is only done once, at startup, from PhoneApp.onCreate().
1375 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001376 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 synchronized (PhoneInterfaceManager.class) {
1378 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001379 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380 } else {
1381 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1382 }
1383 return sInstance;
1384 }
1385 }
1386
1387 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001388 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001389 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001390 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001391 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1393 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001394 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001395 mTelephonySharedPreferences =
1396 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001397 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001398 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001399
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 publish();
1401 }
1402
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001403 private Phone getDefaultPhone() {
1404 Phone thePhone = getPhone(getDefaultSubscription());
1405 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1406 }
1407
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001408 private void publish() {
1409 if (DBG) log("publish: " + this);
1410
1411 ServiceManager.addService("phone", this);
1412 }
1413
Stuart Scott584921c2015-01-15 17:10:34 -08001414 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001415 if (request.phone != null) {
1416 return request.phone;
1417 } else {
1418 return getPhoneFromSubId(request.subId);
1419 }
1420 }
1421
1422 private Phone getPhoneFromSubId(int subId) {
1423 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1424 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001425 }
1426
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001427 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1428 Phone phone = getPhoneFromRequest(request);
1429 return phone == null ? null :
1430 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1431 }
1432
Wink Saville36469e72014-06-11 15:17:00 -07001433 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001434 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001435 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001436 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001437
Naina Nallurid63128d2019-09-17 14:10:30 -07001438 private void sendEraseModemConfig(Phone phone) {
1439 if (phone != null) {
1440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1441 mApp, phone.getSubId(), "eraseModemConfig");
1442 final long identity = Binder.clearCallingIdentity();
1443 try {
1444 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1445 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1446 } finally {
1447 Binder.restoreCallingIdentity(identity);
1448 }
1449 }
1450 }
1451
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001452 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001453 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001454 }
1455
Wink Savilleb564aae2014-10-23 10:18:09 -07001456 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001457 if (DBG) log("dial: " + number);
1458 // No permission check needed here: This is just a wrapper around the
1459 // ACTION_DIAL intent, which is available to any app since it puts up
1460 // the UI before it does anything.
1461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001462 final long identity = Binder.clearCallingIdentity();
1463 try {
1464 String url = createTelUrl(number);
1465 if (url == null) {
1466 return;
1467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001469 // PENDING: should we just silently fail if phone is offhook or ringing?
1470 PhoneConstants.State state = mCM.getState(subId);
1471 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1472 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1473 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1474 mApp.startActivity(intent);
1475 }
1476 } finally {
1477 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478 }
1479 }
1480
1481 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001482 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001483 }
1484
Wink Savilleb564aae2014-10-23 10:18:09 -07001485 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486 if (DBG) log("call: " + number);
1487
1488 // This is just a wrapper around the ACTION_CALL intent, but we still
1489 // need to do a permission check since we're calling startActivity()
1490 // from the context of the phone app.
1491 enforceCallPermission();
1492
Jordan Liu1617b712019-07-10 15:06:26 -07001493 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001494 != AppOpsManager.MODE_ALLOWED) {
1495 return;
1496 }
1497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001498 final long identity = Binder.clearCallingIdentity();
1499 try {
1500 String url = createTelUrl(number);
1501 if (url == null) {
1502 return;
1503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001505 boolean isValid = false;
1506 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1507 if (slist != null) {
1508 for (SubscriptionInfo subInfoRecord : slist) {
1509 if (subInfoRecord.getSubscriptionId() == subId) {
1510 isValid = true;
1511 break;
1512 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001513 }
Wink Saville08874612014-08-31 19:19:58 -07001514 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001515 if (!isValid) {
1516 return;
1517 }
Wink Saville08874612014-08-31 19:19:58 -07001518
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001519 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1520 intent.putExtra(SUBSCRIPTION_KEY, subId);
1521 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1522 mApp.startActivity(intent);
1523 } finally {
1524 Binder.restoreCallingIdentity(identity);
1525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 }
1527
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001529 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001530 }
1531
Wink Savilleb564aae2014-10-23 10:18:09 -07001532 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001533 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001534 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1535 }
1536
1537 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001538 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001539 }
1540
Wink Savilleb564aae2014-10-23 10:18:09 -07001541 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001542 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001543 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1544 }
1545
1546 /** {@hide} */
1547 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001548 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001549 }
1550
Wink Savilleb564aae2014-10-23 10:18:09 -07001551 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001552 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001553
1554 final long identity = Binder.clearCallingIdentity();
1555 try {
1556 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1557 checkSimPin.start();
1558 return checkSimPin.unlockSim(null, pin);
1559 } finally {
1560 Binder.restoreCallingIdentity(identity);
1561 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001562 }
1563
Wink Saville9de0f752013-10-22 19:04:03 -07001564 /** {@hide} */
1565 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001566 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001567 }
1568
Wink Savilleb564aae2014-10-23 10:18:09 -07001569 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001571
1572 final long identity = Binder.clearCallingIdentity();
1573 try {
1574 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1575 checkSimPuk.start();
1576 return checkSimPuk.unlockSim(puk, pin);
1577 } finally {
1578 Binder.restoreCallingIdentity(identity);
1579 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 }
1581
1582 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001583 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001584 * a synchronous one.
1585 */
1586 private static class UnlockSim extends Thread {
1587
1588 private final IccCard mSimCard;
1589
1590 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001591 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1592 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593
1594 // For replies from SimCard interface
1595 private Handler mHandler;
1596
1597 // For async handler to identify request type
1598 private static final int SUPPLY_PIN_COMPLETE = 100;
1599
1600 public UnlockSim(IccCard simCard) {
1601 mSimCard = simCard;
1602 }
1603
1604 @Override
1605 public void run() {
1606 Looper.prepare();
1607 synchronized (UnlockSim.this) {
1608 mHandler = new Handler() {
1609 @Override
1610 public void handleMessage(Message msg) {
1611 AsyncResult ar = (AsyncResult) msg.obj;
1612 switch (msg.what) {
1613 case SUPPLY_PIN_COMPLETE:
1614 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1615 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001616 mRetryCount = msg.arg1;
1617 if (ar.exception != null) {
1618 if (ar.exception instanceof CommandException &&
1619 ((CommandException)(ar.exception)).getCommandError()
1620 == CommandException.Error.PASSWORD_INCORRECT) {
1621 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1622 } else {
1623 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1624 }
1625 } else {
1626 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001628 mDone = true;
1629 UnlockSim.this.notifyAll();
1630 }
1631 break;
1632 }
1633 }
1634 };
1635 UnlockSim.this.notifyAll();
1636 }
1637 Looper.loop();
1638 }
1639
1640 /*
1641 * Use PIN or PUK to unlock SIM card
1642 *
1643 * If PUK is null, unlock SIM card with PIN
1644 *
1645 * If PUK is not null, unlock SIM card with PUK and set PIN code
1646 */
Wink Saville9de0f752013-10-22 19:04:03 -07001647 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648
1649 while (mHandler == null) {
1650 try {
1651 wait();
1652 } catch (InterruptedException e) {
1653 Thread.currentThread().interrupt();
1654 }
1655 }
1656 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1657
1658 if (puk == null) {
1659 mSimCard.supplyPin(pin, callback);
1660 } else {
1661 mSimCard.supplyPuk(puk, pin, callback);
1662 }
1663
1664 while (!mDone) {
1665 try {
1666 Log.d(LOG_TAG, "wait for done");
1667 wait();
1668 } catch (InterruptedException e) {
1669 // Restore the interrupted status
1670 Thread.currentThread().interrupt();
1671 }
1672 }
1673 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001674 int[] resultArray = new int[2];
1675 resultArray[0] = mResult;
1676 resultArray[1] = mRetryCount;
1677 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 }
1679 }
1680
1681 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001682 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001683
1684 }
1685
Wink Savilleb564aae2014-10-23 10:18:09 -07001686 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 // No permission check needed here: this call is harmless, and it's
1688 // needed for the ServiceState.requestStateUpdate() call (which is
1689 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001690 final long identity = Binder.clearCallingIdentity();
1691 try {
1692 final Phone phone = getPhone(subId);
1693 if (phone != null) {
1694 phone.updateServiceLocation();
1695 }
1696 } finally {
1697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 }
1700
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001701 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001702 @Override
1703 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001704 return isRadioOnWithFeature(callingPackage, null);
1705 }
1706
1707
1708 @Override
1709 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1710 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1711 callingFeatureId);
1712 }
1713
1714 @Deprecated
1715 @Override
1716 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1717 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001718 }
1719
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001720 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001721 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1722 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001724 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001725 return false;
1726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001727
1728 final long identity = Binder.clearCallingIdentity();
1729 try {
1730 return isRadioOnForSubscriber(subId);
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
1733 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001734 }
1735
1736 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001737 final long identity = Binder.clearCallingIdentity();
1738 try {
1739 final Phone phone = getPhone(subId);
1740 if (phone != null) {
1741 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1742 } else {
1743 return false;
1744 }
1745 } finally {
1746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 }
1749
1750 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001751 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 }
Wink Saville36469e72014-06-11 15:17:00 -07001753
Wink Savilleb564aae2014-10-23 10:18:09 -07001754 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001756
1757 final long identity = Binder.clearCallingIdentity();
1758 try {
1759 final Phone phone = getPhone(subId);
1760 if (phone != null) {
1761 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1762 }
1763 } finally {
1764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001765 }
Wink Saville36469e72014-06-11 15:17:00 -07001766 }
1767
1768 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001769 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001770 }
1771
Wink Savilleb564aae2014-10-23 10:18:09 -07001772 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001773 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001774
1775 final long identity = Binder.clearCallingIdentity();
1776 try {
1777 final Phone phone = getPhone(subId);
1778 if (phone == null) {
1779 return false;
1780 }
1781 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1782 toggleRadioOnOffForSubscriber(subId);
1783 }
1784 return true;
1785 } finally {
1786 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
Wink Saville36469e72014-06-11 15:17:00 -07001789
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001790 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001791 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001792 /*
1793 * If any of the Radios are available, it will need to be
1794 * shutdown. So return true if any Radio is available.
1795 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001796 final long identity = Binder.clearCallingIdentity();
1797 try {
1798 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1799 Phone phone = PhoneFactory.getPhone(i);
1800 if (phone != null && phone.isRadioAvailable()) return true;
1801 }
1802 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1803 return false;
1804 } finally {
1805 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001806 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001807 }
1808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001809 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001810 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001811 enforceModifyPermission();
1812
1813 final long identity = Binder.clearCallingIdentity();
1814 try {
1815 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1816 logv("Shutting down Phone " + i);
1817 shutdownRadioUsingPhoneId(i);
1818 }
1819 } finally {
1820 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001821 }
1822 }
1823
1824 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001825 Phone phone = PhoneFactory.getPhone(phoneId);
1826 if (phone != null && phone.isRadioAvailable()) {
1827 phone.shutdownRadio();
1828 }
1829 }
1830
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001832 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001833
1834 final long identity = Binder.clearCallingIdentity();
1835 try {
1836 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1837 if (defaultPhone != null) {
1838 defaultPhone.setRadioPower(turnOn);
1839 return true;
1840 } else {
1841 loge("There's no default phone.");
1842 return false;
1843 }
1844 } finally {
1845 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001846 }
Wink Saville36469e72014-06-11 15:17:00 -07001847 }
1848
Wink Savilleb564aae2014-10-23 10:18:09 -07001849 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001851
1852 final long identity = Binder.clearCallingIdentity();
1853 try {
1854 final Phone phone = getPhone(subId);
1855 if (phone != null) {
1856 phone.setRadioPower(turnOn);
1857 return true;
1858 } else {
1859 return false;
1860 }
1861 } finally {
1862 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001863 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001864 }
1865
Wink Saville36469e72014-06-11 15:17:00 -07001866 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001867 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 public boolean enableDataConnectivity() {
1869 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001870
1871 final long identity = Binder.clearCallingIdentity();
1872 try {
1873 int subId = mSubscriptionController.getDefaultDataSubId();
1874 final Phone phone = getPhone(subId);
1875 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001876 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001877 return true;
1878 } else {
1879 return false;
1880 }
1881 } finally {
1882 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 }
1885
Wink Saville36469e72014-06-11 15:17:00 -07001886 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001887 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 public boolean disableDataConnectivity() {
1889 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001890
1891 final long identity = Binder.clearCallingIdentity();
1892 try {
1893 int subId = mSubscriptionController.getDefaultDataSubId();
1894 final Phone phone = getPhone(subId);
1895 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001896 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001897 return true;
1898 } else {
1899 return false;
1900 }
1901 } finally {
1902 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001903 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 }
1905
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001907 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001908 final long identity = Binder.clearCallingIdentity();
1909 try {
1910 final Phone phone = getPhone(subId);
1911 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001912 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001913 } else {
1914 return false;
1915 }
1916 } finally {
1917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 }
1920
1921 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001922 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001923 }
1924
pkanwarae03a6b2016-11-06 20:37:09 -08001925 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001926 enforceCallPermission();
1927
1928 final long identity = Binder.clearCallingIdentity();
1929 try {
1930 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1931 return;
1932 }
1933 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1934 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1935 } finally {
1936 Binder.restoreCallingIdentity(identity);
1937 }
pkanwar32d516d2016-10-14 19:37:38 -07001938 };
1939
Wink Savilleb564aae2014-10-23 10:18:09 -07001940 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001942
1943 final long identity = Binder.clearCallingIdentity();
1944 try {
1945 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1946 return false;
1947 }
1948 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1949 } finally {
1950 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 }
1953
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001955 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001956 }
1957
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001958 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001959 final long identity = Binder.clearCallingIdentity();
1960 try {
1961 Phone phone = PhoneFactory.getPhone(slotIndex);
1962 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1963 PhoneConstantConversions.convertCallState(phone.getState());
1964 } finally {
1965 Binder.restoreCallingIdentity(identity);
1966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 }
1968
Sanket Padawe356d7632015-06-22 14:03:32 -07001969 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001970 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001971 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1972 }
1973
1974 @Override
1975 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001976 final long identity = Binder.clearCallingIdentity();
1977 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001978 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001979 if (phone != null) {
1980 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1981 } else {
1982 return PhoneConstantConversions.convertDataState(
1983 PhoneConstants.DataState.DISCONNECTED);
1984 }
1985 } finally {
1986 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001987 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988 }
1989
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001991 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001992 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1993 }
1994
1995 @Override
1996 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001997 final long identity = Binder.clearCallingIdentity();
1998 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001999 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000 if (phone != null) {
2001 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2002 } else {
2003 return TelephonyManager.DATA_ACTIVITY_NONE;
2004 }
2005 } finally {
2006 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002007 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002008 }
2009
2010 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002011 public Bundle getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002012 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002013 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002014
2015 LocationAccessPolicy.LocationPermissionResult locationResult =
2016 LocationAccessPolicy.checkLocationPermission(mApp,
2017 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2018 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002019 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002020 .setCallingPid(Binder.getCallingPid())
2021 .setCallingUid(Binder.getCallingUid())
2022 .setMethod("getCellLocation")
2023 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2024 .build());
2025 switch (locationResult) {
2026 case DENIED_HARD:
2027 throw new SecurityException("Not allowed to access cell location");
2028 case DENIED_SOFT:
2029 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 }
2031
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002032 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002033 final long identity = Binder.clearCallingIdentity();
2034 try {
2035 if (DBG_LOC) log("getCellLocation: is active user");
2036 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002037 int subId = mSubscriptionController.getDefaultDataSubId();
2038 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2039 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040 return data;
2041 } finally {
2042 Binder.restoreCallingIdentity(identity);
2043 }
Svetoslav64fad262015-04-14 14:35:21 -07002044 }
2045
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002047 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2048 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002049 if (!TextUtils.isEmpty(callingPackage)) {
2050 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002051 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2052 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002053 return "";
2054 }
2055 }
2056
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002057 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2058 // registered cell info, so return a NULL country instead.
2059 final long identity = Binder.clearCallingIdentity();
2060 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002061 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2062 // Get default phone in this case.
2063 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2064 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002065 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002066 // Todo: fix this when we can get the actual cellular network info when the device
2067 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002068 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002069 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2070 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002071 return "";
2072 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002073 Phone phone = PhoneFactory.getPhone(phoneId);
2074 if (phone != null) {
2075 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002076 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002077 if (sst != null) {
2078 LocaleTracker lt = sst.getLocaleTracker();
2079 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002080 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2081 return lt.getCurrentCountry();
2082 } else if (emergencyNumberTracker != null) {
2083 return emergencyNumberTracker.getEmergencyCountryIso();
2084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002085 }
2086 }
2087 }
2088 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002089 } finally {
2090 Binder.restoreCallingIdentity(identity);
2091 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002092 }
2093
2094 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002096 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002097 }
2098
Sanket Padawe356d7632015-06-22 14:03:32 -07002099 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002100 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002101 mApp.enforceCallingOrSelfPermission(
2102 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002103
2104 final long identity = Binder.clearCallingIdentity();
2105 try {
2106 final Phone phone = getPhone(subId);
2107 if (phone != null) {
2108 phone.enableLocationUpdates();
2109 }
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 }
2114
2115 @Override
2116 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002117 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002118 }
2119
Sanket Padawe356d7632015-06-22 14:03:32 -07002120 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002121 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002122 mApp.enforceCallingOrSelfPermission(
2123 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002124
2125 final long identity = Binder.clearCallingIdentity();
2126 try {
2127 final Phone phone = getPhone(subId);
2128 if (phone != null) {
2129 phone.disableLocationUpdates();
2130 }
2131 } finally {
2132 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002133 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 }
2135
Nathan Harold31d7ff32018-10-15 20:20:30 -07002136 /**
2137 * Returns the target SDK version number for a given package name.
2138 *
Nathan Haroldec184742019-07-10 17:04:16 -07002139 * This call MUST be invoked before clearing the calling UID.
2140 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002141 * @return target SDK if the package is found or INT_MAX.
2142 */
2143 private int getTargetSdk(String packageName) {
2144 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002145 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002146 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002147 if (ai != null) return ai.targetSdkVersion;
2148 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002149 loge("Failed to get package info for pkg="
2150 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002151 }
2152 return Integer.MAX_VALUE;
2153 }
2154
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 @Override
2156 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002157 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2158 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002159 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002160 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2161 throw new SecurityException(
2162 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2163 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002164
Jordan Liu1617b712019-07-10 15:06:26 -07002165 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2167 return null;
2168 }
Svetoslav64fad262015-04-14 14:35:21 -07002169
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002170 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002172 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002173 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174
Nathan Haroldf180aac2018-06-01 18:43:55 -07002175 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2176 for (CellInfo ci : info) {
2177 if (ci instanceof CellInfoGsm) {
2178 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2179 } else if (ci instanceof CellInfoWcdma) {
2180 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002183 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 }
2185
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002186 private List<CellInfo> getCachedCellInfo() {
2187 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2188 for (Phone phone : PhoneFactory.getPhones()) {
2189 List<CellInfo> info = phone.getAllCellInfo();
2190 if (info != null) cellInfos.addAll(info);
2191 }
2192 return cellInfos;
2193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194
2195 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002196 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002197 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002198 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002199
2200 LocationAccessPolicy.LocationPermissionResult locationResult =
2201 LocationAccessPolicy.checkLocationPermission(mApp,
2202 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2203 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002204 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002205 .setCallingPid(Binder.getCallingPid())
2206 .setCallingUid(Binder.getCallingUid())
2207 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002208 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002209 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2210 .build());
2211 switch (locationResult) {
2212 case DENIED_HARD:
2213 throw new SecurityException("Not allowed to access cell info");
2214 case DENIED_SOFT:
2215 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 }
2217
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002218 final int targetSdk = getTargetSdk(callingPackage);
2219 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2220 return getCachedCellInfo();
2221 }
2222
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002223 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002224 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002225 final long identity = Binder.clearCallingIdentity();
2226 try {
2227 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2228 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002229 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002230 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002231 if (info != null) cellInfos.addAll(info);
2232 }
2233 return cellInfos;
2234 } finally {
2235 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 }
2237 }
2238
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002239 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002240 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2241 String callingFeatureId) {
2242 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2243 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002244 }
2245
2246 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002247 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2248 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002249 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002250 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002251 }
2252
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002253 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2254 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002255 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002256 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002257
2258 LocationAccessPolicy.LocationPermissionResult locationResult =
2259 LocationAccessPolicy.checkLocationPermission(mApp,
2260 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2261 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002262 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002263 .setCallingPid(Binder.getCallingPid())
2264 .setCallingUid(Binder.getCallingUid())
2265 .setMethod("requestCellInfoUpdate")
2266 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2267 .build());
2268 switch (locationResult) {
2269 case DENIED_HARD:
2270 throw new SecurityException("Not allowed to access cell info");
2271 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002272 try {
2273 cb.onCellInfo(new ArrayList<CellInfo>());
2274 } catch (RemoteException re) {
2275 // Drop without consequences
2276 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002277 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002278 }
2279
Nathan Harolda939a962019-05-09 10:13:47 -07002280
2281 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002282 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2283
2284 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2285 }
2286
2287 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002289 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002290 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002291
2292 final long identity = Binder.clearCallingIdentity();
2293 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002294 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295 } finally {
2296 Binder.restoreCallingIdentity(identity);
2297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 }
2299
Shishir Agrawala9f32182016-04-12 12:00:16 -07002300 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002301 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002302 Phone phone = PhoneFactory.getPhone(slotIndex);
2303 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002304 return null;
2305 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002306 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002307 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002308 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002309 return null;
2310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002311
2312 final long identity = Binder.clearCallingIdentity();
2313 try {
2314 return phone.getImei();
2315 } finally {
2316 Binder.restoreCallingIdentity(identity);
2317 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002318 }
2319
2320 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002321 public String getTypeAllocationCodeForSlot(int slotIndex) {
2322 Phone phone = PhoneFactory.getPhone(slotIndex);
2323 String tac = null;
2324 if (phone != null) {
2325 String imei = phone.getImei();
2326 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2327 }
2328 return tac;
2329 }
2330
2331 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002332 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002333 Phone phone = PhoneFactory.getPhone(slotIndex);
2334 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002335 return null;
2336 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002337
Jeff Davidson913390f2018-02-23 17:11:49 -08002338 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002339 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002340 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002341 return null;
2342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002343
2344 final long identity = Binder.clearCallingIdentity();
2345 try {
2346 return phone.getMeid();
2347 } finally {
2348 Binder.restoreCallingIdentity(identity);
2349 }
Jack Yu2af8d712017-03-15 17:14:14 -07002350 }
2351
2352 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002353 public String getManufacturerCodeForSlot(int slotIndex) {
2354 Phone phone = PhoneFactory.getPhone(slotIndex);
2355 String manufacturerCode = null;
2356 if (phone != null) {
2357 String meid = phone.getMeid();
2358 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2359 }
2360 return manufacturerCode;
2361 }
2362
2363 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002364 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2365 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002366 Phone phone = PhoneFactory.getPhone(slotIndex);
2367 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002368 return null;
2369 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002370 int subId = phone.getSubId();
2371 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002372 mApp, subId, callingPackage, callingFeatureId,
2373 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002374 return null;
2375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002376
2377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 return phone.getDeviceSvn();
2380 } finally {
2381 Binder.restoreCallingIdentity(identity);
2382 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002383 }
2384
fionaxu43304da2017-11-27 22:51:16 -08002385 @Override
2386 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387 final long identity = Binder.clearCallingIdentity();
2388 try {
2389 final Phone phone = getPhone(subId);
2390 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2391 } finally {
2392 Binder.restoreCallingIdentity(identity);
2393 }
fionaxu43304da2017-11-27 22:51:16 -08002394 }
2395
2396 @Override
2397 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002398 final long identity = Binder.clearCallingIdentity();
2399 try {
2400 final Phone phone = getPhone(subId);
2401 return phone == null ? null : phone.getCarrierName();
2402 } finally {
2403 Binder.restoreCallingIdentity(identity);
2404 }
fionaxu43304da2017-11-27 22:51:16 -08002405 }
2406
calvinpanffe225e2018-11-01 19:43:06 +08002407 @Override
chen xu0026ca62019-03-06 15:28:50 -08002408 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002409 final long identity = Binder.clearCallingIdentity();
2410 try {
2411 final Phone phone = getPhone(subId);
2412 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002413 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002414 } finally {
2415 Binder.restoreCallingIdentity(identity);
2416 }
2417 }
2418
2419 @Override
chen xu0026ca62019-03-06 15:28:50 -08002420 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002421 final long identity = Binder.clearCallingIdentity();
2422 try {
2423 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002424 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002425 } finally {
2426 Binder.restoreCallingIdentity(identity);
2427 }
2428 }
2429
chen xu651eec72018-11-11 19:03:44 -08002430 @Override
chen xu864e11c2018-12-06 22:10:03 -08002431 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2432 if (!isSubscriptionMccMnc) {
2433 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2434 }
chen xu651eec72018-11-11 19:03:44 -08002435 final Phone phone = PhoneFactory.getPhone(slotIndex);
2436 if (phone == null) {
2437 return TelephonyManager.UNKNOWN_CARRIER_ID;
2438 }
2439 final long identity = Binder.clearCallingIdentity();
2440 try {
2441 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2442 } finally {
2443 Binder.restoreCallingIdentity(identity);
2444 }
2445 }
2446
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 //
2448 // Internal helper methods.
2449 //
2450
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002451 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2453 *
2454 * @throws SecurityException if the caller does not have the required permission
2455 */
2456 private void enforceModifyPermission() {
2457 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2458 }
2459
Shuo Qian3b6ee772019-11-13 17:43:31 -08002460 private void enforceActiveEmergencySessionPermission() {
2461 mApp.enforceCallingOrSelfPermission(
2462 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2463 }
2464
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 /**
2466 * Make sure the caller has the CALL_PHONE permission.
2467 *
2468 * @throws SecurityException if the caller does not have the required permission
2469 */
2470 private void enforceCallPermission() {
2471 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2472 }
2473
paulhu5a773602019-08-23 19:17:33 +08002474 private void enforceSettingsPermission() {
2475 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002476 }
2477
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 private String createTelUrl(String number) {
2479 if (TextUtils.isEmpty(number)) {
2480 return null;
2481 }
2482
Jake Hambye994d462014-02-03 13:10:13 -08002483 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 }
2485
Ihab Awadf9e92732013-12-05 18:02:52 -08002486 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2488 }
2489
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002490 private static void logv(String msg) {
2491 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2492 }
2493
Ihab Awadf9e92732013-12-05 18:02:52 -08002494 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2496 }
2497
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002498 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002500 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002501 }
2502
Sanket Padawe356d7632015-06-22 14:03:32 -07002503 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002504 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505 final long identity = Binder.clearCallingIdentity();
2506 try {
2507 final Phone phone = PhoneFactory.getPhone(slotIndex);
2508 if (phone == null) {
2509 return PhoneConstants.PHONE_TYPE_NONE;
2510 } else {
2511 return phone.getPhoneType();
2512 }
2513 } finally {
2514 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002515 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 }
2517
2518 /**
2519 * Returns the CDMA ERI icon index to display
2520 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002521 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002522 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2523 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2524 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002525 }
2526
Sanket Padawe356d7632015-06-22 14:03:32 -07002527 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002528 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2529 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002531 mApp, subId, callingPackage, callingFeatureId,
2532 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002533 return -1;
2534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002535
2536 final long identity = Binder.clearCallingIdentity();
2537 try {
2538 final Phone phone = getPhone(subId);
2539 if (phone != null) {
2540 return phone.getCdmaEriIconIndex();
2541 } else {
2542 return -1;
2543 }
2544 } finally {
2545 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 }
2548
2549 /**
2550 * Returns the CDMA ERI icon mode,
2551 * 0 - ON
2552 * 1 - FLASHING
2553 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002554 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002555 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2556 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2557 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002558 }
2559
Sanket Padawe356d7632015-06-22 14:03:32 -07002560 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002561 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2562 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002563 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002564 mApp, subId, callingPackage, callingFeatureId,
2565 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002566 return -1;
2567 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 final Phone phone = getPhone(subId);
2572 if (phone != null) {
2573 return phone.getCdmaEriIconMode();
2574 } else {
2575 return -1;
2576 }
2577 } finally {
2578 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002579 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002580 }
2581
2582 /**
2583 * Returns the CDMA ERI text,
2584 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002585 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002586 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2587 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2588 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002589 }
2590
Sanket Padawe356d7632015-06-22 14:03:32 -07002591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002592 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2593 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002594 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002595 mApp, subId, callingPackage, callingFeatureId,
2596 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002597 return null;
2598 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599
2600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 final Phone phone = getPhone(subId);
2603 if (phone != null) {
2604 return phone.getCdmaEriText();
2605 } else {
2606 return null;
2607 }
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611 }
2612
2613 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002614 * Returns the CDMA MDN.
2615 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002616 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002617 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2619 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620
2621 final long identity = Binder.clearCallingIdentity();
2622 try {
2623 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002624 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 return phone.getLine1Number();
2626 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002627 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628 return null;
2629 }
2630 } finally {
2631 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002632 }
2633 }
2634
2635 /**
2636 * Returns the CDMA MIN.
2637 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002638 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002639 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2641 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642
2643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 final Phone phone = getPhone(subId);
2646 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2647 return phone.getCdmaMin();
2648 } else {
2649 return null;
2650 }
2651 } finally {
2652 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002653 }
2654 }
2655
Hall Liud892bec2018-11-30 14:51:45 -08002656 @Override
2657 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2658 INumberVerificationCallback callback, String callingPackage) {
2659 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2660 != PERMISSION_GRANTED) {
2661 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2662 }
2663 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2664
2665 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2666 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2667 throw new SecurityException("Calling package must be configured in the device config");
2668 }
2669
2670 if (range == null) {
2671 throw new NullPointerException("Range must be non-null");
2672 }
2673
2674 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002675 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002676
2677 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2678 }
2679
Junda Liuca05d5d2014-08-14 22:36:34 -07002680 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 * Returns true if CDMA provisioning needs to run.
2682 */
2683 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684 final long identity = Binder.clearCallingIdentity();
2685 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002686 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687 } finally {
2688 Binder.restoreCallingIdentity(identity);
2689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 }
2691
2692 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002693 * Sets the voice mail number of a given subId.
2694 */
2695 @Override
2696 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002697 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2698 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699
2700 final long identity = Binder.clearCallingIdentity();
2701 try {
2702 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2703 new Pair<String, String>(alphaTag, number), new Integer(subId));
2704 return success;
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
2707 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002708 }
2709
Ta-wei Yen87c49842016-05-13 21:19:52 -07002710 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002711 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002713 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2714 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002715 if (!TextUtils.equals(callingPackage, systemDialer)) {
2716 throw new SecurityException("caller must be system dialer");
2717 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718
2719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2722 if (phoneAccountHandle == null) {
2723 return null;
2724 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002725 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 } finally {
2727 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002728 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002729 }
2730
2731 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002732 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2733 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002736 mApp, subId, callingPackage, callingFeatureId,
2737 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002738 return null;
2739 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002741 final long identity = Binder.clearCallingIdentity();
2742 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002743 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002744 } finally {
2745 Binder.restoreCallingIdentity(identity);
2746 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002747 }
2748
2749 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002750 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2751 VisualVoicemailSmsFilterSettings settings) {
2752 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753
2754 final long identity = Binder.clearCallingIdentity();
2755 try {
2756 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002757 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758 } finally {
2759 Binder.restoreCallingIdentity(identity);
2760 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002761 }
2762
2763 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002764 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2765 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766
2767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002770 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771 } finally {
2772 Binder.restoreCallingIdentity(identity);
2773 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002774 }
2775
2776 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002777 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2778 String callingPackage, int subId) {
2779 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780
2781 final long identity = Binder.clearCallingIdentity();
2782 try {
2783 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002784 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 } finally {
2786 Binder.restoreCallingIdentity(identity);
2787 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002788 }
2789
2790 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002791 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002792 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793
2794 final long identity = Binder.clearCallingIdentity();
2795 try {
2796 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002797 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798 } finally {
2799 Binder.restoreCallingIdentity(identity);
2800 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002801 }
2802
2803 @Override
2804 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2805 String number, int port, String text, PendingIntent sentIntent) {
2806 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002807 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002808 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002809 SmsController smsController = PhoneFactory.getSmsController();
2810 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2811 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002812 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002813
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002814 /**
fionaxu0152e512016-11-14 13:36:14 -08002815 * Sets the voice activation state of a given subId.
2816 */
2817 @Override
2818 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2820 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821
2822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 final Phone phone = getPhone(subId);
2825 if (phone != null) {
2826 phone.setVoiceActivationState(activationState);
2827 } else {
2828 loge("setVoiceActivationState fails with invalid subId: " + subId);
2829 }
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002832 }
2833 }
2834
2835 /**
2836 * Sets the data activation state of a given subId.
2837 */
2838 @Override
2839 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2841 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002842
2843 final long identity = Binder.clearCallingIdentity();
2844 try {
2845 final Phone phone = getPhone(subId);
2846 if (phone != null) {
2847 phone.setDataActivationState(activationState);
2848 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002849 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850 }
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002853 }
2854 }
2855
2856 /**
2857 * Returns the voice activation state of a given subId.
2858 */
2859 @Override
2860 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002861 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862
fionaxu0152e512016-11-14 13:36:14 -08002863 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 if (phone != null) {
2867 return phone.getVoiceActivationState();
2868 } else {
2869 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2870 }
2871 } finally {
2872 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002873 }
2874 }
2875
2876 /**
2877 * Returns the data activation state of a given subId.
2878 */
2879 @Override
2880 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002881 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882
fionaxu0152e512016-11-14 13:36:14 -08002883 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884 final long identity = Binder.clearCallingIdentity();
2885 try {
2886 if (phone != null) {
2887 return phone.getDataActivationState();
2888 } else {
2889 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2890 }
2891 } finally {
2892 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002893 }
2894 }
2895
2896 /**
Wink Saville36469e72014-06-11 15:17:00 -07002897 * Returns the unread count of voicemails for a subId
2898 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002899 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002900 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2901 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002902 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002903 mApp, subId, callingPackage, callingFeatureId,
2904 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002905 return 0;
2906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 final Phone phone = getPhone(subId);
2910 if (phone != null) {
2911 return phone.getVoiceMessageCount();
2912 } else {
2913 return 0;
2914 }
2915 } finally {
2916 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002917 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002918 }
2919
2920 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002921 * returns true, if the device is in a state where both voice and data
2922 * are supported simultaneously. This can change based on location or network condition.
2923 */
2924 @Override
2925 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926 final long identity = Binder.clearCallingIdentity();
2927 try {
2928 final Phone phone = getPhone(subId);
2929 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
2932 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002933 }
2934
2935 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002936 * Send the dialer code if called from the current default dialer or the caller has
2937 * carrier privilege.
2938 * @param inputCode The dialer code to send
2939 */
2940 @Override
2941 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002942 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002943 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002944 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2945 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002946 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002947 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002948 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002950
2951 final long identity = Binder.clearCallingIdentity();
2952 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002953 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954 } finally {
2955 Binder.restoreCallingIdentity(identity);
2956 }
fionaxu235cc5e2017-03-06 22:25:57 -08002957 }
2958
Pengquan Menga1bb6272018-09-06 09:59:22 -07002959 @Override
2960 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002961 if (!isActiveSubscription(subId)) {
2962 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2963 }
2964
Pengquan Menga1bb6272018-09-06 09:59:22 -07002965 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2966 }
2967
Brad Ebinger35c841c2018-10-01 10:40:55 -07002968 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002969 public boolean isInEmergencySmsMode() {
2970 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 for (Phone phone : PhoneFactory.getPhones()) {
2974 if (phone.isInEmergencySmsMode()) {
2975 return true;
2976 }
2977 }
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
2981 return false;
2982 }
2983
2984 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002985 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2986 throws RemoteException {
2987 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002988 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2989 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2990 "IMS not available on device.");
2991 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002992 final long token = Binder.clearCallingIdentity();
2993 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002994 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002995 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002996 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002997 } catch (ImsException e) {
2998 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002999 } finally {
3000 Binder.restoreCallingIdentity(token);
3001 }
3002 }
3003
3004 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003005 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
3006 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003007 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3008 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3009 }
Meng Wangafbc5852019-09-19 17:37:13 -07003010 final long token = Binder.clearCallingIdentity();
3011 try {
3012 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3013 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3014 .removeRegistrationCallbackForSubscription(c, subId);
3015 } catch (ImsException e) {
3016 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3017 + "is inactive, ignoring unregister.");
3018 // If the subscription is no longer active, just return, since the callback
3019 // will already have been removed internally.
3020 } finally {
3021 Binder.restoreCallingIdentity(token);
3022 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003023 }
3024
Brad Ebingera34a6c22019-10-22 17:36:18 -07003025 /**
3026 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3027 */
3028 @Override
3029 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3030 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3031 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3032 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3033 "IMS not available on device.");
3034 }
3035 final long token = Binder.clearCallingIdentity();
3036 try {
3037 Phone phone = getPhone(subId);
3038 if (phone == null) {
3039 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3040 + subId + "'");
3041 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3042 }
3043 phone.getImsRegistrationState(regState -> {
3044 try {
3045 consumer.accept((regState == null)
3046 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3047 } catch (RemoteException e) {
3048 // Ignore if the remote process is no longer available to call back.
3049 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3050 }
3051 });
3052 } finally {
3053 Binder.restoreCallingIdentity(token);
3054 }
3055 }
3056
3057 /**
3058 * Get the transport type for the IMS service registration state.
3059 */
3060 @Override
3061 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3062 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3063 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3064 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3065 "IMS not available on device.");
3066 }
3067 final long token = Binder.clearCallingIdentity();
3068 try {
3069 Phone phone = getPhone(subId);
3070 if (phone == null) {
3071 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3072 + subId + "'");
3073 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3074 }
3075 phone.getImsRegistrationTech(regTech -> {
3076 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3077 int regTechConverted = (regTech == null)
3078 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3079 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3080 regTechConverted);
3081 try {
3082 consumer.accept(regTechConverted);
3083 } catch (RemoteException e) {
3084 // Ignore if the remote process is no longer available to call back.
3085 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3086 }
3087 });
3088 } finally {
3089 Binder.restoreCallingIdentity(token);
3090 }
3091 }
3092
Brad Ebinger35c841c2018-10-01 10:40:55 -07003093 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003094 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3095 throws RemoteException {
3096 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003097 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3098 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3099 "IMS not available on device.");
3100 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003101 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3102 final long token = Binder.clearCallingIdentity();
3103 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003104 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003105 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003106 } catch (ImsException e) {
3107 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 } finally {
3109 Binder.restoreCallingIdentity(token);
3110 }
3111 }
3112
3113 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003114 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3115 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003116 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3117 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3118 }
Meng Wangafbc5852019-09-19 17:37:13 -07003119
3120 final long token = Binder.clearCallingIdentity();
3121 try {
3122 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3123 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003124 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003125 } catch (ImsException e) {
3126 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3127 + "is inactive, ignoring unregister.");
3128 // If the subscription is no longer active, just return, since the callback
3129 // will already have been removed internally.
3130 } finally {
3131 Binder.restoreCallingIdentity(token);
3132 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003133 }
3134
3135 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003136 public boolean isCapable(int subId, int capability, int regTech) {
3137 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3139 final long token = Binder.clearCallingIdentity();
3140 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003141 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003142 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003143 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003144 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3145 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003146 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003147 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3148 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003149 } finally {
3150 Binder.restoreCallingIdentity(token);
3151 }
3152 }
3153
3154 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003155 public boolean isAvailable(int subId, int capability, int regTech) {
3156 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003157 final long token = Binder.clearCallingIdentity();
3158 try {
3159 Phone phone = getPhone(subId);
3160 if (phone == null) return false;
3161 return phone.isImsCapabilityAvailable(capability, regTech);
3162 } finally {
3163 Binder.restoreCallingIdentity(token);
3164 }
3165 }
3166
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003167 /**
3168 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3169 * subscription.
3170 * @param subId The subscription to use to check the configuration.
3171 * @param callback The callback that will be used to send the result.
3172 * @param capability The MmTelFeature capability that will be used to send the result.
3173 * @param transportType The transport type of the MmTelFeature capability.
3174 */
3175 @Override
3176 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3177 int transportType) {
3178 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3179 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3180 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3181 "IMS not available on device.");
3182 }
3183 final long token = Binder.clearCallingIdentity();
3184 try {
3185 int slotId = getSlotIndex(subId);
3186 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3187 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3188 + subId + "'");
3189 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3190 }
3191 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3192 transportType, aBoolean -> {
3193 try {
3194 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3195 } catch (RemoteException e) {
3196 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3197 + "running. Ignore");
3198 }
3199 });
3200 } finally {
3201 Binder.restoreCallingIdentity(token);
3202 }
3203 }
3204
Brad Ebinger35c841c2018-10-01 10:40:55 -07003205 @Override
3206 public boolean isAdvancedCallingSettingEnabled(int subId) {
3207 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3208 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3209 final long token = Binder.clearCallingIdentity();
3210 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003211 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003212 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003213 } catch (ImsException e) {
3214 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003215 } finally {
3216 Binder.restoreCallingIdentity(token);
3217 }
3218 }
3219
3220 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003221 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003223 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003224 final long identity = Binder.clearCallingIdentity();
3225 try {
3226 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003227 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003228 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
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(identity);
3233 }
3234 }
3235
3236 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003237 public boolean isVtSettingEnabled(int subId) {
3238 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003239 final long identity = Binder.clearCallingIdentity();
3240 try {
3241 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003242 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3243 } catch (ImsException e) {
3244 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003245 } finally {
3246 Binder.restoreCallingIdentity(identity);
3247 }
3248 }
3249
3250 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003251 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003253 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003254 final long identity = Binder.clearCallingIdentity();
3255 try {
3256 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003257 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003258 } catch (ImsException e) {
3259 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003260 } finally {
3261 Binder.restoreCallingIdentity(identity);
3262 }
3263 }
3264
3265 @Override
3266 public boolean isVoWiFiSettingEnabled(int subId) {
3267 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3268 final long identity = Binder.clearCallingIdentity();
3269 try {
3270 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003271 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003272 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003273 } catch (ImsException e) {
3274 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003275 } finally {
3276 Binder.restoreCallingIdentity(identity);
3277 }
3278 }
3279
3280 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003281 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003283 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003284 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 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003288 } catch (ImsException e) {
3289 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003290 } finally {
3291 Binder.restoreCallingIdentity(identity);
3292 }
3293 }
3294
3295 @Override
3296 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3297 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003301 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003302 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003303 } catch (ImsException e) {
3304 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003305 } finally {
3306 Binder.restoreCallingIdentity(identity);
3307 }
3308 }
3309
3310 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003311 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003313 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003314 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 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003318 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
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
3327 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3329 "setVoWiFiNonPersistent");
3330 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 Ebinger2d29c012019-05-07 18:33:46 -07003334 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
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 int getVoWiFiModeSetting(int subId) {
3344 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003348 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003350 } catch (ImsException e) {
3351 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
3355 }
3356
3357 @Override
3358 public void setVoWiFiModeSetting(int subId, int mode) {
3359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3360 "setVoWiFiModeSetting");
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 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 getSlotIndexOrException(subId)).setWfcMode(mode, 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 int getVoWiFiRoamingModeSetting(int subId) {
3375 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003379 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003380 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003381 } catch (ImsException e) {
3382 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 } finally {
3384 Binder.restoreCallingIdentity(identity);
3385 }
3386 }
3387
3388 @Override
3389 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3391 "setVoWiFiRoamingModeSetting");
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 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003396 getSlotIndexOrException(subId)).setWfcMode(mode, 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 setRttCapabilitySetting(int subId, boolean isEnabled) {
3406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3407 "setRttCapabilityEnabled");
3408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003411 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3412 } catch (ImsException e) {
3413 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003414 } finally {
3415 Binder.restoreCallingIdentity(identity);
3416 }
3417 }
3418
3419 @Override
3420 public boolean isTtyOverVolteEnabled(int subId) {
3421 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003425 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003427 } catch (ImsException e) {
3428 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003429 } finally {
3430 Binder.restoreCallingIdentity(identity);
3431 }
3432 }
3433
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003434 @Override
3435 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3436 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003440 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003441 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003442 } catch (ImsException e) {
3443 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003444 } finally {
3445 Binder.restoreCallingIdentity(identity);
3446 }
3447 }
3448
3449 @Override
3450 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3451 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3452 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003453 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3454 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3455 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003456 try {
3457 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003458 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003459 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003460 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003461 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3462 + "is inactive, ignoring unregister.");
3463 // If the subscription is no longer active, just return, since the callback will already
3464 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003465 } finally {
3466 Binder.restoreCallingIdentity(identity);
3467 }
3468 }
3469
3470 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003471 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3472 boolean isProvisioned) {
3473 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3474 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3475 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3476 }
3477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3478 "setProvisioningStatusForCapability");
3479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3482 Phone phone = getPhone(subId);
3483 if (phone == null) {
3484 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3485 + subId);
3486 return;
3487 }
3488 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3489 return;
3490 }
3491
3492 // this capability requires provisioning, route to the correct API.
3493 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3494 switch (capability) {
3495 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3496 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3497 ims.setVolteProvisioned(isProvisioned);
3498 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3499 ims.setWfcProvisioned(isProvisioned);
3500 }
3501 break;
3502 }
3503 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3504 // There is currently no difference in VT provisioning type.
3505 ims.setVtProvisioned(isProvisioned);
3506 break;
3507 }
3508 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3509 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3510 // change the capability of the feature instead if needed.
3511 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3512 == isProvisioned) {
3513 // No change in provisioning.
3514 return;
3515 }
3516 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3517 try {
3518 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003519 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003520 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3521 + ", Exception" + e.getMessage());
3522 }
3523 break;
3524 }
3525 default: {
3526 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3527 + capability + "', which does not require provisioning.");
3528 }
3529 }
3530
3531 } finally {
3532 Binder.restoreCallingIdentity(identity);
3533 }
3534 }
3535
3536 @Override
3537 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3538 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3539 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3540 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3541 }
3542 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3546 Phone phone = getPhone(subId);
3547 if (phone == null) {
3548 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3549 + subId);
3550 // We will fail with "true" as the provisioning status because this is the default
3551 // if we do not require provisioning.
3552 return true;
3553 }
3554
3555 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3556 return true;
3557 }
3558
3559 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3560 switch (capability) {
3561 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3562 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3563 return ims.isVolteProvisionedOnDevice();
3564 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3565 return ims.isWfcProvisionedOnDevice();
3566 }
3567 // This should never happen, since we are checking tech above to make sure it
3568 // is either LTE or IWLAN.
3569 throw new IllegalArgumentException("Invalid radio technology for voice "
3570 + "capability.");
3571 }
3572 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3573 // There is currently no difference in VT provisioning type.
3574 return ims.isVtProvisionedOnDevice();
3575 }
3576 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3577 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3578 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3579 }
3580 default: {
3581 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3582 + capability + "', which does not require provisioning.");
3583 }
3584 }
3585
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
3588 }
3589 }
3590
3591 @Override
3592 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3593 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3594 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3595 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3596 }
3597 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3598 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3599 return (provisionedBits & capability) > 0;
3600 }
3601
3602 @Override
3603 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3604 boolean isProvisioned) {
3605 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3606 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3607 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3608 }
3609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3610 "setProvisioningStatusForCapability");
3611 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3612 // If the current provisioning status for capability already matches isProvisioned,
3613 // do nothing.
3614 if (((provisionedBits & capability) > 0) == isProvisioned) {
3615 return;
3616 }
3617 if (isProvisioned) {
3618 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3619 } else {
3620 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3621 }
3622 }
3623
3624 /**
3625 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3626 * technology. The bitfield should mirror the bitfield defined by
3627 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3628 */
3629 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3630 String key = getMmTelProvisioningKey(subId, tech);
3631 // Default is no capabilities are provisioned.
3632 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3633 }
3634
3635 /**
3636 * Sets the MmTel capability provisioning bitfield (defined by
3637 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3638 * technology specified.
3639 *
3640 * Note: This is a synchronous command and should not be called on UI thread.
3641 */
3642 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3643 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3644 String key = getMmTelProvisioningKey(subId, tech);
3645 editor.putInt(key, newField);
3646 editor.commit();
3647 }
3648
3649 private static String getMmTelProvisioningKey(int subId, int tech) {
3650 // resulting key is provision_ims_mmtel_{subId}_{tech}
3651 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3652 }
3653
3654 /**
3655 * Query CarrierConfig to see if the specified capability requires provisioning for the
3656 * carrier associated with the subscription id.
3657 */
3658 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3659 int capability) {
3660 CarrierConfigManager configManager = new CarrierConfigManager(context);
3661 PersistableBundle c = configManager.getConfigForSubId(subId);
3662 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003663 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003664 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3665 false);
3666 boolean requireVoiceVtProvisioning = c.getBoolean(
3667 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3668
3669 // First check to make sure that the capability requires provisioning.
3670 switch (capability) {
3671 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3672 // intentional fallthrough
3673 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3674 if (requireVoiceVtProvisioning) {
3675 // Voice and Video requires provisioning
3676 return true;
3677 }
3678 break;
3679 }
3680 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3681 if (requireUtProvisioning) {
3682 // UT requires provisioning
3683 return true;
3684 }
3685 break;
3686 }
3687 }
3688 return false;
3689 }
3690
3691 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003692 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003693 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3694 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3695 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003696 enforceReadPrivilegedPermission("getImsProvisioningInt");
3697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003700 int slotId = getSlotIndex(subId);
3701 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3702 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3703 + subId + "' for key:" + key);
3704 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3705 }
3706 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003707 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003708 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3709 + subId + "' for key:" + key);
3710 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
3714 }
3715
3716 @Override
3717 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003718 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3719 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3720 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003721 enforceReadPrivilegedPermission("getImsProvisioningString");
3722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003725 int slotId = getSlotIndex(subId);
3726 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3727 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3728 + subId + "' for key:" + key);
3729 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3730 }
3731 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003732 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003733 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3734 + subId + "' for key:" + key);
3735 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003736 } finally {
3737 Binder.restoreCallingIdentity(identity);
3738 }
3739 }
3740
3741 @Override
3742 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003743 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3744 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3745 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3747 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003751 int slotId = getSlotIndex(subId);
3752 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3753 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3754 + subId + "' for key:" + key);
3755 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3756 }
3757 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003758 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003759 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3760 + "' for key:" + key);
3761 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003762 } finally {
3763 Binder.restoreCallingIdentity(identity);
3764 }
3765 }
3766
3767 @Override
3768 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003769 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3770 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3771 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3773 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003774 final long identity = Binder.clearCallingIdentity();
3775 try {
3776 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003777 int slotId = getSlotIndex(subId);
3778 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3779 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3780 + subId + "' for key:" + key);
3781 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3782 }
3783 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003784 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003785 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3786 + "' for key:" + key);
3787 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003788 } finally {
3789 Binder.restoreCallingIdentity(identity);
3790 }
3791 }
3792
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003793 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003794 int slotId = SubscriptionManager.getSlotIndex(subId);
3795 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003796 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3797 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003798 }
3799 return slotId;
3800 }
3801
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003802 private int getSlotIndex(int subId) {
3803 int slotId = SubscriptionManager.getSlotIndex(subId);
3804 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3805 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3806 }
3807 return slotId;
3808 }
3809
Wink Saville36469e72014-06-11 15:17:00 -07003810 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003811 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003812 */
3813 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003814 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3815 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003816 final int targetSdk = getTargetSdk(callingPackage);
3817 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003818 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003819 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003820 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003821 mApp, subId, callingPackage, callingFeatureId,
3822 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003823 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3824 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 final Phone phone = getPhone(subId);
3829 if (phone != null) {
3830 return phone.getServiceState().getDataNetworkType();
3831 } else {
3832 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3833 }
3834 } finally {
3835 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003836 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003837 }
3838
3839 /**
3840 * Returns the data network type
3841 */
3842 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003843 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3844 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3845 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003846 }
3847
3848 /**
3849 * Returns the data network type for a subId
3850 */
3851 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003852 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3853 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003854 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003855 mApp, subId, callingPackage, callingFeatureId,
3856 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003857 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3858 }
3859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003860 final long identity = Binder.clearCallingIdentity();
3861 try {
3862 final Phone phone = getPhone(subId);
3863 if (phone != null) {
3864 return phone.getServiceState().getDataNetworkType();
3865 } else {
3866 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3867 }
3868 } finally {
3869 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003871 }
3872
3873 /**
Wink Saville36469e72014-06-11 15:17:00 -07003874 * Returns the Voice network type for a subId
3875 */
3876 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003877 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3878 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003880 mApp, subId, callingPackage, callingFeatureId,
3881 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003882 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3883 }
3884
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003885 final long identity = Binder.clearCallingIdentity();
3886 try {
3887 final Phone phone = getPhone(subId);
3888 if (phone != null) {
3889 return phone.getServiceState().getVoiceNetworkType();
3890 } else {
3891 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3892 }
3893 } finally {
3894 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003896 }
3897
3898 /**
3899 * @return true if a ICC card is present
3900 */
3901 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003902 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003903 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3904 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003905 }
3906
3907 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003908 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003909 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003910 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003911 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912 final long identity = Binder.clearCallingIdentity();
3913 try {
3914 final Phone phone = PhoneFactory.getPhone(slotIndex);
3915 if (phone != null) {
3916 return phone.getIccCard().hasIccCard();
3917 } else {
3918 return false;
3919 }
3920 } finally {
3921 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003923 }
3924
3925 /**
3926 * Return if the current radio is LTE on CDMA. This
3927 * is a tri-state return value as for a period of time
3928 * the mode may be unknown.
3929 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003930 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003931 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003932 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003933 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003934 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003935 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3936 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3937 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003938 }
3939
Sanket Padawe356d7632015-06-22 14:03:32 -07003940 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003941 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3942 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003943 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003944 mApp, subId, callingPackage, callingFeatureId,
3945 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003946 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3947 }
3948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 final Phone phone = getPhone(subId);
3952 if (phone == null) {
3953 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3954 } else {
3955 return phone.getLteOnCdmaMode();
3956 }
3957 } finally {
3958 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003959 }
Wink Saville36469e72014-06-11 15:17:00 -07003960 }
3961
Wink Saville36469e72014-06-11 15:17:00 -07003962 /**
3963 * {@hide}
3964 * Returns Default subId, 0 in the case of single standby.
3965 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003966 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003967 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003968 }
3969
Shishir Agrawala9f32182016-04-12 12:00:16 -07003970 private int getSlotForDefaultSubscription() {
3971 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3972 }
3973
Wink Savilleb564aae2014-10-23 10:18:09 -07003974 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003975 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003976 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003977
Pengquan Menge92a50d2018-09-21 15:54:48 -07003978 private boolean isActiveSubscription(int subId) {
3979 return mSubscriptionController.isActiveSubId(subId);
3980 }
3981
Ihab Awadf2177b72013-11-25 13:33:23 -08003982 /**
3983 * @see android.telephony.TelephonyManager.WifiCallingChoices
3984 */
3985 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003986 final long identity = Binder.clearCallingIdentity();
3987 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003988 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003989 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3990 getWhenToMakeWifiCallsDefaultPreference());
3991 } finally {
3992 Binder.restoreCallingIdentity(identity);
3993 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003994 }
3995
3996 /**
3997 * @see android.telephony.TelephonyManager.WifiCallingChoices
3998 */
3999 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004000 final long identity = Binder.clearCallingIdentity();
4001 try {
4002 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004003 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004004 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4005 } finally {
4006 Binder.restoreCallingIdentity(identity);
4007 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004008 }
4009
Sailesh Nepald1e68152013-12-12 19:08:02 -08004010 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004011 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004012 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004013 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004014
Jordan Liu4c733742019-02-28 12:03:40 -08004015 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4016 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4017 if (phoneId == -1) {
4018 throw new IllegalArgumentException("Given slot index: " + slotIndex
4019 + " does not correspond to an active phone");
4020 }
4021 return PhoneFactory.getPhone(phoneId);
4022 }
4023
Shishir Agrawal566b7612013-10-28 14:41:00 -07004024 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004025 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4026 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4028 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004029 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004030 if (DBG) {
4031 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4032 }
4033 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4034 p2);
4035 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004036
Jordan Liu4c733742019-02-28 12:03:40 -08004037
4038 @Override
4039 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4040 int slotIndex, String callingPackage, String aid, int p2) {
4041 enforceModifyPermission();
4042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4043 if (DBG) {
4044 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4045 }
4046 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4047 callingPackage, aid, p2);
4048 }
4049
4050 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4051 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 if (TextUtils.equals(ISDR_AID, aid)) {
4055 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004056 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4057 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058 if (bestComponent == null
4059 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4060 loge("The calling package is not allowed to access ISD-R.");
4061 throw new SecurityException(
4062 "The calling package is not allowed to access ISD-R.");
4063 }
Derek Tan740e1672017-06-27 14:56:27 -07004064 }
Derek Tan740e1672017-06-27 14:56:27 -07004065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004066 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004067 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4068 null /* workSource */);
4069 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070 return response;
4071 } finally {
4072 Binder.restoreCallingIdentity(identity);
4073 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004074 }
4075
4076 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004077 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4079 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004080 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4081 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4082 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004083
Jordan Liu4c733742019-02-28 12:03:40 -08004084 @Override
4085 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4086 enforceModifyPermission();
4087 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4088 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4089 channel);
4090 }
4091
4092 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093 final long identity = Binder.clearCallingIdentity();
4094 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095 if (channel < 0) {
4096 return false;
4097 }
Jordan Liu4c733742019-02-28 12:03:40 -08004098 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4099 null /* workSource */);
4100 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101 return success;
4102 } finally {
4103 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004104 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004105 }
4106
4107 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004108 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004109 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4111 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004112 if (DBG) {
4113 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4114 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4115 + p3 + " data=" + data);
4116 }
4117 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4118 command, p1, p2, p3, data);
4119 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004120
Jordan Liu4c733742019-02-28 12:03:40 -08004121 @Override
4122 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4123 int command, int p1, int p2, int p3, String data) {
4124 enforceModifyPermission();
4125 if (DBG) {
4126 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4127 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4128 + p3 + " data=" + data);
4129 }
4130 return iccTransmitApduLogicalChannelWithPermission(
4131 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4132 data);
4133 }
4134
4135 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4136 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004137 final long identity = Binder.clearCallingIdentity();
4138 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004139 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004140 return "";
4141 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004144 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4145 null /* workSource */);
4146 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004147
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148 // Append the returned status code to the end of the response payload.
4149 String s = Integer.toHexString(
4150 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4151 if (response.payload != null) {
4152 s = IccUtils.bytesToHexString(response.payload) + s;
4153 }
4154 return s;
4155 } finally {
4156 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004157 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004158 }
Jake Hambye994d462014-02-03 13:10:13 -08004159
Evan Charltonc66da362014-05-16 14:06:40 -07004160 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004161 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4162 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4164 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004165 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004166 if (DBG) {
4167 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4168 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4169 }
4170 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4171 cla, command, p1, p2, p3, data);
4172 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004173
Jordan Liu4c733742019-02-28 12:03:40 -08004174 @Override
4175 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4176 int command, int p1, int p2, int p3, String data) {
4177 enforceModifyPermission();
4178 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4179 if (DBG) {
4180 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4181 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4182 + " data=" + data);
4183 }
4184
4185 return iccTransmitApduBasicChannelWithPermission(
4186 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4187 p2, p3, data);
4188 }
4189
4190 // open APDU basic channel assuming the caller has sufficient permissions
4191 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4192 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193 final long identity = Binder.clearCallingIdentity();
4194 try {
4195 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4196 && TextUtils.equals(ISDR_AID, data)) {
4197 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004198 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4199 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004200 if (bestComponent == null
4201 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4202 loge("The calling package is not allowed to select ISD-R.");
4203 throw new SecurityException(
4204 "The calling package is not allowed to select ISD-R.");
4205 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004206 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004208 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004209 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4210 null /* workSource */);
4211 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213 // Append the returned status code to the end of the response payload.
4214 String s = Integer.toHexString(
4215 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4216 if (response.payload != null) {
4217 s = IccUtils.bytesToHexString(response.payload) + s;
4218 }
4219 return s;
4220 } finally {
4221 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004222 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004223 }
4224
4225 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004226 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004227 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4229 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004231 final long identity = Binder.clearCallingIdentity();
4232 try {
4233 if (DBG) {
4234 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4235 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4236 }
4237
4238 IccIoResult response =
4239 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4240 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4241 subId);
4242
4243 if (DBG) {
4244 log("Exchange SIM_IO [R]" + response);
4245 }
4246
4247 byte[] result = null;
4248 int length = 2;
4249 if (response.payload != null) {
4250 length = 2 + response.payload.length;
4251 result = new byte[length];
4252 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4253 } else {
4254 result = new byte[length];
4255 }
4256
4257 result[length - 1] = (byte) response.sw2;
4258 result[length - 2] = (byte) response.sw1;
4259 return result;
4260 } finally {
4261 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004262 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004263 }
4264
Nathan Haroldb3014052017-01-25 15:57:32 -08004265 /**
4266 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4267 * on a particular subscription
4268 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004269 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4270 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004272 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004273 return null;
4274 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275
4276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 if (appType != TelephonyManager.APPTYPE_USIM
4279 && appType != TelephonyManager.APPTYPE_SIM) {
4280 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4281 return null;
4282 }
4283 Object response = sendRequest(
4284 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4285 if (response instanceof String[]) {
4286 return (String[]) response;
4287 }
yincheng zhao2737e882019-09-06 17:06:54 -07004288 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004290 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004291 } finally {
4292 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004293 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004294 }
4295
yincheng zhao2737e882019-09-06 17:06:54 -07004296 /**
4297 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4298 * subscription.
4299 *
4300 * @param subId the id of the subscription.
4301 * @param appType the uicc app type, must be USIM or SIM.
4302 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4303 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004304 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004305 * @return number of fplmns that is successfully written to the SIM.
4306 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004307 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4308 String callingFeatureId) {
4309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4310 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004311 if (DBG) logv("no permissions for setForbiddenplmns");
4312 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4313 }
4314 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4315 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4316 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4317 }
4318 if (fplmns == null) {
4319 throw new IllegalArgumentException("Fplmn List provided is null");
4320 }
4321 for (String fplmn : fplmns) {
4322 if (!CellIdentity.isValidPlmn(fplmn)) {
4323 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4324 }
4325 }
4326 final long identity = Binder.clearCallingIdentity();
4327 try {
4328 Object response = sendRequest(
4329 CMD_SET_FORBIDDEN_PLMNS,
4330 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4331 subId);
4332 return (int) response;
4333 } finally {
4334 Binder.restoreCallingIdentity(identity);
4335 }
4336 }
4337
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004338 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004339 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4341 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343 final long identity = Binder.clearCallingIdentity();
4344 try {
4345 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4346 if (response.payload == null) {
4347 return "";
4348 }
Evan Charltonc66da362014-05-16 14:06:40 -07004349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350 // Append the returned status code to the end of the response payload.
4351 String s = Integer.toHexString(
4352 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4353 s = IccUtils.bytesToHexString(response.payload) + s;
4354 return s;
4355 } finally {
4356 Binder.restoreCallingIdentity(identity);
4357 }
Evan Charltonc66da362014-05-16 14:06:40 -07004358 }
4359
Jake Hambye994d462014-02-03 13:10:13 -08004360 /**
4361 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4362 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4363 *
4364 * @param itemID the ID of the item to read
4365 * @return the NV item as a String, or null on error.
4366 */
4367 @Override
4368 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004369 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4371 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004372
4373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004376 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004377 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4378 return value;
4379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
Jake Hambye994d462014-02-03 13:10:13 -08004382 }
4383
4384 /**
4385 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4386 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4387 *
4388 * @param itemID the ID of the item to read
4389 * @param itemValue the value to write, as a String
4390 * @return true on success; false on any failure
4391 */
4392 @Override
4393 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004394 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4396 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397
4398 final long identity = Binder.clearCallingIdentity();
4399 try {
4400 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4401 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004402 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4404 return success;
4405 } finally {
4406 Binder.restoreCallingIdentity(identity);
4407 }
Jake Hambye994d462014-02-03 13:10:13 -08004408 }
4409
4410 /**
4411 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4412 * Used for device configuration by some CDMA operators.
4413 *
4414 * @param preferredRoamingList byte array containing the new PRL
4415 * @return true on success; false on any failure
4416 */
4417 @Override
4418 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4420 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004421
4422 final long identity = Binder.clearCallingIdentity();
4423 try {
4424 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4425 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4426 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4427 return success;
4428 } finally {
4429 Binder.restoreCallingIdentity(identity);
4430 }
Jake Hambye994d462014-02-03 13:10:13 -08004431 }
4432
4433 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004434 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004435 * Used for device configuration by some CDMA operators.
4436 *
chen xu6dac5ab2018-10-26 17:39:23 -07004437 * @param slotIndex - device slot.
4438 *
Jake Hambye994d462014-02-03 13:10:13 -08004439 * @return true on success; false on any failure
4440 */
4441 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004442 public boolean resetModemConfig(int slotIndex) {
4443 Phone phone = PhoneFactory.getPhone(slotIndex);
4444 if (phone != null) {
4445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4446 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447
chen xu6dac5ab2018-10-26 17:39:23 -07004448 final long identity = Binder.clearCallingIdentity();
4449 try {
4450 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4451 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4452 return success;
4453 } finally {
4454 Binder.restoreCallingIdentity(identity);
4455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 }
chen xu6dac5ab2018-10-26 17:39:23 -07004457 return false;
4458 }
4459
4460 /**
4461 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4462 *
4463 * @param slotIndex - device slot.
4464 *
4465 * @return true on success; false on any failure
4466 */
4467 @Override
4468 public boolean rebootModem(int slotIndex) {
4469 Phone phone = PhoneFactory.getPhone(slotIndex);
4470 if (phone != null) {
4471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4472 mApp, phone.getSubId(), "rebootModem");
4473
4474 final long identity = Binder.clearCallingIdentity();
4475 try {
4476 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4477 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4478 return success;
4479 } finally {
4480 Binder.restoreCallingIdentity(identity);
4481 }
4482 }
4483 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004484 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004485
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004486 public String[] getPcscfAddress(String apnType, String callingPackage,
4487 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004488 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4490 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004491 return new String[0];
4492 }
4493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004494 final long identity = Binder.clearCallingIdentity();
4495 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004496 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004497 } finally {
4498 Binder.restoreCallingIdentity(identity);
4499 }
Wink Saville36469e72014-06-11 15:17:00 -07004500 }
4501
Brad Ebinger51f743a2017-01-23 13:50:20 -08004502 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004503 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4504 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004505 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004506 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004507 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508
4509 final long identity = Binder.clearCallingIdentity();
4510 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004511 ImsResolver resolver = PhoneFactory.getImsResolver();
4512 if (resolver == null) {
4513 // may happen if the device does not support IMS.
4514 return;
4515 }
4516 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004520 }
4521
4522 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004523 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4524 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004525 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004526 public void disableIms(int slotId) {
4527 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528
4529 final long identity = Binder.clearCallingIdentity();
4530 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004531 ImsResolver resolver = PhoneFactory.getImsResolver();
4532 if (resolver == null) {
4533 // may happen if the device does not support IMS.
4534 return;
4535 }
4536 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004537 } finally {
4538 Binder.restoreCallingIdentity(identity);
4539 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004540 }
4541
4542 /**
4543 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4544 * feature or {@link null} if the service is not available. If the feature is available, the
4545 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4546 */
4547 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004548 IImsServiceFeatureCallback callback) {
4549 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004550
4551 final long identity = Binder.clearCallingIdentity();
4552 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004553 ImsResolver resolver = PhoneFactory.getImsResolver();
4554 if (resolver == null) {
4555 // may happen if the device does not support IMS.
4556 return null;
4557 }
4558 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559 } finally {
4560 Binder.restoreCallingIdentity(identity);
4561 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004562 }
4563
4564 /**
4565 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4566 * feature during emergency calling or {@link null} if the service is not available. If the
4567 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4568 * listener for feature updates.
4569 */
4570 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572
4573 final long identity = Binder.clearCallingIdentity();
4574 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004575 ImsResolver resolver = PhoneFactory.getImsResolver();
4576 if (resolver == null) {
4577 // may happen if the device does not support IMS.
4578 return null;
4579 }
4580 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 } finally {
4582 Binder.restoreCallingIdentity(identity);
4583 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004584 }
4585
Brad Ebinger5f64b052017-12-14 14:26:15 -08004586 /**
4587 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004588 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004589 */
4590 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4591 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592
4593 final long identity = Binder.clearCallingIdentity();
4594 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004595 ImsResolver resolver = PhoneFactory.getImsResolver();
4596 if (resolver == null) {
4597 // may happen if the device does not support IMS.
4598 return null;
4599 }
4600 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601 } finally {
4602 Binder.restoreCallingIdentity(identity);
4603 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004604 }
4605
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004606 /**
4607 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004608 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004609 */
4610 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4611 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004612
4613 final long identity = Binder.clearCallingIdentity();
4614 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004615 ImsResolver resolver = PhoneFactory.getImsResolver();
4616 if (resolver == null) {
4617 // may happen if the device does not support IMS.
4618 return null;
4619 }
4620 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004621 } finally {
4622 Binder.restoreCallingIdentity(identity);
4623 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004624 }
4625
Brad Ebinger884c07b2018-02-15 16:17:40 -08004626 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004627 * Sets the ImsService Package Name that Telephony will bind to.
4628 *
4629 * @param slotId the slot ID that the ImsService should bind for.
4630 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4631 * ImsService is the device default ImsService.
4632 * @param packageName The package name of the application that contains the ImsService to bind
4633 * to.
4634 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4635 * @hide
4636 */
4637 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004638 int[] subIds = SubscriptionManager.getSubId(slotId);
4639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4640 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4641 "setImsService");
4642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004643 final long identity = Binder.clearCallingIdentity();
4644 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004645 ImsResolver resolver = PhoneFactory.getImsResolver();
4646 if (resolver == null) {
4647 // may happen if the device does not support IMS.
4648 return false;
4649 }
4650 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4651 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004652 } finally {
4653 Binder.restoreCallingIdentity(identity);
4654 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004655 }
4656
4657 /**
4658 * Return the ImsService configuration.
4659 *
4660 * @param slotId The slot that the ImsService is associated with.
4661 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4662 * the device default.
4663 * @return the package name of the ImsService configuration.
4664 */
4665 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004666 int[] subIds = SubscriptionManager.getSubId(slotId);
4667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4668 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4669 "getImsService");
4670
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004671 final long identity = Binder.clearCallingIdentity();
4672 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004673 ImsResolver resolver = PhoneFactory.getImsResolver();
4674 if (resolver == null) {
4675 // may happen if the device does not support IMS.
4676 return "";
4677 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004678 // TODO: change API to query RCS separately.
4679 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4680 ImsFeature.FEATURE_MMTEL);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681 } finally {
4682 Binder.restoreCallingIdentity(identity);
4683 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004684 }
4685
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004686 /**
4687 * Get the MmTelFeature state associated with the requested subscription id.
4688 * @param subId The subscription that the MmTelFeature is associated with.
4689 * @param callback A callback with an integer containing the
4690 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4691 */
4692 @Override
4693 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4694 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4695 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4696 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4697 "IMS not available on device.");
4698 }
4699 final long token = Binder.clearCallingIdentity();
4700 try {
4701 int slotId = getSlotIndex(subId);
4702 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4703 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4704 + subId + "'");
4705 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4706 }
4707 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4708 try {
4709 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4710 } catch (RemoteException e) {
4711 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4712 + "Ignore");
4713 }
4714 });
4715 } finally {
4716 Binder.restoreCallingIdentity(token);
4717 }
4718 }
4719
Wink Saville36469e72014-06-11 15:17:00 -07004720 public void setImsRegistrationState(boolean registered) {
4721 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004722
4723 final long identity = Binder.clearCallingIdentity();
4724 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004725 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004726 } finally {
4727 Binder.restoreCallingIdentity(identity);
4728 }
Wink Saville36469e72014-06-11 15:17:00 -07004729 }
4730
4731 /**
Stuart Scott54788802015-03-30 13:18:01 -07004732 * Set the network selection mode to automatic.
4733 *
4734 */
4735 @Override
4736 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4738 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004739
Pengquan Menge92a50d2018-09-21 15:54:48 -07004740 if (!isActiveSubscription(subId)) {
4741 return;
4742 }
4743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 final long identity = Binder.clearCallingIdentity();
4745 try {
4746 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4747 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4748 } finally {
4749 Binder.restoreCallingIdentity(identity);
4750 }
Stuart Scott54788802015-03-30 13:18:01 -07004751 }
4752
Pengquan Mengea84e042018-09-20 14:57:26 -07004753 /**
4754 * Ask the radio to connect to the input network and change selection mode to manual.
4755 *
4756 * @param subId the id of the subscription.
4757 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4758 * the operator to attach to.
4759 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4760 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4761 * normal network selection next time.
4762 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004763 */
4764 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004765 public boolean setNetworkSelectionModeManual(
4766 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4768 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004769
4770 if (!isActiveSubscription(subId)) {
4771 return false;
4772 }
4773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774 final long identity = Binder.clearCallingIdentity();
4775 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004776 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004777 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004778 if (DBG) {
4779 log("setNetworkSelectionModeManual: subId: " + subId
4780 + " operator: " + operatorInfo);
4781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004782 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4783 } finally {
4784 Binder.restoreCallingIdentity(identity);
4785 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004786 }
4787
4788 /**
4789 * Scans for available networks.
4790 */
4791 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004792 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4793 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4795 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004796 LocationAccessPolicy.LocationPermissionResult locationResult =
4797 LocationAccessPolicy.checkLocationPermission(mApp,
4798 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4799 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004800 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004801 .setCallingPid(Binder.getCallingPid())
4802 .setCallingUid(Binder.getCallingUid())
4803 .setMethod("getCellNetworkScanResults")
4804 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4805 .build());
4806 switch (locationResult) {
4807 case DENIED_HARD:
4808 throw new SecurityException("Not allowed to access scan results -- location");
4809 case DENIED_SOFT:
4810 return null;
4811 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004812
Pengquan Menga1bb6272018-09-06 09:59:22 -07004813 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004814 try {
4815 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004816 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818 } finally {
4819 Binder.restoreCallingIdentity(identity);
4820 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004821 }
4822
4823 /**
yinxub1bed742017-04-17 11:45:04 -07004824 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004825 *
yinxub1bed742017-04-17 11:45:04 -07004826 * @param subId id of the subscription
4827 * @param request contains the radio access networks with bands/channels to scan
4828 * @param messenger callback messenger for scan results or errors
4829 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004830 * @return the id of the requested scan which can be used to stop the scan.
4831 */
4832 @Override
4833 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004834 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4836 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004837 LocationAccessPolicy.LocationPermissionResult locationResult =
4838 LocationAccessPolicy.checkLocationPermission(mApp,
4839 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4840 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004841 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004842 .setCallingPid(Binder.getCallingPid())
4843 .setCallingUid(Binder.getCallingUid())
4844 .setMethod("requestNetworkScan")
4845 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4846 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004847 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004848 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004849 if (e != null) {
4850 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4851 throw e;
4852 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004853 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004854 return TelephonyScanManager.INVALID_SCAN_ID;
4855 }
4856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004857 }
Hall Liu912dfd32019-04-25 14:02:26 -07004858 int callingUid = Binder.getCallingUid();
4859 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004860 final long identity = Binder.clearCallingIdentity();
4861 try {
4862 return mNetworkScanRequestTracker.startNetworkScan(
4863 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004864 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004865 } finally {
4866 Binder.restoreCallingIdentity(identity);
4867 }
yinxu504e1392017-04-12 16:03:22 -07004868 }
4869
Hall Liub2ac8ef2019-02-28 15:56:23 -08004870 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004871 NetworkScanRequest request, int subId) {
4872 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4873 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4874 boolean hasNetworkScanPermission =
4875 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4876 == PERMISSION_GRANTED;
4877
4878 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4879 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4880 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004881 }
4882
4883 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4884 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004885 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4886 return new SecurityException("Specific channels must not be"
4887 + " scanned without location access.");
4888 }
4889 }
4890 }
4891
Hall Liub2ac8ef2019-02-28 15:56:23 -08004892 return null;
4893 }
4894
yinxu504e1392017-04-12 16:03:22 -07004895 /**
4896 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004897 *
4898 * @param subId id of the subscription
4899 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004900 */
4901 @Override
4902 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4904 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004905
Hall Liu912dfd32019-04-25 14:02:26 -07004906 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907 final long identity = Binder.clearCallingIdentity();
4908 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004909 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 } finally {
4911 Binder.restoreCallingIdentity(identity);
4912 }
yinxu504e1392017-04-12 16:03:22 -07004913 }
4914
4915 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004916 * Get the calculated preferred network type.
4917 * Used for debugging incorrect network type.
4918 *
4919 * @return the preferred network type, defined in RILConstants.java.
4920 */
4921 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004922 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004923 final Phone defaultPhone = getDefaultPhone();
4924 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004925 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004926 return RILConstants.PREFERRED_NETWORK_MODE;
4927 }
4928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004929 final long identity = Binder.clearCallingIdentity();
4930 try {
4931 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004932 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
Junda Liu84d15a22014-07-02 11:21:04 -07004936 }
4937
4938 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004939 * Get the preferred network type.
4940 * Used for device configuration by some CDMA operators.
4941 *
4942 * @return the preferred network type, defined in RILConstants.java.
4943 */
4944 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004945 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004946 TelephonyPermissions
4947 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4948 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949
4950 final long identity = Binder.clearCallingIdentity();
4951 try {
4952 if (DBG) log("getPreferredNetworkType");
4953 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4954 int networkType = (result != null ? result[0] : -1);
4955 if (DBG) log("getPreferredNetworkType: " + networkType);
4956 return networkType;
4957 } finally {
4958 Binder.restoreCallingIdentity(identity);
4959 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004960 }
4961
4962 /**
4963 * Set the preferred network type.
4964 * Used for device configuration by some CDMA operators.
4965 *
4966 * @param networkType the preferred network type, defined in RILConstants.java.
4967 * @return true on success; false on any failure.
4968 */
4969 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004970 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4972 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973
4974 final long identity = Binder.clearCallingIdentity();
4975 try {
4976 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4977 Boolean success = (Boolean) sendRequest(
4978 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4979 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4980 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004981 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4983 }
4984 return success;
4985 } finally {
4986 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004987 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004988 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004989
4990 /**
Miaoa84611c2019-03-15 09:21:10 +08004991 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004992 *
Miaoa84611c2019-03-15 09:21:10 +08004993 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004994 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004995 * @hide
4996 */
4997 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004998 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004999 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005001 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002 try {
Miaoa84611c2019-03-15 09:21:10 +08005003 if (phone != null) {
5004 return phone.hasMatchedTetherApnSetting();
5005 } else {
5006 return false;
5007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008 } finally {
5009 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005010 }
Junda Liu475951f2014-11-07 16:45:03 -08005011 }
5012
5013 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005014 * Set mobile data enabled
5015 * Used by the user through settings etc to turn on/off mobile data
5016 *
5017 * @param enable {@code true} turn turn data on, else {@code false}
5018 */
5019 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005020 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5022 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023
5024 final long identity = Binder.clearCallingIdentity();
5025 try {
5026 int phoneId = mSubscriptionController.getPhoneId(subId);
5027 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5028 Phone phone = PhoneFactory.getPhone(phoneId);
5029 if (phone != null) {
5030 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005031 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005032 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005033 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005034 }
5035 } finally {
5036 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005037 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005038 }
5039
5040 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005041 * Get the user enabled state of Mobile Data.
5042 *
5043 * TODO: remove and use isUserDataEnabled.
5044 * This can't be removed now because some vendor codes
5045 * calls through ITelephony directly while they should
5046 * use TelephonyManager.
5047 *
5048 * @return true on enabled
5049 */
5050 @Override
5051 public boolean getDataEnabled(int subId) {
5052 return isUserDataEnabled(subId);
5053 }
5054
5055 /**
5056 * Get whether mobile data is enabled per user setting.
5057 *
5058 * There are other factors deciding whether mobile data is actually enabled, but they are
5059 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005060 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005061 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005062 *
5063 * @return {@code true} if data is enabled else {@code false}
5064 */
5065 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005066 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005067 try {
5068 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5069 null);
5070 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5072 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074
5075 final long identity = Binder.clearCallingIdentity();
5076 try {
5077 int phoneId = mSubscriptionController.getPhoneId(subId);
5078 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5079 Phone phone = PhoneFactory.getPhone(phoneId);
5080 if (phone != null) {
5081 boolean retVal = phone.isUserDataEnabled();
5082 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5083 return retVal;
5084 } else {
5085 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5086 return false;
5087 }
5088 } finally {
5089 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005090 }
5091 }
5092
5093 /**
5094 * Get whether mobile data is enabled.
5095 *
5096 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5097 * whether mobile data is actually enabled.
5098 *
5099 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5100 *
5101 * @return {@code true} if data is enabled else {@code false}
5102 */
5103 @Override
5104 public boolean isDataEnabled(int subId) {
5105 try {
5106 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5107 null);
5108 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5110 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005111 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112
5113 final long identity = Binder.clearCallingIdentity();
5114 try {
5115 int phoneId = mSubscriptionController.getPhoneId(subId);
5116 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5117 Phone phone = PhoneFactory.getPhone(phoneId);
5118 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005119 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005120 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5121 return retVal;
5122 } else {
5123 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5124 return false;
5125 }
5126 } finally {
5127 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005128 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005129 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005130
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005131 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5132 Phone phone) {
5133 //load access rules from carrier configs, and check those as well: b/139133814
5134 SubscriptionController subController = SubscriptionController.getInstance();
5135 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5136 || subController == null) return privilegeFromSim;
5137
5138 int uid = Binder.getCallingUid();
5139 PackageManager pkgMgr = phone.getContext().getPackageManager();
5140 String[] packages = pkgMgr.getPackagesForUid(uid);
5141
5142 final long identity = Binder.clearCallingIdentity();
5143 try {
5144 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5145 SubscriptionManager subManager = (SubscriptionManager)
5146 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5147 for (String pkg : packages) {
5148 if (subManager.canManageSubscription(subInfo, pkg)) {
5149 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5150 }
5151 }
5152 return privilegeFromSim;
5153 } finally {
5154 Binder.restoreCallingIdentity(identity);
5155 }
5156 }
5157
5158 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5159 String pkgName) {
5160 //load access rules from carrier configs, and check those as well: b/139133814
5161 SubscriptionController subController = SubscriptionController.getInstance();
5162 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5163 || subController == null) return privilegeFromSim;
5164
5165 final long identity = Binder.clearCallingIdentity();
5166 try {
5167 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5168 SubscriptionManager subManager = (SubscriptionManager)
5169 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5170 return subManager.canManageSubscription(subInfo, pkgName)
5171 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5172 } finally {
5173 Binder.restoreCallingIdentity(identity);
5174 }
5175 }
5176
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005177 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005178 public int getCarrierPrivilegeStatus(int subId) {
5179 final Phone phone = getPhone(subId);
5180 if (phone == null) {
5181 loge("getCarrierPrivilegeStatus: Invalid subId");
5182 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5183 }
5184 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005185 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005186 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005187 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5188 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005189
5190 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5191 card.getCarrierPrivilegeStatusForCurrentTransaction(
5192 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005193 }
Junda Liu29340342014-07-10 15:23:27 -07005194
5195 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005196 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005197 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005198 final Phone phone = getPhone(subId);
5199 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005200 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005201 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5202 }
5203 UiccProfile profile =
5204 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5205 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005206 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005207 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5208 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005209 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005210 profile.getCarrierPrivilegeStatusForUid(
5211 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005212 }
5213
5214 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005215 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5216 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005217 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005218 }
5219
5220 int phoneId = SubscriptionManager.getPhoneId(subId);
5221 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005222 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005223 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005224 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5225 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005226 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5227 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5228 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005229 }
5230
5231 @Override
5232 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005233 if (TextUtils.isEmpty(pkgName))
5234 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005235 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5236 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5237 UiccCard card = UiccController.getInstance().getUiccCard(i);
5238 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005239 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005240 continue;
5241 }
5242
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005243 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5244 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5245 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005246 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5247 break;
5248 }
5249 }
5250
5251 return result;
Junda Liu29340342014-07-10 15:23:27 -07005252 }
Derek Tan89e89d42014-07-08 17:00:10 -07005253
5254 @Override
Junda Liue64de782015-04-16 17:19:16 -07005255 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5256 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5257 loge("phoneId " + phoneId + " is not valid.");
5258 return null;
5259 }
5260 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005261 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005262 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005263 return null ;
5264 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005265 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005266 }
5267
Amith Yamasani6e118872016-02-19 12:53:51 -08005268 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005269 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005270 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005271 List<String> privilegedPackages = new ArrayList<>();
5272 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005273 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5274 // has UICC in that slot.
5275 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005276 if (card.hasCarrierPrivilegeRules()) {
5277 if (packages == null) {
5278 // Only check packages in user 0 for now
5279 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005280 PackageManager.MATCH_DISABLED_COMPONENTS
5281 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005282 | PackageManager.GET_SIGNING_CERTIFICATES,
5283 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005284 }
5285 for (int p = packages.size() - 1; p >= 0; p--) {
5286 PackageInfo pkgInfo = packages.get(p);
5287 if (pkgInfo != null && pkgInfo.packageName != null
5288 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005289 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005290 privilegedPackages.add(pkgInfo.packageName);
5291 }
5292 }
5293 }
5294 }
5295 return privilegedPackages;
5296 }
5297
chen xuf7e9fe82019-05-09 19:31:02 -07005298 @Override
5299 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005300 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5301
5302 final long identity = Binder.clearCallingIdentity();
5303
chen xuf7e9fe82019-05-09 19:31:02 -07005304 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005305 try {
5306 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5307 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5308 }
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005311 }
5312 return privilegedPackages;
5313 }
5314
Wink Savilleb564aae2014-10-23 10:18:09 -07005315 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005316 final Phone phone = getPhone(subId);
5317 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005318 if (card == null) {
5319 loge("getIccId: No UICC");
5320 return null;
5321 }
5322 String iccId = card.getIccId();
5323 if (TextUtils.isEmpty(iccId)) {
5324 loge("getIccId: ICC ID is null or empty.");
5325 return null;
5326 }
5327 return iccId;
5328 }
5329
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005330 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005331 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5332 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005333 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005334 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 final long identity = Binder.clearCallingIdentity();
5337 try {
5338 final String iccId = getIccId(subId);
5339 final Phone phone = getPhone(subId);
5340 if (phone == null) {
5341 return false;
5342 }
5343 final String subscriberId = phone.getSubscriberId();
5344
5345 if (DBG_MERGE) {
5346 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5347 + subscriberId + " to " + number);
5348 }
5349
5350 if (TextUtils.isEmpty(iccId)) {
5351 return false;
5352 }
5353
5354 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5355
5356 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5357 if (alphaTag == null) {
5358 editor.remove(alphaTagPrefKey);
5359 } else {
5360 editor.putString(alphaTagPrefKey, alphaTag);
5361 }
5362
5363 // Record both the line number and IMSI for this ICCID, since we need to
5364 // track all merged IMSIs based on line number
5365 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5366 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5367 if (number == null) {
5368 editor.remove(numberPrefKey);
5369 editor.remove(subscriberPrefKey);
5370 } else {
5371 editor.putString(numberPrefKey, number);
5372 editor.putString(subscriberPrefKey, subscriberId);
5373 }
5374
5375 editor.commit();
5376 return true;
5377 } finally {
5378 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005379 }
Derek Tan7226c842014-07-02 17:42:23 -07005380 }
5381
5382 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005383 public String getLine1NumberForDisplay(int subId, String callingPackage,
5384 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005385 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005387 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005388 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005389 return null;
5390 }
Derek Tan97ebb422014-09-05 16:55:38 -07005391
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005392 final long identity = Binder.clearCallingIdentity();
5393 try {
5394 String iccId = getIccId(subId);
5395 if (iccId != null) {
5396 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5397 if (DBG_MERGE) {
5398 log("getLine1NumberForDisplay returning "
5399 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5400 }
5401 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005402 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5404 return null;
5405 } finally {
5406 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005407 }
Derek Tan7226c842014-07-02 17:42:23 -07005408 }
5409
5410 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005411 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5412 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005413 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005414 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005415 return null;
5416 }
Derek Tan97ebb422014-09-05 16:55:38 -07005417
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 final long identity = Binder.clearCallingIdentity();
5419 try {
5420 String iccId = getIccId(subId);
5421 if (iccId != null) {
5422 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5423 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5424 }
5425 return null;
5426 } finally {
5427 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005428 }
Derek Tan7226c842014-07-02 17:42:23 -07005429 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005430
5431 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005432 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5433 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005434 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5435 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005436 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005437 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005438 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005439 return null;
5440 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005441
Jordan Liub49b04b2019-05-06 14:45:15 -07005442 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5443 // the process, where TelephonyManager was instantiated.
5444 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005445 final long identity = Binder.clearCallingIdentity();
5446 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005447 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 final TelephonyManager tele = TelephonyManager.from(context);
5449 final SubscriptionManager sub = SubscriptionManager.from(context);
5450
5451 // Figure out what subscribers are currently active
5452 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005453
Jordan Liub49b04b2019-05-06 14:45:15 -07005454 // Only consider subs which match the current subId
5455 // This logic can be simplified. See b/131189269 for progress.
5456 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005457 activeSubscriberIds.add(tele.getSubscriberId(subId));
5458 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459
5460 // First pass, find a number override for an active subscriber
5461 String mergeNumber = null;
5462 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5463 for (String key : prefs.keySet()) {
5464 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5465 final String subscriberId = (String) prefs.get(key);
5466 if (activeSubscriberIds.contains(subscriberId)) {
5467 final String iccId = key.substring(
5468 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5469 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5470 mergeNumber = (String) prefs.get(numberKey);
5471 if (DBG_MERGE) {
5472 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5473 + " for active subscriber " + subscriberId);
5474 }
5475 if (!TextUtils.isEmpty(mergeNumber)) {
5476 break;
5477 }
5478 }
5479 }
5480 }
5481
5482 // Shortcut when no active merged subscribers
5483 if (TextUtils.isEmpty(mergeNumber)) {
5484 return null;
5485 }
5486
5487 // Second pass, find all subscribers under that line override
5488 final ArraySet<String> result = new ArraySet<>();
5489 for (String key : prefs.keySet()) {
5490 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5491 final String number = (String) prefs.get(key);
5492 if (mergeNumber.equals(number)) {
5493 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5494 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5495 final String subscriberId = (String) prefs.get(subscriberKey);
5496 if (!TextUtils.isEmpty(subscriberId)) {
5497 result.add(subscriberId);
5498 }
5499 }
5500 }
5501 }
5502
5503 final String[] resultArray = result.toArray(new String[result.size()]);
5504 Arrays.sort(resultArray);
5505 if (DBG_MERGE) {
5506 Slog.d(LOG_TAG,
5507 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5508 }
5509 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005510 } finally {
5511 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005512 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005513 }
5514
5515 @Override
zoey chen38003472019-12-13 17:16:31 +08005516 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5517 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005518
5519 final long identity = Binder.clearCallingIdentity();
5520 try {
5521 final TelephonyManager telephonyManager = mApp.getSystemService(
5522 TelephonyManager.class);
5523 String subscriberId = telephonyManager.getSubscriberId(subId);
5524 if (subscriberId == null) {
5525 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005526 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005527 + subId);
5528 }
5529 return null;
5530 }
5531
5532 final SubscriptionInfo info = SubscriptionController.getInstance()
5533 .getSubscriptionInfo(subId);
5534 final ParcelUuid groupUuid = info.getGroupUuid();
5535 // If it doesn't belong to any group, return just subscriberId of itself.
5536 if (groupUuid == null) {
5537 return new String[]{subscriberId};
5538 }
5539
5540 // Get all subscriberIds from the group.
5541 final List<String> mergedSubscriberIds = new ArrayList<>();
5542 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005543 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5544 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005545 for (SubscriptionInfo subInfo : groupInfos) {
5546 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5547 if (subscriberId != null) {
5548 mergedSubscriberIds.add(subscriberId);
5549 }
5550 }
5551
5552 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5553 } finally {
5554 Binder.restoreCallingIdentity(identity);
5555
5556 }
5557 }
5558
5559 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005560 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005561 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005562 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005563
5564 final long identity = Binder.clearCallingIdentity();
5565 try {
5566 final Phone phone = getPhone(subId);
5567 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005571 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005572
5573 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005574 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005575 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5576 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005577 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5578 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579
5580 final long identity = Binder.clearCallingIdentity();
5581 try {
5582 final Phone phone = getPhone(subId);
5583 if (phone == null) {
5584 return false;
5585 }
5586 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5587 cdmaNonRoamingList);
5588 } finally {
5589 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005590 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005591 }
5592
5593 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005594 @Deprecated
5595 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5596 enforceModifyPermission();
5597
5598 int returnValue = 0;
5599 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005600 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005601 if(result.exception == null) {
5602 if (result.result != null) {
5603 byte[] responseData = (byte[])(result.result);
5604 if(responseData.length > oemResp.length) {
5605 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5606 responseData.length + "bytes. Buffer Size is " +
5607 oemResp.length + "bytes.");
5608 }
5609 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5610 returnValue = responseData.length;
5611 }
5612 } else {
5613 CommandException ex = (CommandException) result.exception;
5614 returnValue = ex.getCommandError().ordinal();
5615 if(returnValue > 0) returnValue *= -1;
5616 }
5617 } catch (RuntimeException e) {
5618 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5619 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5620 if(returnValue > 0) returnValue *= -1;
5621 }
5622
5623 return returnValue;
5624 }
5625
5626 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005627 public void setRadioCapability(RadioAccessFamily[] rafs) {
5628 try {
5629 ProxyController.getInstance().setRadioCapability(rafs);
5630 } catch (RuntimeException e) {
5631 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5632 }
5633 }
5634
5635 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005636 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005637 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005638 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005639 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005640 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 final long identity = Binder.clearCallingIdentity();
5643 try {
chen xub97461a2018-10-26 14:17:57 -07005644 TelephonyPermissions
5645 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5646 mApp, phone.getSubId(), "getRadioAccessFamily");
5647 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 } finally {
5649 Binder.restoreCallingIdentity(identity);
5650 }
chen xub97461a2018-10-26 14:17:57 -07005651 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005652 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005653
5654 @Override
5655 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005656 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005657 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658
5659 final long identity = Binder.clearCallingIdentity();
5660 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005661 ImsManager.getInstance(defaultPhone.getContext(),
5662 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 } finally {
5664 Binder.restoreCallingIdentity(identity);
5665 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005666 }
5667
5668 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005669 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005670 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005671 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5672 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005673 return false;
5674 }
Svet Ganovb320e182015-04-16 12:30:10 -07005675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 final long identity = Binder.clearCallingIdentity();
5677 try {
5678 // Check the user preference and the system-level IMS setting. Even if the user has
5679 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5680 // In the long run, we may instead need to check if there exists a connection service
5681 // which can support video calling.
5682 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005683 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 return imsManager.isVtEnabledByPlatform()
5685 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5686 && imsManager.isVtEnabledByUser();
5687 } finally {
5688 Binder.restoreCallingIdentity(identity);
5689 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005690 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005691
Andrew Leea1239f22015-03-02 17:44:07 -08005692 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005693 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5694 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005696 mApp, subId, callingPackage, callingFeatureId,
5697 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 return false;
5699 }
5700
5701 final long identity = Binder.clearCallingIdentity();
5702 try {
5703 CarrierConfigManager configManager =
5704 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005705 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5707 } finally {
5708 Binder.restoreCallingIdentity(identity);
5709 }
Andrew Leea1239f22015-03-02 17:44:07 -08005710 }
5711
5712 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005713 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005715 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 return false;
5717 }
5718
5719 final long identity = Binder.clearCallingIdentity();
5720 try {
5721 CarrierConfigManager configManager =
5722 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005723 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5725 } finally {
5726 Binder.restoreCallingIdentity(identity);
5727 }
Andrew Leea1239f22015-03-02 17:44:07 -08005728 }
5729
Andrew Lee9431b832015-03-09 18:46:45 -07005730 @Override
5731 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005732 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005733 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005734 }
5735
5736 @Override
5737 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 final long identity = Binder.clearCallingIdentity();
5739 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005740 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741 } finally {
5742 Binder.restoreCallingIdentity(identity);
5743 }
Andrew Lee9431b832015-03-09 18:46:45 -07005744 }
5745
Hall Liuf6668912018-10-31 17:05:23 -07005746 /**
5747 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5748 * support for the feature and device firmware support.
5749 *
5750 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5751 */
5752 @Override
5753 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005755 final Phone phone = getPhone(subscriptionId);
5756 if (phone == null) {
5757 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5758 return false;
5759 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005761 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5763 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005764 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 return isCarrierSupported && isDeviceSupported;
5766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
Hall Liu98187582018-01-22 19:15:32 -08005769 }
5770
Hall Liuf6668912018-10-31 17:05:23 -07005771 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005772 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5773 * RTT setting, will return true if the device and carrier both support RTT.
5774 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005775 */
5776 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777 final long identity = Binder.clearCallingIdentity();
5778 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00005779 boolean isRttSupported = isRttSupported(subscriptionId);
5780 boolean isUserRttSettingOn = Settings.Secure.getInt(
5781 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5782 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5783 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5784 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 } finally {
5786 Binder.restoreCallingIdentity(identity);
5787 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005788 }
5789
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005790 @Deprecated
5791 @Override
5792 public String getDeviceId(String callingPackage) {
5793 return getDeviceIdWithFeature(callingPackage, null);
5794 }
5795
Sanket Padawe7310cc72015-01-14 09:53:20 -08005796 /**
5797 * Returns the unique device ID of phone, for example, the IMEI for
5798 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5799 *
5800 * <p>Requires Permission:
5801 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5802 */
5803 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005804 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005805 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005806 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005807 return null;
5808 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005809 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005810 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005811 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005812 return null;
5813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814
5815 final long identity = Binder.clearCallingIdentity();
5816 try {
5817 return phone.getDeviceId();
5818 } finally {
5819 Binder.restoreCallingIdentity(identity);
5820 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005821 }
5822
Ping Sunc67b7c22016-03-02 19:16:45 +08005823 /**
5824 * {@hide}
5825 * Returns the IMS Registration Status on a particular subid
5826 *
5827 * @param subId
5828 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005829 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005830 Phone phone = getPhone(subId);
5831 if (phone != null) {
5832 return phone.isImsRegistered();
5833 } else {
5834 return false;
5835 }
5836 }
5837
Santos Cordon7a1885b2015-02-03 11:15:19 -08005838 @Override
5839 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005840 final long identity = Binder.clearCallingIdentity();
5841 try {
5842 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5843 } finally {
5844 Binder.restoreCallingIdentity(identity);
5845 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005846 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005847
Tyler Gunnf70ed162019-04-03 15:28:53 -07005848 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005849 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005850 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005851 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005852 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005853 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5854 }
5855 final long identity = Binder.clearCallingIdentity();
5856 try {
5857 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5858 } finally {
5859 Binder.restoreCallingIdentity(identity);
5860 }
5861 }
5862
5863 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005864 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5865 final long identity = Binder.clearCallingIdentity();
5866 try {
5867 Phone phone = getPhone(subscriptionId);
5868 if (phone == null) {
5869 return null;
5870 }
5871 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5872 } finally {
5873 Binder.restoreCallingIdentity(identity);
5874 }
5875 }
5876
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005877 /**
5878 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005879 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005880 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881 final long identity = Binder.clearCallingIdentity();
5882 try {
5883 Phone phone = getPhone(subId);
5884 if (phone != null) {
5885 return phone.isWifiCallingEnabled();
5886 } else {
5887 return false;
5888 }
5889 } finally {
5890 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005891 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005892 }
5893
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005894 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005895 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005896 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005897 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005898 final long identity = Binder.clearCallingIdentity();
5899 try {
5900 Phone phone = getPhone(subId);
5901 if (phone != null) {
5902 return phone.isVideoEnabled();
5903 } else {
5904 return false;
5905 }
5906 } finally {
5907 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005908 }
5909 }
5910
5911 /**
5912 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5913 * defined in {@link ImsRegistrationImplBase}.
5914 */
5915 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916 final long identity = Binder.clearCallingIdentity();
5917 try {
5918 Phone phone = getPhone(subId);
5919 if (phone != null) {
5920 return phone.getImsRegistrationTech();
5921 } else {
5922 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5923 }
5924 } finally {
5925 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005926 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005927 }
5928
Stuart Scott8eef64f2015-04-08 15:13:54 -07005929 @Override
5930 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08005931 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005932 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5933 return;
5934 }
5935
Svet Ganovcc087f82015-05-12 20:35:54 -07005936 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005937
Svet Ganovcc087f82015-05-12 20:35:54 -07005938 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005939 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5940 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005941 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005942 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005943 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005944 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5945 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005946 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005947 // There has been issues when Sms raw table somehow stores orphan
5948 // fragments. They lead to garbled message when new fragments come
5949 // in and combined with those stale ones. In case this happens again,
5950 // user can reset all network settings which will clean up this table.
5951 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005952 // Clean up IMS settings as well here.
5953 int slotId = getSlotIndex(subId);
5954 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5955 ImsManager.getInstance(mApp, slotId).factoryReset();
5956 }
Naina Nallurid63128d2019-09-17 14:10:30 -07005957
5958 // Erase modem config if erase modem on network setting is enabled.
5959 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5960 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5961 if (configValue != null && Boolean.parseBoolean(configValue)) {
5962 sendEraseModemConfig(getDefaultPhone());
5963 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005964 } finally {
5965 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005966 }
5967 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005968
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005969 private void cleanUpSmsRawTable(Context context) {
5970 ContentResolver resolver = context.getContentResolver();
5971 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5972 resolver.delete(uri, null, null);
5973 }
5974
Narayan Kamath1c496c22015-04-16 14:40:19 +01005975 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005976 public String getSimLocaleForSubscriber(int subId) {
5977 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5978 final Phone phone = getPhone(subId);
5979 if (phone == null) {
5980 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005981 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983 final long identity = Binder.clearCallingIdentity();
5984 try {
chen xu5d3637b2019-01-21 23:31:38 -08005985 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005986 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08005987 if (info == null) {
5988 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5989 return null;
5990 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 // Try and fetch the locale from the carrier properties or from the SIM language
5992 // preferences (EF-PL and EF-LI)...
5993 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005995 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5996 if (localeFromDefaultSim != null) {
5997 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5998 if (DBG) log("Using locale from subId: " + subId + " locale: "
5999 + localeFromDefaultSim);
6000 return localeFromDefaultSim.toLanguageTag();
6001 } else {
6002 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 }
6004 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006005
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 // The SIM language preferences only store a language (e.g. fr = French), not an
6007 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6008 // the SIM and carrier preferences does not include a country we add the country
6009 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006010 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006012 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 return mccLocale.toLanguageTag();
6014 }
6015
6016 if (DBG) log("No locale found - returning null");
6017 return null;
6018 } finally {
6019 Binder.restoreCallingIdentity(identity);
6020 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006021 }
6022
6023 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006024 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6025 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006026 }
6027
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028 /**
6029 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6030 */
6031 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006032 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6033 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006034 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006035
Chenjie Yu1ba97252018-01-11 18:16:20 -08006036 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006037 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006038
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006039 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006040 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6041 * representing the state of the modem.
6042 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006043 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6044 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006045 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006046 */
6047 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006048 public void requestModemActivityInfo(ResultReceiver result) {
6049 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006050 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051
6052 final long identity = Binder.clearCallingIdentity();
6053 try {
6054 ModemActivityInfo ret = null;
6055 synchronized (mLastModemActivityInfo) {
6056 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6057 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006058 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006059 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006061 int[] txTimeMs = info.getTransmitTimeMillis();
6062 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006064 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 }
6066 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006067 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6068 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069 mLastModemActivityInfo.setIdleTimeMillis(
6070 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006071 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6072 mLastModemActivityInfo.setReceiveTimeMillis(
6073 info.getReceiveTimeMillis() + mLastModemActivityInfo
6074 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006075 }
Chen Xud78231e2019-09-10 18:49:52 -07006076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6078 mLastModemActivityInfo.getSleepTimeMillis(),
6079 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006080 mLastModemActivityInfo.getTransmitTimeMillis(),
6081 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006082 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083 Bundle bundle = new Bundle();
6084 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6085 result.send(0, bundle);
6086 } finally {
6087 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006088 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006089 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006090
Siddharth Rayb8114062018-06-17 15:02:38 -07006091 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6092 // less than total activity duration.
6093 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6094 if (info == null) {
6095 return false;
6096 }
6097 int activityDurationMs =
6098 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6099 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006100 int[] txTimeMs = info.getTransmitTimeMillis();
6101 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6102 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006103 }
6104 return (info.isValid()
6105 && (info.getSleepTimeMillis() <= activityDurationMs)
6106 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006107 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006108 && (totalTxTimeMs <= activityDurationMs));
6109 }
6110
Jack Yu85bd38a2015-11-09 11:34:32 -08006111 /**
6112 * {@hide}
6113 * Returns the service state information on specified subscription.
6114 */
6115 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006116 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6117 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006119 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006120 return null;
6121 }
6122
Hall Liuf19c44f2018-11-27 14:38:17 -08006123 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6124 LocationAccessPolicy.checkLocationPermission(mApp,
6125 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6126 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006127 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006128 .setCallingPid(Binder.getCallingPid())
6129 .setCallingUid(Binder.getCallingUid())
6130 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006131 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006132 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6133 .build());
6134
6135 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6136 LocationAccessPolicy.checkLocationPermission(mApp,
6137 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6138 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006139 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006140 .setCallingPid(Binder.getCallingPid())
6141 .setCallingUid(Binder.getCallingUid())
6142 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006143 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006144 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6145 .build());
6146 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6147 boolean hasFinePermission =
6148 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6149 boolean hasCoarsePermission =
6150 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6151
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006152 final long identity = Binder.clearCallingIdentity();
6153 try {
6154 final Phone phone = getPhone(subId);
6155 if (phone == null) {
6156 return null;
6157 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006158
Hall Liuf19c44f2018-11-27 14:38:17 -08006159 ServiceState ss = phone.getServiceState();
6160
6161 // Scrub out the location info in ServiceState depending on what level of access
6162 // the caller has.
6163 if (hasFinePermission) return ss;
6164 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6165 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 } finally {
6167 Binder.restoreCallingIdentity(identity);
6168 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006169 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006170
6171 /**
6172 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6173 *
6174 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6175 * voicemail ringtone.
6176 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6177 * PhoneAccount.
6178 */
6179 @Override
6180 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006181 final long identity = Binder.clearCallingIdentity();
6182 try {
6183 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6184 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006185 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006186 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6189 } finally {
6190 Binder.restoreCallingIdentity(identity);
6191 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006192 }
6193
6194 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006195 * Sets the per-account voicemail ringtone.
6196 *
6197 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6198 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6199 *
6200 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6201 * voicemail ringtone.
6202 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6203 * PhoneAccount.
6204 */
6205 @Override
6206 public void setVoicemailRingtoneUri(String callingPackage,
6207 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006208 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006209 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006210 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6211 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6213 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6214 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006215 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006216
6217 final long identity = Binder.clearCallingIdentity();
6218 try {
6219 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6220 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006221 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006222 }
6223 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6224 } finally {
6225 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006226 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006227 }
6228
6229 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006230 * Returns whether vibration is set for voicemail notification in Phone settings.
6231 *
6232 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6233 * voicemail vibration setting.
6234 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6235 */
6236 @Override
6237 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 final long identity = Binder.clearCallingIdentity();
6239 try {
6240 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6241 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006242 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006243 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006245 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6246 } finally {
6247 Binder.restoreCallingIdentity(identity);
6248 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006249 }
6250
Youhan Wange64578a2016-05-02 15:32:42 -07006251 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006252 * Sets the per-account voicemail vibration.
6253 *
6254 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6255 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6256 *
6257 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6258 * voicemail vibration setting.
6259 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6260 * specific PhoneAccount.
6261 */
6262 @Override
6263 public void setVoicemailVibrationEnabled(String callingPackage,
6264 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006265 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006266 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006267 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6268 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6270 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6271 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006272 }
6273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006274 final long identity = Binder.clearCallingIdentity();
6275 try {
6276 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6277 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006278 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006279 }
6280 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6281 } finally {
6282 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006283 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006284 }
6285
6286 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006287 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6288 *
6289 * @throws SecurityException if the caller does not have the required permission
6290 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006291 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006292 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006293 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006294 }
6295
6296 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006297 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6298 * permission.
6299 *
6300 * @throws SecurityException if the caller does not have the required permission
6301 */
6302 private void enforceSendSmsPermission() {
6303 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6304 }
6305
6306 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006307 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006308 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006309 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006310 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006311 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006312 final long identity = Binder.clearCallingIdentity();
6313 try {
6314 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006315 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 if (componentName == null) {
6317 throw new SecurityException(
6318 "Caller not current active visual voicemail package[null]");
6319 }
6320 String vvmPackage = componentName.getPackageName();
6321 if (!callingPackage.equals(vvmPackage)) {
6322 throw new SecurityException("Caller not current active visual voicemail package["
6323 + vvmPackage + "]");
6324 }
6325 } finally {
6326 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006327 }
6328 }
6329
6330 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006331 * Return the application ID for the app type.
6332 *
6333 * @param subId the subscription ID that this request applies to.
6334 * @param appType the uicc app type.
6335 * @return Application ID for specificied app type, or null if no uicc.
6336 */
6337 @Override
6338 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006339 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006340 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006341
6342 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006343 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006344 if (phone == null) {
6345 return null;
6346 }
6347 String aid = null;
6348 try {
6349 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6350 .getApplicationByType(appType).getAid();
6351 } catch (Exception e) {
6352 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6353 }
6354 return aid;
6355 } finally {
6356 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006357 }
Youhan Wange64578a2016-05-02 15:32:42 -07006358 }
6359
Youhan Wang4001d252016-05-11 10:29:41 -07006360 /**
6361 * Return the Electronic Serial Number.
6362 *
6363 * @param subId the subscription ID that this request applies to.
6364 * @return ESN or null if error.
6365 */
6366 @Override
6367 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006368 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006369 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006370
6371 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006372 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006373 if (phone == null) {
6374 return null;
6375 }
6376 String esn = null;
6377 try {
6378 esn = phone.getEsn();
6379 } catch (Exception e) {
6380 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6381 }
6382 return esn;
6383 } finally {
6384 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006385 }
Youhan Wang4001d252016-05-11 10:29:41 -07006386 }
6387
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006388 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006389 * Return the Preferred Roaming List Version.
6390 *
6391 * @param subId the subscription ID that this request applies to.
6392 * @return PRLVersion or null if error.
6393 */
6394 @Override
6395 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006396 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006397 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006398
6399 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006400 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 if (phone == null) {
6402 return null;
6403 }
6404 String cdmaPrlVersion = null;
6405 try {
6406 cdmaPrlVersion = phone.getCdmaPrlVersion();
6407 } catch (Exception e) {
6408 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6409 }
6410 return cdmaPrlVersion;
6411 } finally {
6412 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006413 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006414 }
6415
6416 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006417 * Get snapshot of Telephony histograms
6418 * @return List of Telephony histograms
6419 * @hide
6420 */
6421 @Override
6422 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6424 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425
6426 final long identity = Binder.clearCallingIdentity();
6427 try {
6428 return RIL.getTelephonyRILTimingHistograms();
6429 } finally {
6430 Binder.restoreCallingIdentity(identity);
6431 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006432 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006433
6434 /**
6435 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006436 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6437 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006438 * Require system privileges. In the future we may add this to carrier APIs.
6439 *
Michele Berionne482f8202018-11-27 18:57:59 -08006440 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006441 */
6442 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006443 @TelephonyManager.SetCarrierRestrictionResult
6444 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006445 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006446 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006447
Michele Berionne482f8202018-11-27 18:57:59 -08006448 if (carrierRestrictionRules == null) {
6449 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006450 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006452 final long identity = Binder.clearCallingIdentity();
6453 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006454 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006455 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006456 } finally {
6457 Binder.restoreCallingIdentity(identity);
6458 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006459 }
6460
6461 /**
6462 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006463 * Get the allowed carrier list and the excluded carrier list, including the priority between
6464 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006465 * Require system privileges. In the future we may add this to carrier APIs.
6466 *
Michele Berionne482f8202018-11-27 18:57:59 -08006467 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006468 */
6469 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006470 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006471 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006472 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006473
6474 final long identity = Binder.clearCallingIdentity();
6475 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006476 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6477 if (response instanceof CarrierRestrictionRules) {
6478 return (CarrierRestrictionRules) response;
6479 }
6480 // Response is an Exception of some kind,
6481 // which is signalled to the user as a NULL retval
6482 return null;
6483 } catch (Exception e) {
6484 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6485 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006486 } finally {
6487 Binder.restoreCallingIdentity(identity);
6488 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006489 }
6490
fionaxu59545b42016-05-25 15:53:37 -07006491 /**
6492 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6493 * @param subId the subscription ID that this action applies to.
6494 * @param enabled control enable or disable metered apns.
6495 * {@hide}
6496 */
6497 @Override
6498 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6499 enforceModifyPermission();
6500 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006501
6502 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006503 if (phone == null) {
6504 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6505 return;
6506 }
6507 try {
6508 phone.carrierActionSetMeteredApnsEnabled(enabled);
6509 } catch (Exception e) {
6510 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006511 } finally {
6512 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006513 }
6514 }
6515
6516 /**
6517 * Action set from carrier signalling broadcast receivers to enable/disable radio
6518 * @param subId the subscription ID that this action applies to.
6519 * @param enabled control enable or disable radio.
6520 * {@hide}
6521 */
6522 @Override
6523 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6524 enforceModifyPermission();
6525 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526
6527 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006528 if (phone == null) {
6529 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6530 return;
6531 }
6532 try {
6533 phone.carrierActionSetRadioEnabled(enabled);
6534 } catch (Exception e) {
6535 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536 } finally {
6537 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006538 }
6539 }
6540
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006541 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006542 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6543 * network status based on which carrier apps could apply actions accordingly,
6544 * enable/disable default url handler for example.
6545 *
6546 * @param subId the subscription ID that this action applies to.
6547 * @param report control start/stop reporting the default network status.
6548 * {@hide}
6549 */
6550 @Override
6551 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6552 enforceModifyPermission();
6553 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554
6555 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006556 if (phone == null) {
6557 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6558 return;
6559 }
6560 try {
6561 phone.carrierActionReportDefaultNetworkStatus(report);
6562 } catch (Exception e) {
6563 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564 } finally {
6565 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006566 }
6567 }
6568
6569 /**
fionaxud9622282017-07-17 17:51:30 -07006570 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6571 * @param subId the subscription ID that this action applies to.
6572 * {@hide}
6573 */
6574 @Override
6575 public void carrierActionResetAll(int subId) {
6576 enforceModifyPermission();
6577 final Phone phone = getPhone(subId);
6578 if (phone == null) {
6579 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6580 return;
6581 }
6582 try {
6583 phone.carrierActionResetAll();
6584 } catch (Exception e) {
6585 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6586 }
6587 }
6588
6589 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006590 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6591 * bug report is being generated.
6592 */
6593 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006594 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006595 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6596 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006597 writer.println("Permission Denial: can't dump Phone from pid="
6598 + Binder.getCallingPid()
6599 + ", uid=" + Binder.getCallingUid()
6600 + "without permission "
6601 + android.Manifest.permission.DUMP);
6602 return;
6603 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006604 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006605 }
Jack Yueb89b242016-06-22 13:27:47 -07006606
Brad Ebingerdac2f002018-04-03 15:17:52 -07006607 @Override
6608 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6609 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6610 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006611 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6612 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006613 }
6614
Jack Yueb89b242016-06-22 13:27:47 -07006615 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006616 * Get aggregated video call data usage since boot.
6617 *
6618 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6619 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006620 * {@hide}
6621 */
6622 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006623 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006624 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6625 null);
6626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006627 final long identity = Binder.clearCallingIdentity();
6628 try {
6629 // NetworkStatsService keeps tracking the active network interface and identity. It
6630 // records the delta with the corresponding network identity.
6631 // We just return the total video call data usage snapshot since boot.
6632 Phone phone = getPhone(subId);
6633 if (phone != null) {
6634 return phone.getVtDataUsage(perUidStats);
6635 }
6636 return null;
6637 } finally {
6638 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006639 }
Jack Yueb89b242016-06-22 13:27:47 -07006640 }
Jack Yu75ab2952016-07-08 14:29:33 -07006641
6642 /**
6643 * Policy control of data connection. Usually used when data limit is passed.
6644 * @param enabled True if enabling the data, otherwise disabling.
6645 * @param subId Subscription index
6646 * {@hide}
6647 */
6648 @Override
6649 public void setPolicyDataEnabled(boolean enabled, int subId) {
6650 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006651
6652 final long identity = Binder.clearCallingIdentity();
6653 try {
6654 Phone phone = getPhone(subId);
6655 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006656 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657 }
6658 } finally {
6659 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006660 }
6661 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006662
6663 /**
6664 * Get Client request stats
6665 * @return List of Client Request Stats
6666 * @hide
6667 */
6668 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006669 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6670 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006671 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006672 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006673 return null;
6674 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006675 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006677 final long identity = Binder.clearCallingIdentity();
6678 try {
6679 if (phone != null) {
6680 return phone.getClientRequestStats();
6681 }
6682
6683 return null;
6684 } finally {
6685 Binder.restoreCallingIdentity(identity);
6686 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006687 }
6688
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006689 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006690 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006691 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006692 }
Jack Yueb4124c2017-02-16 15:32:43 -08006693
6694 /**
Grace Chen70990072017-03-24 17:21:30 -07006695 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006696 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006697 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006698 * @param state State of SIM (power down, power up, pass through)
6699 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6700 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6701 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006702 *
6703 **/
6704 @Override
Grace Chen70990072017-03-24 17:21:30 -07006705 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006706 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006707 Phone phone = PhoneFactory.getPhone(slotIndex);
6708
vagdeviaf9a5b92018-08-15 16:01:53 -07006709 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711 final long identity = Binder.clearCallingIdentity();
6712 try {
6713 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006714 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 }
6716 } finally {
6717 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006718 }
6719 }
Shuo Qiandd210312017-04-12 22:11:33 +00006720
Tyler Gunn65d45c22017-06-05 11:22:26 -07006721 private boolean isUssdApiAllowed(int subId) {
6722 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006723 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006724 if (configManager == null) {
6725 return false;
6726 }
6727 PersistableBundle pb = configManager.getConfigForSubId(subId);
6728 if (pb == null) {
6729 return false;
6730 }
6731 return pb.getBoolean(
6732 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6733 }
6734
Shuo Qiandd210312017-04-12 22:11:33 +00006735 /**
6736 * Check if phone is in emergency callback mode
6737 * @return true if phone is in emergency callback mode
6738 * @param subId sub id
6739 */
goneil9c5f4872017-12-05 14:07:56 -08006740 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006741 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006742 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006743 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006744
6745 final long identity = Binder.clearCallingIdentity();
6746 try {
6747 if (phone != null) {
6748 return phone.isInEcm();
6749 } else {
6750 return false;
6751 }
6752 } finally {
6753 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006754 }
6755 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006756
6757 /**
6758 * Get the current signal strength information for the given subscription.
6759 * Because this information is not updated when the device is in a low power state
6760 * it should not be relied-upon to be current.
6761 * @param subId Subscription index
6762 * @return the most recent cached signal strength info from the modem
6763 */
6764 @Override
6765 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006766 final long identity = Binder.clearCallingIdentity();
6767 try {
6768 Phone p = getPhone(subId);
6769 if (p == null) {
6770 return null;
6771 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006772
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006773 return p.getSignalStrength();
6774 } finally {
6775 Binder.restoreCallingIdentity(identity);
6776 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006777 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006778
Pengquan Meng77b7f132018-08-22 14:49:57 -07006779 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006780 * Get the current modem radio state for the given slot.
6781 * @param slotIndex slot index.
6782 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006783 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006784 * @return the current radio power state from the modem
6785 */
6786 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006787 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006788 Phone phone = PhoneFactory.getPhone(slotIndex);
6789 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006790 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6791 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006792 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6793 }
6794
6795 final long identity = Binder.clearCallingIdentity();
6796 try {
6797 return phone.getRadioPowerState();
6798 } finally {
6799 Binder.restoreCallingIdentity(identity);
6800 }
6801 }
6802 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6803 }
6804
6805 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006806 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6807 *
6808 * <p>Requires one of the following permissions:
6809 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6810 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6811 * privileges.
6812 *
6813 * @param subId subscription id
6814 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6815 * {@code false}.
6816 */
6817 @Override
6818 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006819 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6820 null /* message */);
6821
Pengquan Menga1bb6272018-09-06 09:59:22 -07006822 boolean isEnabled = false;
6823 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006824 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006825 Phone phone = getPhone(subId);
6826 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006827 } catch (Exception e) {
6828 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6829 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006830 } finally {
6831 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006832 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006833 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006834 }
6835
6836
6837 /**
6838 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6839 *
6840 * <p> Requires permission:
6841 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6842 * privileges.
6843 *
6844 * @param subId subscription id
6845 * @param isEnabled {@code true} means enable, {@code false} means disable.
6846 */
6847 @Override
6848 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6850 mApp, subId, "setDataRoamingEnabled");
6851
Pengquan Menga1bb6272018-09-06 09:59:22 -07006852 final long identity = Binder.clearCallingIdentity();
6853 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006854 Phone phone = getPhone(subId);
6855 if (phone != null) {
6856 phone.setDataRoamingEnabled(isEnabled);
6857 }
6858 } finally {
6859 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006860 }
6861 }
6862
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006863 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006864 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006865 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6866 mApp, subId, "isManualNetworkSelectionAllowed");
6867
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006868 boolean isAllowed = true;
6869 final long identity = Binder.clearCallingIdentity();
6870 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006871 Phone phone = getPhone(subId);
6872 if (phone != null) {
6873 isAllowed = phone.isCspPlmnEnabled();
6874 }
6875 } finally {
6876 Binder.restoreCallingIdentity(identity);
6877 }
6878 return isAllowed;
6879 }
6880
6881 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006882 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006883 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006884 try {
6885 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006886 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006887 } catch (SecurityException e) {
6888 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6889 // has carrier privileges on an active UICC
6890 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6891 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006892 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006893 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006894 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006895
6896 final long identity = Binder.clearCallingIdentity();
6897 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006898 UiccController uiccController = UiccController.getInstance();
6899 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006900 if (hasReadPermission) {
6901 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006902 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006903
6904 // Remove private info if the caller doesn't have access
6905 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6906 for (UiccCardInfo cardInfo : cardInfos) {
6907 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6908 // is available
6909 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6910 if (card == null || card.getUiccProfile() == null) {
6911 // assume no access if the card or profile is unavailable
6912 filteredInfos.add(cardInfo.getUnprivileged());
6913 continue;
6914 }
6915 UiccProfile profile = card.getUiccProfile();
6916 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6917 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6918 filteredInfos.add(cardInfo);
6919 } else {
6920 filteredInfos.add(cardInfo.getUnprivileged());
6921 }
6922 }
6923 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006924 } finally {
6925 Binder.restoreCallingIdentity(identity);
6926 }
6927 }
6928
6929 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006930 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006931 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006933 final long identity = Binder.clearCallingIdentity();
6934 try {
6935 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6936 if (slots == null) {
6937 Rlog.i(LOG_TAG, "slots is null.");
6938 return null;
6939 }
6940
6941 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6942 for (int i = 0; i < slots.length; i++) {
6943 UiccSlot slot = slots[i];
6944 if (slot == null) {
6945 continue;
6946 }
6947
Jordan Liu7be7e652019-05-06 18:55:02 +00006948 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006949 UiccCard card = slot.getUiccCard();
6950 if (card != null) {
6951 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006952 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006953 cardId = slot.getEid();
6954 if (TextUtils.isEmpty(cardId)) {
6955 cardId = slot.getIccId();
6956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006957 }
6958
Jordan Liu857451f2019-05-09 16:35:35 -07006959 if (cardId != null) {
6960 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6961 // if cardId is an EID, it's all digits so this is fine
6962 cardId = IccUtils.stripTrailingFs(cardId);
6963 }
6964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965 int cardState = 0;
6966 switch (slot.getCardState()) {
6967 case CARDSTATE_ABSENT:
6968 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6969 break;
6970 case CARDSTATE_PRESENT:
6971 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6972 break;
6973 case CARDSTATE_ERROR:
6974 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6975 break;
6976 case CARDSTATE_RESTRICTED:
6977 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6978 break;
6979 default:
6980 break;
6981
6982 }
6983
6984 infos[i] = new UiccSlotInfo(
6985 slot.isActive(),
6986 slot.isEuicc(),
6987 cardId,
6988 cardState,
6989 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006990 slot.isExtendedApduSupported(),
6991 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992 }
6993 return infos;
6994 } finally {
6995 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006996 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006997 }
6998
6999 @Override
7000 public boolean switchSlots(int[] physicalSlots) {
7001 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002
7003 final long identity = Binder.clearCallingIdentity();
7004 try {
7005 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7006 } finally {
7007 Binder.restoreCallingIdentity(identity);
7008 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007009 }
Jack Yu4c988042018-02-27 15:30:01 -08007010
7011 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007012 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007013 final long identity = Binder.clearCallingIdentity();
7014 try {
7015 return UiccController.getInstance().getCardIdForDefaultEuicc();
7016 } finally {
7017 Binder.restoreCallingIdentity(identity);
7018 }
7019 }
7020
7021 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007022 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7023 enforceModifyPermission();
7024 final Phone phone = getPhone(subId);
7025 if (phone == null) {
7026 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7027 return;
7028 }
7029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007030 final long identity = Binder.clearCallingIdentity();
7031 try {
7032 phone.setRadioIndicationUpdateMode(filters, mode);
7033 } finally {
7034 Binder.restoreCallingIdentity(identity);
7035 }
Jack Yu4c988042018-02-27 15:30:01 -08007036 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007037
7038 /**
goneil47ffb6e2018-04-06 15:40:58 -07007039 * A test API to reload the UICC profile.
7040 *
7041 * <p>Requires that the calling app has permission
7042 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7043 * @hide
7044 */
7045 @Override
7046 public void refreshUiccProfile(int subId) {
7047 enforceModifyPermission();
7048
7049 final long identity = Binder.clearCallingIdentity();
7050 try {
7051 Phone phone = getPhone(subId);
7052 if (phone == null) {
7053 return;
7054 }
7055 UiccCard uiccCard = phone.getUiccCard();
7056 if (uiccCard == null) {
7057 return;
7058 }
7059 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7060 if (uiccProfile == null) {
7061 return;
7062 }
7063 uiccProfile.refresh();
7064 } finally {
7065 Binder.restoreCallingIdentity(identity);
7066 }
7067 }
7068
7069 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007070 * Returns false if the mobile data is disabled by default, otherwise return true.
7071 */
7072 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007073 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007074 }
7075
7076 /**
7077 * Returns true if the data roaming is enabled by default, i.e the system property
7078 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7079 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7080 */
7081 private boolean getDefaultDataRoamingEnabled(int subId) {
7082 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007083 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007084 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007085 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7086 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7087 return isDataRoamingEnabled;
7088 }
7089
7090 /**
7091 * Returns the default network type for the given {@code subId}, if the default network type is
7092 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7093 */
7094 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007095 List<Integer> list = TelephonyProperties.default_network();
7096 int phoneId = mSubscriptionController.getPhoneId(subId);
7097 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7098 return list.get(phoneId);
7099 }
7100 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007101 }
fionaxua13278b2018-03-21 00:08:13 -07007102
7103 @Override
7104 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007105 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007106 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107
7108 final long identity = Binder.clearCallingIdentity();
7109 try {
7110 final Phone phone = getPhone(subId);
7111 if (phone == null) {
7112 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7113 return;
7114 }
chen xueaba88a2019-03-15 13:15:10 -07007115 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7116 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007117 } finally {
7118 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007119 }
fionaxua13278b2018-03-21 00:08:13 -07007120 }
7121
7122 @Override
7123 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007124 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007125
7126 final long identity = Binder.clearCallingIdentity();
7127 try {
7128 final Phone phone = getPhone(subId);
7129 if (phone == null) {
7130 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7131 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7132 }
7133 return phone.getCarrierIdListVersion();
7134 } finally {
7135 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007136 }
fionaxua13278b2018-03-21 00:08:13 -07007137 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007138
7139 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007140 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7141 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007142 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007143 mApp, subId, callingPackage, callingFeatureId,
7144 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007145 return -1;
7146 }
7147
7148 final long identity = Binder.clearCallingIdentity();
7149 try {
7150 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7151 } finally {
7152 Binder.restoreCallingIdentity(identity);
7153 }
7154 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007155
7156 @Override
7157 public int getCdmaRoamingMode(int subId) {
7158 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7159 mApp, subId, "getCdmaRoamingMode");
7160
7161 final long identity = Binder.clearCallingIdentity();
7162 try {
7163 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7164 } finally {
7165 Binder.restoreCallingIdentity(identity);
7166 }
7167 }
7168
7169 @Override
7170 public boolean setCdmaRoamingMode(int subId, int mode) {
7171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7172 mApp, subId, "setCdmaRoamingMode");
7173
7174 final long identity = Binder.clearCallingIdentity();
7175 try {
7176 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7177 } finally {
7178 Binder.restoreCallingIdentity(identity);
7179 }
7180 }
7181
7182 @Override
7183 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7184 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7185 mApp, subId, "setCdmaSubscriptionMode");
7186
7187 final long identity = Binder.clearCallingIdentity();
7188 try {
7189 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7190 } finally {
7191 Binder.restoreCallingIdentity(identity);
7192 }
7193 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007194
sqianc5eccab2018-10-19 18:46:41 -07007195 @Override
sqian8c685422019-02-22 15:55:18 -08007196 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007197 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007199 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7200 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007201 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7202 }
7203 final long identity = Binder.clearCallingIdentity();
7204 try {
sqian854d44b2018-12-12 16:48:18 -08007205 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7206 for (Phone phone: PhoneFactory.getPhones()) {
7207 if (phone.getEmergencyNumberTracker() != null
7208 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7209 emergencyNumberListInternal.put(
7210 phone.getSubId(),
7211 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7212 }
sqian11b7a0e2018-12-05 18:48:28 -08007213 }
sqian854d44b2018-12-12 16:48:18 -08007214 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007215 } finally {
7216 Binder.restoreCallingIdentity(identity);
7217 }
sqianc5eccab2018-10-19 18:46:41 -07007218 }
7219
7220 @Override
sqian8c685422019-02-22 15:55:18 -08007221 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007222 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007223 if (!exactMatch) {
7224 TelephonyPermissions
7225 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007226 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007227 }
7228 final long identity = Binder.clearCallingIdentity();
7229 try {
sqian854d44b2018-12-12 16:48:18 -08007230 for (Phone phone: PhoneFactory.getPhones()) {
7231 if (phone.getEmergencyNumberTracker() != null
7232 && phone.getEmergencyNumberTracker() != null) {
7233 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7234 number, exactMatch)) {
7235 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007236 }
7237 }
sqian11b7a0e2018-12-05 18:48:28 -08007238 }
7239 return false;
7240 } finally {
7241 Binder.restoreCallingIdentity(identity);
7242 }
7243 }
7244
sqianf4ca7ed2019-01-15 18:32:07 -08007245 /**
7246 * Update emergency number list for test mode.
7247 */
7248 @Override
7249 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7250 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7251 "updateEmergencyNumberListTestMode");
7252
7253 final long identity = Binder.clearCallingIdentity();
7254 try {
7255 for (Phone phone: PhoneFactory.getPhones()) {
7256 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7257 if (tracker != null) {
7258 tracker.executeEmergencyNumberTestModeCommand(action, num);
7259 }
7260 }
7261 } finally {
7262 Binder.restoreCallingIdentity(identity);
7263 }
7264 }
7265
7266 /**
7267 * Get the full emergency number list for test mode.
7268 */
7269 @Override
7270 public List<String> getEmergencyNumberListTestMode() {
7271 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7272 "getEmergencyNumberListTestMode");
7273
7274 final long identity = Binder.clearCallingIdentity();
7275 try {
7276 Set<String> emergencyNumbers = new HashSet<>();
7277 for (Phone phone: PhoneFactory.getPhones()) {
7278 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7279 if (tracker != null) {
7280 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7281 emergencyNumbers.add(num.getNumber());
7282 }
7283 }
7284 }
7285 return new ArrayList<>(emergencyNumbers);
7286 } finally {
7287 Binder.restoreCallingIdentity(identity);
7288 }
7289 }
7290
chen xud6b45bd2018-10-30 22:27:10 -07007291 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007292 public int getEmergencyNumberDbVersion(int subId) {
7293 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7294
7295 final long identity = Binder.clearCallingIdentity();
7296 try {
7297 final Phone phone = getPhone(subId);
7298 if (phone == null) {
7299 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7300 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7301 }
7302 return phone.getEmergencyNumberDbVersion();
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
7305 }
7306 }
7307
7308 @Override
7309 public void notifyOtaEmergencyNumberDbInstalled() {
7310 enforceModifyPermission();
7311
7312 final long identity = Binder.clearCallingIdentity();
7313 try {
7314 for (Phone phone: PhoneFactory.getPhones()) {
7315 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7316 if (tracker != null) {
7317 tracker.updateOtaEmergencyNumberDatabase();
7318 }
7319 }
7320 } finally {
7321 Binder.restoreCallingIdentity(identity);
7322 }
7323 }
7324
7325 @Override
7326 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7327 enforceActiveEmergencySessionPermission();
7328
7329 final long identity = Binder.clearCallingIdentity();
7330 try {
7331 for (Phone phone: PhoneFactory.getPhones()) {
7332 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7333 if (tracker != null) {
7334 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7335 }
7336 }
7337 } finally {
7338 Binder.restoreCallingIdentity(identity);
7339 }
7340 }
7341
7342 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007343 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7344 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7345 Phone phone = getPhone(subId);
7346 if (phone == null) {
7347 return null;
7348 }
7349 final long identity = Binder.clearCallingIdentity();
7350 try {
7351 UiccProfile profile = UiccController.getInstance()
7352 .getUiccProfileForPhone(phone.getPhoneId());
7353 if (profile != null) {
7354 return profile.getCertsFromCarrierPrivilegeAccessRules();
7355 }
7356 } finally {
7357 Binder.restoreCallingIdentity(identity);
7358 }
7359 return null;
7360 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007361
7362 /**
7363 * Enable or disable a modem stack.
7364 */
7365 @Override
7366 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7367 enforceModifyPermission();
7368
7369 final long identity = Binder.clearCallingIdentity();
7370 try {
7371 Phone phone = PhoneFactory.getPhone(slotIndex);
7372 if (phone == null) {
7373 return false;
7374 } else {
7375 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7376 }
7377 } finally {
7378 Binder.restoreCallingIdentity(identity);
7379 }
7380 }
Michelecea4cf22018-12-21 15:00:11 -08007381
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007382 /**
7383 * Whether a modem stack is enabled or not.
7384 */
7385 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007386 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7387 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007388 Phone phone = PhoneFactory.getPhone(slotIndex);
7389 if (phone == null) return false;
7390
7391 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007392 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7393 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007394 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7395 }
7396
7397 final long identity = Binder.clearCallingIdentity();
7398 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007399 try {
7400 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7401 } catch (NoSuchElementException ex) {
7402 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7403 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007404 } finally {
7405 Binder.restoreCallingIdentity(identity);
7406 }
7407 }
7408
Michelecea4cf22018-12-21 15:00:11 -08007409 @Override
Michele0ea7d782019-03-19 14:58:42 -07007410 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007411 enforceModifyPermission();
7412
7413 final long identity = Binder.clearCallingIdentity();
7414 try {
7415 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007416 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007417 .commit();
7418 } finally {
7419 Binder.restoreCallingIdentity(identity);
7420 }
7421 }
7422
7423 @Override
Michele0ea7d782019-03-19 14:58:42 -07007424 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007425 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007426 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007427 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7428 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007429 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007430 }
Michelecea4cf22018-12-21 15:00:11 -08007431
7432 final long identity = Binder.clearCallingIdentity();
7433 try {
Michele0ea7d782019-03-19 14:58:42 -07007434 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007435 } finally {
7436 Binder.restoreCallingIdentity(identity);
7437 }
7438 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007439
Michele0ea7d782019-03-19 14:58:42 -07007440 @TelephonyManager.IsMultiSimSupportedResult
7441 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007442 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7443 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7444 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007445 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7446 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007447 }
7448 // Check if the hardware supports multisim functionality. If usage of multisim is not
7449 // supported by the modem, indicate that it is restricted.
7450 PhoneCapability staticCapability =
7451 mPhoneConfigurationManager.getStaticPhoneCapability();
7452 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007453 loge("isMultiSimSupportedInternal: no static configuration available");
7454 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007455 }
7456 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007457 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7458 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007459 }
7460 // Check if support of multiple SIMs is restricted by carrier
7461 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007462 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007463 }
7464
Michele0ea7d782019-03-19 14:58:42 -07007465 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007466 }
7467
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007468 /**
7469 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007470 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7471 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7472 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007473 * @param numOfSims number of active sims we want to switch to
7474 */
7475 @Override
7476 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007477 if (numOfSims == 1) {
7478 enforceModifyPermission();
7479 } else {
7480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7481 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7482 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007483 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007484
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007485 try {
Michele30b57b22019-03-01 12:01:14 -08007486 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007487 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007488 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7489 return;
7490 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007491 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
7494 }
7495 }
7496
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007497 @Override
7498 public boolean isApplicationOnUicc(int subId, int appType) {
7499 enforceReadPrivilegedPermission("isApplicationOnUicc");
7500 Phone phone = getPhone(subId);
7501 if (phone == null) {
7502 return false;
7503 }
7504 final long identity = Binder.clearCallingIdentity();
7505 try {
7506 UiccCard uiccCard = phone.getUiccCard();
7507 if (uiccCard == null) {
7508 return false;
7509 }
7510 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7511 if (uiccProfile == null) {
7512 return false;
7513 }
7514 if (TelephonyManager.APPTYPE_SIM <= appType
7515 && appType <= TelephonyManager.APPTYPE_ISIM) {
7516 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7517 }
7518 return false;
7519 } finally {
7520 Binder.restoreCallingIdentity(identity);
7521 }
7522 }
7523
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007524 /**
chen xub4baa772019-04-03 10:23:41 -07007525 * Get whether making changes to modem configurations will trigger reboot.
7526 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007527 */
7528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007529 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7530 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007532 mApp, subId, callingPackage, callingFeatureId,
7533 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007534 return false;
7535 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007536 final long identity = Binder.clearCallingIdentity();
7537 try {
7538 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7539 } finally {
7540 Binder.restoreCallingIdentity(identity);
7541 }
7542 }
7543
Nathan Harold29f5f052019-02-15 13:41:57 -08007544 private void updateModemStateMetrics() {
7545 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7546 // TODO: check the state for each modem if the api is ready.
7547 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7548 }
7549
Pengquan Meng3889a572019-01-23 11:16:29 -08007550 @Override
7551 public int[] getSlotsMapping() {
7552 enforceReadPrivilegedPermission("getSlotsMapping");
7553
7554 final long identity = Binder.clearCallingIdentity();
7555 try {
7556 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7557 // All logical slots should have a mapping to a physical slot.
7558 int[] logicalSlotsMapping = new int[phoneCount];
7559 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7560 for (int i = 0; i < slotInfos.length; i++) {
7561 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7562 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7563 }
7564 }
7565 return logicalSlotsMapping;
7566 } finally {
7567 Binder.restoreCallingIdentity(identity);
7568 }
7569 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007570
7571 /**
7572 * Get the IRadio HAL Version
7573 */
7574 @Override
7575 public int getRadioHalVersion() {
7576 Phone phone = getDefaultPhone();
7577 if (phone == null) return -1;
7578 HalVersion hv = phone.getHalVersion();
7579 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7580 return hv.major * 100 + hv.minor;
7581 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007582
7583 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007584 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7585 * corresponding network requests on a subId.
7586 *
7587 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007588 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007589 * 2) APN is un-metered for this subscription, or
7590 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7591 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7592 *
7593 * @return whether data is allowed for a apn type.
7594 *
7595 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007596 */
7597 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007598 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007599 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7600 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007601
7602 // Now that all security checks passes, perform the operation as ourselves.
7603 final long identity = Binder.clearCallingIdentity();
7604 try {
7605 Phone phone = getPhone(subId);
7606 if (phone == null) return false;
7607
Jack Yu41407ee2019-05-13 16:54:09 -07007608 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007609 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7610 } finally {
7611 Binder.restoreCallingIdentity(identity);
7612 }
7613 }
7614
7615 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007616 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007617 enforceReadPrivilegedPermission("isApnMetered");
7618
7619 // Now that all security checks passes, perform the operation as ourselves.
7620 final long identity = Binder.clearCallingIdentity();
7621 try {
7622 Phone phone = getPhone(subId);
7623 if (phone == null) return true; // By default return true.
7624
Jack Yu41407ee2019-05-13 16:54:09 -07007625 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007626 } finally {
7627 Binder.restoreCallingIdentity(identity);
7628 }
7629 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007630
7631 @Override
7632 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7633 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7634 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7635 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7636 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7637 }
7638 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7639 Intent intent = new Intent();
7640 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7641 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7642 // Bring up choose default SMS subscription dialog right now
7643 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7644 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7645 mApp.startActivity(intent);
7646 }
chen xud5ca2d52019-05-28 15:20:57 -07007647
7648 @Override
7649 public String getMmsUAProfUrl(int subId) {
7650 //TODO investigate if this API should require proper permission check in R b/133791609
7651 final long identity = Binder.clearCallingIdentity();
7652 try {
7653 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7654 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7655 } finally {
7656 Binder.restoreCallingIdentity(identity);
7657 }
7658 }
7659
7660 @Override
7661 public String getMmsUserAgent(int subId) {
7662 //TODO investigate if this API should require proper permission check in R b/133791609
7663 final long identity = Binder.clearCallingIdentity();
7664 try {
7665 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7666 .getString(com.android.internal.R.string.config_mms_user_agent);
7667 } finally {
7668 Binder.restoreCallingIdentity(identity);
7669 }
7670 }
Jack Yub07d4972019-05-28 16:12:25 -07007671
7672 @Override
7673 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7674 enforceModifyPermission();
7675
7676 // Now that all security checks passes, perform the operation as ourselves.
7677 final long identity = Binder.clearCallingIdentity();
7678 try {
7679 Phone phone = getPhone(subId);
7680 if (phone == null) return false;
7681
7682 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7683 } finally {
7684 Binder.restoreCallingIdentity(identity);
7685 }
7686 }
7687
7688 @Override
7689 public boolean isDataAllowedInVoiceCall(int subId) {
7690 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
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().isDataAllowedInVoiceCall();
7699 } finally {
7700 Binder.restoreCallingIdentity(identity);
7701 }
7702 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007703
7704 /**
7705 * Updates whether conference event pacakge handling is enabled.
7706 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7707 * otherwise.
7708 */
7709 @Override
7710 public void setCepEnabled(boolean isCepEnabled) {
7711 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7712
7713 final long identity = Binder.clearCallingIdentity();
7714 try {
7715 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7716 for (Phone phone : PhoneFactory.getPhones()) {
7717 Phone defaultPhone = phone.getImsPhone();
7718 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7719 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7720 ImsPhoneCallTracker imsPhoneCallTracker =
7721 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7722 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7723 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7724 + imsPhone.getMsisdn());
7725 }
7726 }
7727 } finally {
7728 Binder.restoreCallingIdentity(identity);
7729 }
7730 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007731}