blob: 342d61cabd32d5e8db66b6286e27b5a5f070d4bd [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;
Ihab Awadf2177b72013-11-25 13:33:23 -080059import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070060import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090061import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080062import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080063import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070064import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070065import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070066import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080067import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070068import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070070import android.telephony.CellInfoGsm;
71import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070072import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070073import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070074import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070075import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080076import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070077import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080078import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070079import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080080import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080081import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070082import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080083import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070084import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080086import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080087import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080088import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070089import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070090import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080091import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080092import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000093import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070094import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070095import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070096import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080097import android.telephony.data.ApnSetting;
98import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070099import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700100import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800101import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700102import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800104import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700105import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsMmTelFeature;
107import android.telephony.ims.aidl.IImsRcsFeature;
108import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700109import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700110import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.feature.MmTelFeature;
112import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800113import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800117import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800119
Andrew Lee312e8172014-10-23 17:01:36 -0700120import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800121import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700123import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700124import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800125import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700126import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700127import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800129import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700130import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800131import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800133import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700134import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100135import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700136import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700139import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800140import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700141import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700142import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700143import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700144import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700145import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700146import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700147import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800149import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800150import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700151import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800152import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700153import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800154import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700155import com.android.internal.telephony.imsphone.ImsPhone;
156import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800157import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
160import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800161import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700162import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800163import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800165import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000166import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700167import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700169import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700170import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800171import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700172import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700173import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800174
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700175import java.io.FileDescriptor;
176import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800178import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800179import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800180import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800181import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100182import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700184import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186
187/**
188 * Implementation of the ITelephony interface.
189 */
Santos Cordon117fee72014-05-16 17:56:12 -0700190public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191 private static final String LOG_TAG = "PhoneInterfaceManager";
192 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
193 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800194 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195
196 // Message codes used with mMainThreadHandler
197 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700198 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
199 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700200 private static final int CMD_OPEN_CHANNEL = 9;
201 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
202 private static final int CMD_CLOSE_CHANNEL = 11;
203 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800204 private static final int CMD_NV_READ_ITEM = 13;
205 private static final int EVENT_NV_READ_ITEM_DONE = 14;
206 private static final int CMD_NV_WRITE_ITEM = 15;
207 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
208 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
209 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700210 private static final int CMD_RESET_MODEM_CONFIG = 19;
211 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800212 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
213 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
214 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
215 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800216 private static final int CMD_SEND_ENVELOPE = 25;
217 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000218 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
219 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700220 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
221 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
222 private static final int CMD_EXCHANGE_SIM_IO = 31;
223 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800224 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
225 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700226 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
227 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700228 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
229 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700230 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
231 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
232 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
233 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700234 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
235 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
236 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
237 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700238 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800239 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
240 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000241 private static final int CMD_SWITCH_SLOTS = 50;
242 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700243 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
244 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
245 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
246 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
247 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
248 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
249 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
250 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700251 private static final int CMD_GET_ALL_CELL_INFO = 60;
252 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
253 private static final int CMD_GET_CELL_LOCATION = 62;
254 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700255 private static final int CMD_MODEM_REBOOT = 64;
256 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700257 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
258 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800259 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
260 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700261 private static final int CMD_GET_MODEM_STATUS = 70;
262 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700263 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
264 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800266 // Parameters of select command.
267 private static final int SELECT_COMMAND = 0xA4;
268 private static final int SELECT_P1 = 0x04;
269 private static final int SELECT_P2 = 0;
270 private static final int SELECT_P3 = 0x10;
271
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272 /** The singleton instance. */
273 private static PhoneInterfaceManager sInstance;
274
Wink Saville3ab207e2014-11-20 13:07:20 -0800275 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800276 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700277 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private AppOpsManager mAppOps;
279 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800280 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700282 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700283
Derek Tan97ebb422014-09-05 16:55:38 -0700284 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
285 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800286 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800287 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700288
Michelecea4cf22018-12-21 15:00:11 -0800289 // String to store multi SIM allowed
290 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
291
Derek Tan740e1672017-06-27 14:56:27 -0700292 // The AID of ISD-R.
293 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
294
yinxub1bed742017-04-17 11:45:04 -0700295 private NetworkScanRequestTracker mNetworkScanRequestTracker;
296
David Kelly5e06a7f2018-03-12 14:10:59 +0000297 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
298 private static final int MANUFACTURER_CODE_LENGTH = 8;
299
Derek Tan89e89d42014-07-08 17:00:10 -0700300 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700301 * A request object to use for transmitting data to an ICC.
302 */
303 private static final class IccAPDUArgument {
304 public int channel, cla, command, p1, p2, p3;
305 public String data;
306
307 public IccAPDUArgument(int channel, int cla, int command,
308 int p1, int p2, int p3, String data) {
309 this.channel = channel;
310 this.cla = cla;
311 this.command = command;
312 this.p1 = p1;
313 this.p2 = p2;
314 this.p3 = p3;
315 this.data = data;
316 }
317 }
318
319 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700320 * A request object to use for transmitting data to an ICC.
321 */
322 private static final class ManualNetworkSelectionArgument {
323 public OperatorInfo operatorInfo;
324 public boolean persistSelection;
325
326 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
327 this.operatorInfo = operatorInfo;
328 this.persistSelection = persistSelection;
329 }
330 }
331
332 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
334 * request after sending. The main thread will notify the request when it is complete.
335 */
336 private static final class MainThreadRequest {
337 /** The argument to use for the request */
338 public Object argument;
339 /** The result of the request that is run on the main thread */
340 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800341 // The subscriber id that this request applies to. Defaults to
342 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
343 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
Nathan Harold92bed182018-10-12 18:16:49 -0700345 // In cases where subId is unavailable, the caller needs to specify the phone.
346 public Phone phone;
347
vagdeviaf9a5b92018-08-15 16:01:53 -0700348 public WorkSource workSource;
349
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 public MainThreadRequest(Object argument) {
351 this.argument = argument;
352 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800353
Nathan Harold92bed182018-10-12 18:16:49 -0700354 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
355 this.argument = argument;
356 if (phone != null) {
357 this.phone = phone;
358 }
359 this.workSource = workSource;
360 }
361
vagdeviaf9a5b92018-08-15 16:01:53 -0700362 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800363 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800364 if (subId != null) {
365 this.subId = subId;
366 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700367 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 }
370
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800371 private static final class IncomingThirdPartyCallArgs {
372 public final ComponentName component;
373 public final String callId;
374 public final String callerDisplayName;
375
376 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
377 String callerDisplayName) {
378 this.component = component;
379 this.callId = callId;
380 this.callerDisplayName = callerDisplayName;
381 }
382 }
383
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 /**
385 * A handler that processes messages on the main thread in the phone process. Since many
386 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
387 * inbound binder threads to the main thread in the phone process. The Binder thread
388 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
389 * on, which will be notified when the operation completes and will contain the result of the
390 * request.
391 *
392 * <p>If a MainThreadRequest object is provided in the msg.obj field,
393 * note that request.result must be set to something non-null for the calling thread to
394 * unblock.
395 */
396 private final class MainThreadHandler extends Handler {
397 @Override
398 public void handleMessage(Message msg) {
399 MainThreadRequest request;
400 Message onCompleted;
401 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800402 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700403 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800404 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405
406 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700407 case CMD_HANDLE_USSD_REQUEST: {
408 request = (MainThreadRequest) msg.obj;
409 final Phone phone = getPhoneFromRequest(request);
410 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
411 String ussdRequest = ussdObject.first;
412 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700413
Pengquan Menga1bb6272018-09-06 09:59:22 -0700414 if (!isUssdApiAllowed(request.subId)) {
415 // Carrier does not support use of this API, return failure.
416 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
417 UssdResponse response = new UssdResponse(ussdRequest, null);
418 Bundle returnData = new Bundle();
419 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
420 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700421
Pengquan Menga1bb6272018-09-06 09:59:22 -0700422 request.result = true;
423 notifyRequester(request);
424 return;
425 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700426
Pengquan Menga1bb6272018-09-06 09:59:22 -0700427 try {
428 request.result = phone != null
429 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
430 } catch (CallStateException cse) {
431 request.result = false;
432 }
433 // Wake up the requesting thread
434 notifyRequester(request);
435 break;
pkanwar32d516d2016-10-14 19:37:38 -0700436 }
437
Yorke Lee716f67e2015-06-17 15:39:16 -0700438 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700440 final Phone phone = getPhoneFromRequest(request);
441 request.result = phone != null ?
442 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
443 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700449 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700450 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800452 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700453 if (uiccCard == null) {
454 loge("iccTransmitApduLogicalChannel: No UICC");
455 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
459 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700460 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 iccArgument.channel, iccArgument.cla, iccArgument.command,
462 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700464 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 break;
466
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700468 ar = (AsyncResult) msg.obj;
469 request = (MainThreadRequest) ar.userObj;
470 if (ar.exception == null && ar.result != null) {
471 request.result = ar.result;
472 } else {
473 request.result = new IccIoResult(0x6F, 0, (byte[])null);
474 if (ar.result == null) {
475 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800476 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800478 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 } else {
480 loge("iccTransmitApduLogicalChannel: Unknown exception");
481 }
482 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700483 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700484 break;
485
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
487 request = (MainThreadRequest) msg.obj;
488 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 if (uiccCard == null) {
491 loge("iccTransmitApduBasicChannel: No UICC");
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 } else {
495 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
496 request);
497 uiccCard.iccTransmitApduBasicChannel(
498 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
499 iccArgument.p3, iccArgument.data, onCompleted);
500 }
501 break;
502
503 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
504 ar = (AsyncResult) msg.obj;
505 request = (MainThreadRequest) ar.userObj;
506 if (ar.exception == null && ar.result != null) {
507 request.result = ar.result;
508 } else {
509 request.result = new IccIoResult(0x6F, 0, (byte[])null);
510 if (ar.result == null) {
511 loge("iccTransmitApduBasicChannel: Empty response");
512 } else if (ar.exception instanceof CommandException) {
513 loge("iccTransmitApduBasicChannel: CommandException: " +
514 ar.exception);
515 } else {
516 loge("iccTransmitApduBasicChannel: Unknown exception");
517 }
518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700520 break;
521
522 case CMD_EXCHANGE_SIM_IO:
523 request = (MainThreadRequest) msg.obj;
524 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800525 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 if (uiccCard == null) {
527 loge("iccExchangeSimIO: No UICC");
528 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 } else {
531 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
532 request);
533 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
534 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
535 iccArgument.data, onCompleted);
536 }
537 break;
538
539 case EVENT_EXCHANGE_SIM_IO_DONE:
540 ar = (AsyncResult) msg.obj;
541 request = (MainThreadRequest) ar.userObj;
542 if (ar.exception == null && ar.result != null) {
543 request.result = ar.result;
544 } else {
545 request.result = new IccIoResult(0x6f, 0, (byte[])null);
546 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700547 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 break;
549
Derek Tan4d5e5c12014-02-04 11:54:58 -0800550 case CMD_SEND_ENVELOPE:
551 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800552 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 if (uiccCard == null) {
554 loge("sendEnvelopeWithStatus: No UICC");
555 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 } else {
558 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
559 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
560 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800561 break;
562
563 case EVENT_SEND_ENVELOPE_DONE:
564 ar = (AsyncResult) msg.obj;
565 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700566 if (ar.exception == null && ar.result != null) {
567 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800568 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700569 request.result = new IccIoResult(0x6F, 0, (byte[])null);
570 if (ar.result == null) {
571 loge("sendEnvelopeWithStatus: Empty response");
572 } else if (ar.exception instanceof CommandException) {
573 loge("sendEnvelopeWithStatus: CommandException: " +
574 ar.exception);
575 } else {
576 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
577 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800578 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800580 break;
581
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 case CMD_OPEN_CHANNEL:
583 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800584 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800585 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700586 if (uiccCard == null) {
587 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800588 request.result = new IccOpenLogicalChannelResponse(-1,
589 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700590 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 } else {
592 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800593 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
594 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 break;
597
598 case EVENT_OPEN_CHANNEL_DONE:
599 ar = (AsyncResult) msg.obj;
600 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 int[] result = (int[]) ar.result;
604 int channelId = result[0];
605 byte[] selectResponse = null;
606 if (result.length > 1) {
607 selectResponse = new byte[result.length - 1];
608 for (int i = 1; i < result.length; ++i) {
609 selectResponse[i - 1] = (byte) result[i];
610 }
611 }
612 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 if (ar.result == null) {
616 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 if (ar.exception != null) {
619 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
620 }
621
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700623 if (ar.exception instanceof CommandException) {
624 CommandException.Error error =
625 ((CommandException) (ar.exception)).getCommandError();
626 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700627 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700628 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700629 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 }
631 }
632 openChannelResp = new IccOpenLogicalChannelResponse(
633 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700635 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700636 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 break;
638
639 case CMD_CLOSE_CHANNEL:
640 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800641 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700642 if (uiccCard == null) {
643 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900644 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700646 } else {
647 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
648 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
649 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
652 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800653 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
654 break;
655
656 case CMD_NV_READ_ITEM:
657 request = (MainThreadRequest) msg.obj;
658 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800659 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
660 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800661 break;
662
663 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 ar = (AsyncResult) msg.obj;
665 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800666 if (ar.exception == null && ar.result != null) {
667 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800669 request.result = "";
670 if (ar.result == null) {
671 loge("nvReadItem: Empty response");
672 } else if (ar.exception instanceof CommandException) {
673 loge("nvReadItem: CommandException: " +
674 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800676 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 }
678 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 break;
681
Jake Hambye994d462014-02-03 13:10:13 -0800682 case CMD_NV_WRITE_ITEM:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
685 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800686 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700687 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800688 break;
689
690 case EVENT_NV_WRITE_ITEM_DONE:
691 handleNullReturnEvent(msg, "nvWriteItem");
692 break;
693
694 case CMD_NV_WRITE_CDMA_PRL:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800697 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
700 case EVENT_NV_WRITE_CDMA_PRL_DONE:
701 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
702 break;
703
chen xu6dac5ab2018-10-26 17:39:23 -0700704 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800705 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700706 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800707 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800708 break;
709
chen xu6dac5ab2018-10-26 17:39:23 -0700710 case EVENT_RESET_MODEM_CONFIG_DONE:
711 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800712 break;
713
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 case CMD_GET_PREFERRED_NETWORK_TYPE:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700717 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800718 break;
719
720 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
721 ar = (AsyncResult) msg.obj;
722 request = (MainThreadRequest) ar.userObj;
723 if (ar.exception == null && ar.result != null) {
724 request.result = ar.result; // Integer
725 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800726 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 if (ar.result == null) {
728 loge("getPreferredNetworkType: Empty response");
729 } else if (ar.exception instanceof CommandException) {
730 loge("getPreferredNetworkType: CommandException: " +
731 ar.exception);
732 } else {
733 loge("getPreferredNetworkType: Unknown exception");
734 }
735 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700736 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800737 break;
738
739 case CMD_SET_PREFERRED_NETWORK_TYPE:
740 request = (MainThreadRequest) msg.obj;
741 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
742 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700743 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800744 break;
745
746 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
747 handleNullReturnEvent(msg, "setPreferredNetworkType");
748 break;
749
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000750 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
751 request = (MainThreadRequest)msg.obj;
752 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800753 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000754 break;
755
756 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
757 ar = (AsyncResult)msg.obj;
758 request = (MainThreadRequest)ar.userObj;
759 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700760 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000761 break;
762
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800763 case CMD_SET_VOICEMAIL_NUMBER:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
766 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800767 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
768 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800769 break;
770
771 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
772 handleNullReturnEvent(msg, "setVoicemailNumber");
773 break;
774
Stuart Scott54788802015-03-30 13:18:01 -0700775 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
778 request);
779 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
780 break;
781
782 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
783 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
784 break;
785
Shishir Agrawal302c8692015-06-19 13:49:39 -0700786 case CMD_PERFORM_NETWORK_SCAN:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
789 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
790 break;
791
792 case EVENT_PERFORM_NETWORK_SCAN_DONE:
793 ar = (AsyncResult) msg.obj;
794 request = (MainThreadRequest) ar.userObj;
795 CellNetworkScanResult cellScanResult;
796 if (ar.exception == null && ar.result != null) {
797 cellScanResult = new CellNetworkScanResult(
798 CellNetworkScanResult.STATUS_SUCCESS,
799 (List<OperatorInfo>) ar.result);
800 } else {
801 if (ar.result == null) {
802 loge("getCellNetworkScanResults: Empty response");
803 }
804 if (ar.exception != null) {
805 loge("getCellNetworkScanResults: Exception: " + ar.exception);
806 }
807 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
808 if (ar.exception instanceof CommandException) {
809 CommandException.Error error =
810 ((CommandException) (ar.exception)).getCommandError();
811 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
812 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
813 } else if (error == CommandException.Error.GENERIC_FAILURE) {
814 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
815 }
816 }
817 cellScanResult = new CellNetworkScanResult(errorCode, null);
818 }
819 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700820 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700821 break;
822
823 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
824 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700825 ManualNetworkSelectionArgument selArg =
826 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700827 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
828 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700829 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
830 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700831 break;
832
833 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700834 ar = (AsyncResult) msg.obj;
835 request = (MainThreadRequest) ar.userObj;
836 if (ar.exception == null) {
837 request.result = true;
838 } else {
839 request.result = false;
840 loge("setNetworkSelectionModeManual " + ar.exception);
841 }
842 notifyRequester(request);
843 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700844 break;
845
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700846 case CMD_GET_MODEM_ACTIVITY_INFO:
847 request = (MainThreadRequest) msg.obj;
848 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700849 if (defaultPhone != null) {
850 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
851 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700852 break;
853
854 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
855 ar = (AsyncResult) msg.obj;
856 request = (MainThreadRequest) ar.userObj;
857 if (ar.exception == null && ar.result != null) {
858 request.result = ar.result;
859 } else {
860 if (ar.result == null) {
861 loge("queryModemActivityInfo: Empty response");
862 } else if (ar.exception instanceof CommandException) {
863 loge("queryModemActivityInfo: CommandException: " +
864 ar.exception);
865 } else {
866 loge("queryModemActivityInfo: Unknown exception");
867 }
868 }
Amit Mahajand4766222016-01-28 15:28:28 -0800869 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
870 if (request.result == null) {
Chen Xud78231e2019-09-10 18:49:52 -0700871 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800872 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700873 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700874 break;
875
Meng Wang1a7c35a2016-05-05 20:56:15 -0700876 case CMD_SET_ALLOWED_CARRIERS:
877 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800878 CarrierRestrictionRules argument =
879 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800881 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700882 break;
883
884 case EVENT_SET_ALLOWED_CARRIERS_DONE:
885 ar = (AsyncResult) msg.obj;
886 request = (MainThreadRequest) ar.userObj;
887 if (ar.exception == null && ar.result != null) {
888 request.result = ar.result;
889 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800890 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
891 if (ar.exception instanceof CommandException) {
892 loge("setAllowedCarriers: CommandException: " + ar.exception);
893 CommandException.Error error =
894 ((CommandException) (ar.exception)).getCommandError();
895 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
896 request.result =
897 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
898 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700899 } else {
900 loge("setAllowedCarriers: Unknown exception");
901 }
902 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700903 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700904 break;
905
906 case CMD_GET_ALLOWED_CARRIERS:
907 request = (MainThreadRequest) msg.obj;
908 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800909 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700910 break;
911
912 case EVENT_GET_ALLOWED_CARRIERS_DONE:
913 ar = (AsyncResult) msg.obj;
914 request = (MainThreadRequest) ar.userObj;
915 if (ar.exception == null && ar.result != null) {
916 request.result = ar.result;
917 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800918 request.result = new IllegalStateException(
919 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700920 if (ar.result == null) {
921 loge("getAllowedCarriers: Empty response");
922 } else if (ar.exception instanceof CommandException) {
923 loge("getAllowedCarriers: CommandException: " +
924 ar.exception);
925 } else {
926 loge("getAllowedCarriers: Unknown exception");
927 }
928 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700929 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700930 break;
931
Nathan Haroldb3014052017-01-25 15:57:32 -0800932 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
933 ar = (AsyncResult) msg.obj;
934 request = (MainThreadRequest) ar.userObj;
935 if (ar.exception == null && ar.result != null) {
936 request.result = ar.result;
937 } else {
938 request.result = new IllegalArgumentException(
939 "Failed to retrieve Forbidden Plmns");
940 if (ar.result == null) {
941 loge("getForbiddenPlmns: Empty response");
942 } else {
943 loge("getForbiddenPlmns: Unknown exception");
944 }
945 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700946 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800947 break;
948
949 case CMD_GET_FORBIDDEN_PLMNS:
950 request = (MainThreadRequest) msg.obj;
951 uiccCard = getUiccCardFromRequest(request);
952 if (uiccCard == null) {
953 loge("getForbiddenPlmns() UiccCard is null");
954 request.result = new IllegalArgumentException(
955 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800957 break;
958 }
959 Integer appType = (Integer) request.argument;
960 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
961 if (uiccApp == null) {
962 loge("getForbiddenPlmns() no app with specified type -- "
963 + appType);
964 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700965 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800966 break;
967 } else {
968 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
969 + " specified type -- " + appType);
970 }
971 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
972 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
973 onCompleted);
974 break;
975
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000976 case CMD_SWITCH_SLOTS:
977 request = (MainThreadRequest) msg.obj;
978 int[] physicalSlots = (int[]) request.argument;
979 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
980 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
981 break;
982
983 case EVENT_SWITCH_SLOTS_DONE:
984 ar = (AsyncResult) msg.obj;
985 request = (MainThreadRequest) ar.userObj;
986 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700987 notifyRequester(request);
988 break;
989 case CMD_GET_NETWORK_SELECTION_MODE:
990 request = (MainThreadRequest) msg.obj;
991 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
992 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
993 break;
994
995 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
998 if (ar.exception != null) {
999 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1000 } else {
1001 int mode = ((int[]) ar.result)[0];
1002 if (mode == 0) {
1003 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1004 } else {
1005 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1006 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001007 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001008 notifyRequester(request);
1009 break;
1010 case CMD_GET_CDMA_ROAMING_MODE:
1011 request = (MainThreadRequest) msg.obj;
1012 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1013 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1014 break;
1015 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1016 ar = (AsyncResult) msg.obj;
1017 request = (MainThreadRequest) ar.userObj;
1018 if (ar.exception != null) {
1019 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1020 } else {
1021 request.result = ((int[]) ar.result)[0];
1022 }
1023 notifyRequester(request);
1024 break;
1025 case CMD_SET_CDMA_ROAMING_MODE:
1026 request = (MainThreadRequest) msg.obj;
1027 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1028 int mode = (int) request.argument;
1029 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1030 break;
1031 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1032 ar = (AsyncResult) msg.obj;
1033 request = (MainThreadRequest) ar.userObj;
1034 request.result = ar.exception == null;
1035 notifyRequester(request);
1036 break;
1037 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1038 request = (MainThreadRequest) msg.obj;
1039 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1040 int subscriptionMode = (int) request.argument;
1041 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1042 break;
1043 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
1046 request.result = ar.exception == null;
1047 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001048 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001049 case CMD_GET_ALL_CELL_INFO:
1050 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001052 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001053 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001054 case EVENT_GET_ALL_CELL_INFO_DONE:
1055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001057 // If a timeout occurs, the response will be null
1058 request.result = (ar.exception == null && ar.result != null)
1059 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 synchronized (request) {
1061 request.notifyAll();
1062 }
1063 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001064 case CMD_REQUEST_CELL_INFO_UPDATE:
1065 request = (MainThreadRequest) msg.obj;
1066 request.phone.requestCellInfoUpdate(request.workSource,
1067 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1068 break;
1069 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1070 ar = (AsyncResult) msg.obj;
1071 request = (MainThreadRequest) ar.userObj;
1072 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1073 try {
1074 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001076 cb.onError(
1077 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1078 ar.exception.getClass().getName(),
1079 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001080 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001081 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001082 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001083 } else {
1084 // use the result as returned
1085 cb.onCellInfo((List<CellInfo>) ar.result);
1086 }
1087 } catch (RemoteException re) {
1088 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1089 }
1090 break;
1091 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001092 request = (MainThreadRequest) msg.obj;
1093 WorkSource ws = (WorkSource) request.argument;
1094 Phone phone = getPhoneFromRequest(request);
1095 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1096 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001097 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001098 ar = (AsyncResult) msg.obj;
1099 request = (MainThreadRequest) ar.userObj;
1100 if (ar.exception == null) {
1101 request.result = ar.result;
1102 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001103 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001104 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1105 ? new CdmaCellLocation() : new GsmCellLocation();
1106 }
1107
1108 synchronized (request) {
1109 request.notifyAll();
1110 }
1111 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001112 case CMD_MODEM_REBOOT:
1113 request = (MainThreadRequest) msg.obj;
1114 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001115 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001116 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001117 case EVENT_CMD_MODEM_REBOOT_DONE:
1118 handleNullReturnEvent(msg, "rebootModem");
1119 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001120 case CMD_REQUEST_ENABLE_MODEM:
1121 request = (MainThreadRequest) msg.obj;
1122 boolean enable = (boolean) request.argument;
1123 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001124 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001125 PhoneConfigurationManager.getInstance()
1126 .enablePhone(request.phone, enable, onCompleted);
1127 break;
1128 case EVENT_ENABLE_MODEM_DONE:
1129 ar = (AsyncResult) msg.obj;
1130 request = (MainThreadRequest) ar.userObj;
1131 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001132 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001133 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001134 if ((boolean) request.result) {
1135 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1136 updateModemStateMetrics();
1137 } else {
1138 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1139 + ar.exception);
1140 }
1141 notifyRequester(request);
1142 break;
1143 case CMD_GET_MODEM_STATUS:
1144 request = (MainThreadRequest) msg.obj;
1145 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1146 PhoneConfigurationManager.getInstance()
1147 .getPhoneStatusFromModem(request.phone, onCompleted);
1148 break;
1149 case EVENT_GET_MODEM_STATUS_DONE:
1150 ar = (AsyncResult) msg.obj;
1151 request = (MainThreadRequest) ar.userObj;
1152 int id = request.phone.getPhoneId();
1153 if (ar.exception == null && ar.result != null) {
1154 request.result = ar.result;
1155 //update the cache as modem status has changed
1156 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1157 (boolean) request.result);
1158 } else {
1159 // Return true if modem status cannot be retrieved. For most cases,
1160 // modem status is on. And for older version modems, GET_MODEM_STATUS
1161 // and disable modem are not supported. Modem is always on.
1162 // TODO: this should be fixed in R to support a third
1163 // status UNKNOWN b/131631629
1164 request.result = true;
1165 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1166 + ar.exception);
1167 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001168 notifyRequester(request);
1169 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001170 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1171 ar = (AsyncResult) msg.obj;
1172 request = (MainThreadRequest) ar.userObj;
1173 if (ar.exception == null && ar.result != null) {
1174 request.result = ar.result;
1175 } else {
1176 request.result = -1;
1177 loge("Failed to set Forbidden Plmns");
1178 if (ar.result == null) {
1179 loge("setForbidenPlmns: Empty response");
1180 } else if (ar.exception != null) {
1181 loge("setForbiddenPlmns: Exception: " + ar.exception);
1182 request.result = -1;
1183 } else {
1184 loge("setForbiddenPlmns: Unknown exception");
1185 }
1186 }
1187 notifyRequester(request);
1188 break;
1189 case CMD_SET_FORBIDDEN_PLMNS:
1190 request = (MainThreadRequest) msg.obj;
1191 uiccCard = getUiccCardFromRequest(request);
1192 if (uiccCard == null) {
1193 loge("setForbiddenPlmns: UiccCard is null");
1194 request.result = -1;
1195 notifyRequester(request);
1196 break;
1197 }
1198 Pair<Integer, List<String>> setFplmnsArgs =
1199 (Pair<Integer, List<String>>) request.argument;
1200 appType = setFplmnsArgs.first;
1201 List<String> fplmns = setFplmnsArgs.second;
1202 uiccApp = uiccCard.getApplicationByType(appType);
1203 if (uiccApp == null) {
1204 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1205 request.result = -1;
1206 loge("Failed to get UICC App");
1207 notifyRequester(request);
1208 } else {
1209 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1210 ((SIMRecords) uiccApp.getIccRecords())
1211 .setForbiddenPlmns(onCompleted, fplmns);
1212 }
1213 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001214 default:
1215 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1216 break;
1217 }
1218 }
Jake Hambye994d462014-02-03 13:10:13 -08001219
Pengquan Menga1bb6272018-09-06 09:59:22 -07001220 private void notifyRequester(MainThreadRequest request) {
1221 synchronized (request) {
1222 request.notifyAll();
1223 }
1224 }
1225
Jake Hambye994d462014-02-03 13:10:13 -08001226 private void handleNullReturnEvent(Message msg, String command) {
1227 AsyncResult ar = (AsyncResult) msg.obj;
1228 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1229 if (ar.exception == null) {
1230 request.result = true;
1231 } else {
1232 request.result = false;
1233 if (ar.exception instanceof CommandException) {
1234 loge(command + ": CommandException: " + ar.exception);
1235 } else {
1236 loge(command + ": Unknown exception");
1237 }
1238 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001239 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001241 }
1242
1243 /**
1244 * Posts the specified command to be executed on the main thread,
1245 * waits for the request to complete, and returns the result.
1246 * @see #sendRequestAsync
1247 */
1248 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001249 return sendRequest(
1250 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001251 }
1252
1253 /**
1254 * Posts the specified command to be executed on the main thread,
1255 * waits for the request to complete, and returns the result.
1256 * @see #sendRequestAsync
1257 */
1258 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1259 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001260 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001261 }
1262
1263 /**
1264 * Posts the specified command to be executed on the main thread,
1265 * waits for the request to complete, and returns the result.
1266 * @see #sendRequestAsync
1267 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001268 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001269 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001270 }
1271
1272 /**
1273 * Posts the specified command to be executed on the main thread,
1274 * waits for the request to complete, and returns the result.
1275 * @see #sendRequestAsync
1276 */
Nathan Harold92bed182018-10-12 18:16:49 -07001277 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1278 return sendRequest(command, argument, subId, null, workSource);
1279 }
1280
1281 /**
1282 * Posts the specified command to be executed on the main thread,
1283 * waits for the request to complete, and returns the result.
1284 * @see #sendRequestAsync
1285 */
1286 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1287 return sendRequest(
1288 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1289 }
1290
1291 /**
1292 * Posts the specified command to be executed on the main thread,
1293 * waits for the request to complete, and returns the result.
1294 * @see #sendRequestAsync
1295 */
1296 private Object sendRequest(
1297 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001298 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1299 throw new RuntimeException("This method will deadlock if called from the main thread.");
1300 }
1301
Nathan Harold92bed182018-10-12 18:16:49 -07001302 MainThreadRequest request = null;
1303 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1304 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1305 } else if (phone != null) {
1306 request = new MainThreadRequest(argument, phone, workSource);
1307 } else {
1308 request = new MainThreadRequest(argument, subId, workSource);
1309 }
1310
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 Message msg = mMainThreadHandler.obtainMessage(command, request);
1312 msg.sendToTarget();
1313
1314 // Wait for the request to complete
1315 synchronized (request) {
1316 while (request.result == null) {
1317 try {
1318 request.wait();
1319 } catch (InterruptedException e) {
1320 // Do nothing, go back and wait until the request is complete
1321 }
1322 }
1323 }
1324 return request.result;
1325 }
1326
1327 /**
1328 * Asynchronous ("fire and forget") version of sendRequest():
1329 * Posts the specified command to be executed on the main thread, and
1330 * returns immediately.
1331 * @see #sendRequest
1332 */
1333 private void sendRequestAsync(int command) {
1334 mMainThreadHandler.sendEmptyMessage(command);
1335 }
1336
1337 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001338 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001339 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001340 */
1341 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001342 sendRequestAsync(command, argument, null, null);
1343 }
1344
1345 /**
1346 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1347 * @see {@link #sendRequest(int,Object)}
1348 */
1349 private void sendRequestAsync(
1350 int command, Object argument, Phone phone, WorkSource workSource) {
1351 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001352 Message msg = mMainThreadHandler.obtainMessage(command, request);
1353 msg.sendToTarget();
1354 }
1355
1356 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001357 * Initialize the singleton PhoneInterfaceManager instance.
1358 * This is only done once, at startup, from PhoneApp.onCreate().
1359 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001360 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 synchronized (PhoneInterfaceManager.class) {
1362 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001363 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364 } else {
1365 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1366 }
1367 return sInstance;
1368 }
1369 }
1370
1371 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001372 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001373 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001375 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1377 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001378 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001379 mTelephonySharedPreferences =
1380 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001381 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001382 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001383
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 publish();
1385 }
1386
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001387 private Phone getDefaultPhone() {
1388 Phone thePhone = getPhone(getDefaultSubscription());
1389 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1390 }
1391
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 private void publish() {
1393 if (DBG) log("publish: " + this);
1394
1395 ServiceManager.addService("phone", this);
1396 }
1397
Stuart Scott584921c2015-01-15 17:10:34 -08001398 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001399 if (request.phone != null) {
1400 return request.phone;
1401 } else {
1402 return getPhoneFromSubId(request.subId);
1403 }
1404 }
1405
1406 private Phone getPhoneFromSubId(int subId) {
1407 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1408 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001409 }
1410
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001411 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1412 Phone phone = getPhoneFromRequest(request);
1413 return phone == null ? null :
1414 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1415 }
1416
Wink Saville36469e72014-06-11 15:17:00 -07001417 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001418 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001419 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001421
1422 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001423 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001424 }
1425
Wink Savilleb564aae2014-10-23 10:18:09 -07001426 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427 if (DBG) log("dial: " + number);
1428 // No permission check needed here: This is just a wrapper around the
1429 // ACTION_DIAL intent, which is available to any app since it puts up
1430 // the UI before it does anything.
1431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001432 final long identity = Binder.clearCallingIdentity();
1433 try {
1434 String url = createTelUrl(number);
1435 if (url == null) {
1436 return;
1437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001439 // PENDING: should we just silently fail if phone is offhook or ringing?
1440 PhoneConstants.State state = mCM.getState(subId);
1441 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1442 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1443 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1444 mApp.startActivity(intent);
1445 }
1446 } finally {
1447 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 }
1449 }
1450
1451 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001452 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001453 }
1454
Wink Savilleb564aae2014-10-23 10:18:09 -07001455 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 if (DBG) log("call: " + number);
1457
1458 // This is just a wrapper around the ACTION_CALL intent, but we still
1459 // need to do a permission check since we're calling startActivity()
1460 // from the context of the phone app.
1461 enforceCallPermission();
1462
Jordan Liu1617b712019-07-10 15:06:26 -07001463 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001464 != AppOpsManager.MODE_ALLOWED) {
1465 return;
1466 }
1467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001468 final long identity = Binder.clearCallingIdentity();
1469 try {
1470 String url = createTelUrl(number);
1471 if (url == null) {
1472 return;
1473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001475 boolean isValid = false;
1476 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1477 if (slist != null) {
1478 for (SubscriptionInfo subInfoRecord : slist) {
1479 if (subInfoRecord.getSubscriptionId() == subId) {
1480 isValid = true;
1481 break;
1482 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001483 }
Wink Saville08874612014-08-31 19:19:58 -07001484 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001485 if (!isValid) {
1486 return;
1487 }
Wink Saville08874612014-08-31 19:19:58 -07001488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001489 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1490 intent.putExtra(SUBSCRIPTION_KEY, subId);
1491 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1492 mApp.startActivity(intent);
1493 } finally {
1494 Binder.restoreCallingIdentity(identity);
1495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 }
1497
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001499 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001500 }
1501
Wink Savilleb564aae2014-10-23 10:18:09 -07001502 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001503 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001504 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1505 }
1506
1507 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001508 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001509 }
1510
Wink Savilleb564aae2014-10-23 10:18:09 -07001511 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001512 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001513 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1514 }
1515
1516 /** {@hide} */
1517 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001518 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001519 }
1520
Wink Savilleb564aae2014-10-23 10:18:09 -07001521 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001523
1524 final long identity = Binder.clearCallingIdentity();
1525 try {
1526 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1527 checkSimPin.start();
1528 return checkSimPin.unlockSim(null, pin);
1529 } finally {
1530 Binder.restoreCallingIdentity(identity);
1531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532 }
1533
Wink Saville9de0f752013-10-22 19:04:03 -07001534 /** {@hide} */
1535 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001537 }
1538
Wink Savilleb564aae2014-10-23 10:18:09 -07001539 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001540 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001541
1542 final long identity = Binder.clearCallingIdentity();
1543 try {
1544 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1545 checkSimPuk.start();
1546 return checkSimPuk.unlockSim(puk, pin);
1547 } finally {
1548 Binder.restoreCallingIdentity(identity);
1549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001550 }
1551
1552 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001553 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 * a synchronous one.
1555 */
1556 private static class UnlockSim extends Thread {
1557
1558 private final IccCard mSimCard;
1559
1560 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001561 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1562 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563
1564 // For replies from SimCard interface
1565 private Handler mHandler;
1566
1567 // For async handler to identify request type
1568 private static final int SUPPLY_PIN_COMPLETE = 100;
1569
1570 public UnlockSim(IccCard simCard) {
1571 mSimCard = simCard;
1572 }
1573
1574 @Override
1575 public void run() {
1576 Looper.prepare();
1577 synchronized (UnlockSim.this) {
1578 mHandler = new Handler() {
1579 @Override
1580 public void handleMessage(Message msg) {
1581 AsyncResult ar = (AsyncResult) msg.obj;
1582 switch (msg.what) {
1583 case SUPPLY_PIN_COMPLETE:
1584 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1585 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001586 mRetryCount = msg.arg1;
1587 if (ar.exception != null) {
1588 if (ar.exception instanceof CommandException &&
1589 ((CommandException)(ar.exception)).getCommandError()
1590 == CommandException.Error.PASSWORD_INCORRECT) {
1591 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1592 } else {
1593 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1594 }
1595 } else {
1596 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 mDone = true;
1599 UnlockSim.this.notifyAll();
1600 }
1601 break;
1602 }
1603 }
1604 };
1605 UnlockSim.this.notifyAll();
1606 }
1607 Looper.loop();
1608 }
1609
1610 /*
1611 * Use PIN or PUK to unlock SIM card
1612 *
1613 * If PUK is null, unlock SIM card with PIN
1614 *
1615 * If PUK is not null, unlock SIM card with PUK and set PIN code
1616 */
Wink Saville9de0f752013-10-22 19:04:03 -07001617 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618
1619 while (mHandler == null) {
1620 try {
1621 wait();
1622 } catch (InterruptedException e) {
1623 Thread.currentThread().interrupt();
1624 }
1625 }
1626 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1627
1628 if (puk == null) {
1629 mSimCard.supplyPin(pin, callback);
1630 } else {
1631 mSimCard.supplyPuk(puk, pin, callback);
1632 }
1633
1634 while (!mDone) {
1635 try {
1636 Log.d(LOG_TAG, "wait for done");
1637 wait();
1638 } catch (InterruptedException e) {
1639 // Restore the interrupted status
1640 Thread.currentThread().interrupt();
1641 }
1642 }
1643 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001644 int[] resultArray = new int[2];
1645 resultArray[0] = mResult;
1646 resultArray[1] = mRetryCount;
1647 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 }
1649 }
1650
1651 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001652 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001653
1654 }
1655
Wink Savilleb564aae2014-10-23 10:18:09 -07001656 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 // No permission check needed here: this call is harmless, and it's
1658 // needed for the ServiceState.requestStateUpdate() call (which is
1659 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001660 final long identity = Binder.clearCallingIdentity();
1661 try {
1662 final Phone phone = getPhone(subId);
1663 if (phone != null) {
1664 phone.updateServiceLocation();
1665 }
1666 } finally {
1667 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669 }
1670
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001671 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001672 @Override
1673 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001674 return isRadioOnWithFeature(callingPackage, null);
1675 }
1676
1677
1678 @Override
1679 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1680 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1681 callingFeatureId);
1682 }
1683
1684 @Deprecated
1685 @Override
1686 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1687 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001688 }
1689
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001690 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001691 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1692 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001694 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001695 return false;
1696 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001697
1698 final long identity = Binder.clearCallingIdentity();
1699 try {
1700 return isRadioOnForSubscriber(subId);
1701 } finally {
1702 Binder.restoreCallingIdentity(identity);
1703 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001704 }
1705
1706 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001707 final long identity = Binder.clearCallingIdentity();
1708 try {
1709 final Phone phone = getPhone(subId);
1710 if (phone != null) {
1711 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1712 } else {
1713 return false;
1714 }
1715 } finally {
1716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 }
1719
1720 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001721 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001722 }
Wink Saville36469e72014-06-11 15:17:00 -07001723
Wink Savilleb564aae2014-10-23 10:18:09 -07001724 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001726
1727 final long identity = Binder.clearCallingIdentity();
1728 try {
1729 final Phone phone = getPhone(subId);
1730 if (phone != null) {
1731 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1732 }
1733 } finally {
1734 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001735 }
Wink Saville36469e72014-06-11 15:17:00 -07001736 }
1737
1738 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001739 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001740 }
1741
Wink Savilleb564aae2014-10-23 10:18:09 -07001742 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001743 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001744
1745 final long identity = Binder.clearCallingIdentity();
1746 try {
1747 final Phone phone = getPhone(subId);
1748 if (phone == null) {
1749 return false;
1750 }
1751 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1752 toggleRadioOnOffForSubscriber(subId);
1753 }
1754 return true;
1755 } finally {
1756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 }
Wink Saville36469e72014-06-11 15:17:00 -07001759
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001760 public boolean needMobileRadioShutdown() {
1761 /*
1762 * If any of the Radios are available, it will need to be
1763 * shutdown. So return true if any Radio is available.
1764 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001765 final long identity = Binder.clearCallingIdentity();
1766 try {
1767 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1768 Phone phone = PhoneFactory.getPhone(i);
1769 if (phone != null && phone.isRadioAvailable()) return true;
1770 }
1771 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1772 return false;
1773 } finally {
1774 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001775 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001776 }
1777
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001778 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001779 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001780 enforceModifyPermission();
1781
1782 final long identity = Binder.clearCallingIdentity();
1783 try {
1784 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1785 logv("Shutting down Phone " + i);
1786 shutdownRadioUsingPhoneId(i);
1787 }
1788 } finally {
1789 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001790 }
1791 }
1792
1793 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001794 Phone phone = PhoneFactory.getPhone(phoneId);
1795 if (phone != null && phone.isRadioAvailable()) {
1796 phone.shutdownRadio();
1797 }
1798 }
1799
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001800 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001801 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001802
1803 final long identity = Binder.clearCallingIdentity();
1804 try {
1805 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1806 if (defaultPhone != null) {
1807 defaultPhone.setRadioPower(turnOn);
1808 return true;
1809 } else {
1810 loge("There's no default phone.");
1811 return false;
1812 }
1813 } finally {
1814 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001815 }
Wink Saville36469e72014-06-11 15:17:00 -07001816 }
1817
Wink Savilleb564aae2014-10-23 10:18:09 -07001818 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001820
1821 final long identity = Binder.clearCallingIdentity();
1822 try {
1823 final Phone phone = getPhone(subId);
1824 if (phone != null) {
1825 phone.setRadioPower(turnOn);
1826 return true;
1827 } else {
1828 return false;
1829 }
1830 } finally {
1831 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001832 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 }
1834
Wink Saville36469e72014-06-11 15:17:00 -07001835 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001836 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001837 public boolean enableDataConnectivity() {
1838 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001839
1840 final long identity = Binder.clearCallingIdentity();
1841 try {
1842 int subId = mSubscriptionController.getDefaultDataSubId();
1843 final Phone phone = getPhone(subId);
1844 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001845 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001846 return true;
1847 } else {
1848 return false;
1849 }
1850 } finally {
1851 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001852 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 }
1854
Wink Saville36469e72014-06-11 15:17:00 -07001855 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001856 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 public boolean disableDataConnectivity() {
1858 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001859
1860 final long identity = Binder.clearCallingIdentity();
1861 try {
1862 int subId = mSubscriptionController.getDefaultDataSubId();
1863 final Phone phone = getPhone(subId);
1864 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001865 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001866 return true;
1867 } else {
1868 return false;
1869 }
1870 } finally {
1871 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 }
1874
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001876 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001877 final long identity = Binder.clearCallingIdentity();
1878 try {
1879 final Phone phone = getPhone(subId);
1880 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001881 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001882 } else {
1883 return false;
1884 }
1885 } finally {
1886 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001887 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 }
1889
1890 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001891 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001892 }
1893
pkanwarae03a6b2016-11-06 20:37:09 -08001894 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001895 enforceCallPermission();
1896
1897 final long identity = Binder.clearCallingIdentity();
1898 try {
1899 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1900 return;
1901 }
1902 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1903 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1904 } finally {
1905 Binder.restoreCallingIdentity(identity);
1906 }
pkanwar32d516d2016-10-14 19:37:38 -07001907 };
1908
Wink Savilleb564aae2014-10-23 10:18:09 -07001909 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001911
1912 final long identity = Binder.clearCallingIdentity();
1913 try {
1914 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1915 return false;
1916 }
1917 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1918 } finally {
1919 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 }
1922
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001924 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001925 }
1926
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001927 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001928 final long identity = Binder.clearCallingIdentity();
1929 try {
1930 Phone phone = PhoneFactory.getPhone(slotIndex);
1931 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1932 PhoneConstantConversions.convertCallState(phone.getState());
1933 } finally {
1934 Binder.restoreCallingIdentity(identity);
1935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
Sanket Padawe356d7632015-06-22 14:03:32 -07001938 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001939 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001940 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1941 }
1942
1943 @Override
1944 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001945 final long identity = Binder.clearCallingIdentity();
1946 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001947 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001948 if (phone != null) {
1949 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1950 } else {
1951 return PhoneConstantConversions.convertDataState(
1952 PhoneConstants.DataState.DISCONNECTED);
1953 }
1954 } finally {
1955 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 }
1958
Sanket Padawe356d7632015-06-22 14:03:32 -07001959 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001960 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001961 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1962 }
1963
1964 @Override
1965 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001966 final long identity = Binder.clearCallingIdentity();
1967 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001968 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001969 if (phone != null) {
1970 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1971 } else {
1972 return TelephonyManager.DATA_ACTIVITY_NONE;
1973 }
1974 } finally {
1975 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 }
1978
1979 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07001980 public Bundle getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001981 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001982 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001983
1984 LocationAccessPolicy.LocationPermissionResult locationResult =
1985 LocationAccessPolicy.checkLocationPermission(mApp,
1986 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1987 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07001988 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08001989 .setCallingPid(Binder.getCallingPid())
1990 .setCallingUid(Binder.getCallingUid())
1991 .setMethod("getCellLocation")
1992 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1993 .build());
1994 switch (locationResult) {
1995 case DENIED_HARD:
1996 throw new SecurityException("Not allowed to access cell location");
1997 case DENIED_SOFT:
1998 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 }
2000
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002001 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002002 final long identity = Binder.clearCallingIdentity();
2003 try {
2004 if (DBG_LOC) log("getCellLocation: is active user");
2005 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002006 int subId = mSubscriptionController.getDefaultDataSubId();
2007 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2008 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002009 return data;
2010 } finally {
2011 Binder.restoreCallingIdentity(identity);
2012 }
Svetoslav64fad262015-04-14 14:35:21 -07002013 }
2014
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002016 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2017 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002018 if (!TextUtils.isEmpty(callingPackage)) {
2019 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2021 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002022 return "";
2023 }
2024 }
2025
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002026 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2027 // registered cell info, so return a NULL country instead.
2028 final long identity = Binder.clearCallingIdentity();
2029 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002030 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2031 // Get default phone in this case.
2032 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2033 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002034 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002035 // Todo: fix this when we can get the actual cellular network info when the device
2036 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002037 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002038 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2039 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002040 return "";
2041 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002042 Phone phone = PhoneFactory.getPhone(phoneId);
2043 if (phone != null) {
2044 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002045 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002046 if (sst != null) {
2047 LocaleTracker lt = sst.getLocaleTracker();
2048 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002049 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2050 return lt.getCurrentCountry();
2051 } else if (emergencyNumberTracker != null) {
2052 return emergencyNumberTracker.getEmergencyCountryIso();
2053 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054 }
2055 }
2056 }
2057 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002058 } finally {
2059 Binder.restoreCallingIdentity(identity);
2060 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002061 }
2062
2063 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002065 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002066 }
2067
Sanket Padawe356d7632015-06-22 14:03:32 -07002068 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002069 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002070 mApp.enforceCallingOrSelfPermission(
2071 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072
2073 final long identity = Binder.clearCallingIdentity();
2074 try {
2075 final Phone phone = getPhone(subId);
2076 if (phone != null) {
2077 phone.enableLocationUpdates();
2078 }
2079 } finally {
2080 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 }
2083
2084 @Override
2085 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002086 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002087 }
2088
Sanket Padawe356d7632015-06-22 14:03:32 -07002089 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002090 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 mApp.enforceCallingOrSelfPermission(
2092 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002093
2094 final long identity = Binder.clearCallingIdentity();
2095 try {
2096 final Phone phone = getPhone(subId);
2097 if (phone != null) {
2098 phone.disableLocationUpdates();
2099 }
2100 } finally {
2101 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002102 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103 }
2104
Nathan Harold31d7ff32018-10-15 20:20:30 -07002105 /**
2106 * Returns the target SDK version number for a given package name.
2107 *
Nathan Haroldec184742019-07-10 17:04:16 -07002108 * This call MUST be invoked before clearing the calling UID.
2109 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002110 * @return target SDK if the package is found or INT_MAX.
2111 */
2112 private int getTargetSdk(String packageName) {
2113 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002114 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002115 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002116 if (ai != null) return ai.targetSdkVersion;
2117 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002118 loge("Failed to get package info for pkg="
2119 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002120 }
2121 return Integer.MAX_VALUE;
2122 }
2123
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124 @Override
2125 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002126 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2127 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002128 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002129 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2130 throw new SecurityException(
2131 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2132 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002133
Jordan Liu1617b712019-07-10 15:06:26 -07002134 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2136 return null;
2137 }
Svetoslav64fad262015-04-14 14:35:21 -07002138
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002139 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002141 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002142 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143
Nathan Haroldf180aac2018-06-01 18:43:55 -07002144 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2145 for (CellInfo ci : info) {
2146 if (ci instanceof CellInfoGsm) {
2147 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2148 } else if (ci instanceof CellInfoWcdma) {
2149 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2150 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002152 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 }
2154
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002155 private List<CellInfo> getCachedCellInfo() {
2156 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2157 for (Phone phone : PhoneFactory.getPhones()) {
2158 List<CellInfo> info = phone.getAllCellInfo();
2159 if (info != null) cellInfos.addAll(info);
2160 }
2161 return cellInfos;
2162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163
2164 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002165 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002166 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002167 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002168
2169 LocationAccessPolicy.LocationPermissionResult locationResult =
2170 LocationAccessPolicy.checkLocationPermission(mApp,
2171 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2172 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002173 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002174 .setCallingPid(Binder.getCallingPid())
2175 .setCallingUid(Binder.getCallingUid())
2176 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002177 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002178 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2179 .build());
2180 switch (locationResult) {
2181 case DENIED_HARD:
2182 throw new SecurityException("Not allowed to access cell info");
2183 case DENIED_SOFT:
2184 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002187 final int targetSdk = getTargetSdk(callingPackage);
2188 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2189 return getCachedCellInfo();
2190 }
2191
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002192 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002193 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002194 final long identity = Binder.clearCallingIdentity();
2195 try {
2196 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2197 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002198 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002199 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002200 if (info != null) cellInfos.addAll(info);
2201 }
2202 return cellInfos;
2203 } finally {
2204 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002205 }
2206 }
2207
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002208 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002209 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2210 String callingFeatureId) {
2211 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2212 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002213 }
2214
2215 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002216 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2217 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002218 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002219 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002220 }
2221
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002222 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2223 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002224 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002225 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002226
2227 LocationAccessPolicy.LocationPermissionResult locationResult =
2228 LocationAccessPolicy.checkLocationPermission(mApp,
2229 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2230 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002231 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002232 .setCallingPid(Binder.getCallingPid())
2233 .setCallingUid(Binder.getCallingUid())
2234 .setMethod("requestCellInfoUpdate")
2235 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2236 .build());
2237 switch (locationResult) {
2238 case DENIED_HARD:
2239 throw new SecurityException("Not allowed to access cell info");
2240 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002241 try {
2242 cb.onCellInfo(new ArrayList<CellInfo>());
2243 } catch (RemoteException re) {
2244 // Drop without consequences
2245 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002246 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002247 }
2248
Nathan Harolda939a962019-05-09 10:13:47 -07002249
2250 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002251 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2252
2253 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2254 }
2255
2256 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002258 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002259 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260
2261 final long identity = Binder.clearCallingIdentity();
2262 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002263 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264 } finally {
2265 Binder.restoreCallingIdentity(identity);
2266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268
Shishir Agrawala9f32182016-04-12 12:00:16 -07002269 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002270 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002271 Phone phone = PhoneFactory.getPhone(slotIndex);
2272 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002273 return null;
2274 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002275 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002276 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002277 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002278 return null;
2279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002280
2281 final long identity = Binder.clearCallingIdentity();
2282 try {
2283 return phone.getImei();
2284 } finally {
2285 Binder.restoreCallingIdentity(identity);
2286 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002287 }
2288
2289 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002290 public String getTypeAllocationCodeForSlot(int slotIndex) {
2291 Phone phone = PhoneFactory.getPhone(slotIndex);
2292 String tac = null;
2293 if (phone != null) {
2294 String imei = phone.getImei();
2295 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2296 }
2297 return tac;
2298 }
2299
2300 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002301 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002302 Phone phone = PhoneFactory.getPhone(slotIndex);
2303 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002304 return null;
2305 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002306
Jeff Davidson913390f2018-02-23 17:11:49 -08002307 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002308 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002309 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002310 return null;
2311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002312
2313 final long identity = Binder.clearCallingIdentity();
2314 try {
2315 return phone.getMeid();
2316 } finally {
2317 Binder.restoreCallingIdentity(identity);
2318 }
Jack Yu2af8d712017-03-15 17:14:14 -07002319 }
2320
2321 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002322 public String getManufacturerCodeForSlot(int slotIndex) {
2323 Phone phone = PhoneFactory.getPhone(slotIndex);
2324 String manufacturerCode = null;
2325 if (phone != null) {
2326 String meid = phone.getMeid();
2327 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2328 }
2329 return manufacturerCode;
2330 }
2331
2332 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002333 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2334 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002335 Phone phone = PhoneFactory.getPhone(slotIndex);
2336 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002337 return null;
2338 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002339 int subId = phone.getSubId();
2340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002341 mApp, subId, callingPackage, callingFeatureId,
2342 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002343 return null;
2344 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002345
2346 final long identity = Binder.clearCallingIdentity();
2347 try {
2348 return phone.getDeviceSvn();
2349 } finally {
2350 Binder.restoreCallingIdentity(identity);
2351 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002352 }
2353
fionaxu43304da2017-11-27 22:51:16 -08002354 @Override
2355 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002356 final long identity = Binder.clearCallingIdentity();
2357 try {
2358 final Phone phone = getPhone(subId);
2359 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2360 } finally {
2361 Binder.restoreCallingIdentity(identity);
2362 }
fionaxu43304da2017-11-27 22:51:16 -08002363 }
2364
2365 @Override
2366 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002367 final long identity = Binder.clearCallingIdentity();
2368 try {
2369 final Phone phone = getPhone(subId);
2370 return phone == null ? null : phone.getCarrierName();
2371 } finally {
2372 Binder.restoreCallingIdentity(identity);
2373 }
fionaxu43304da2017-11-27 22:51:16 -08002374 }
2375
calvinpanffe225e2018-11-01 19:43:06 +08002376 @Override
chen xu0026ca62019-03-06 15:28:50 -08002377 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 final Phone phone = getPhone(subId);
2381 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002382 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002383 } finally {
2384 Binder.restoreCallingIdentity(identity);
2385 }
2386 }
2387
2388 @Override
chen xu0026ca62019-03-06 15:28:50 -08002389 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002390 final long identity = Binder.clearCallingIdentity();
2391 try {
2392 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002393 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002394 } finally {
2395 Binder.restoreCallingIdentity(identity);
2396 }
2397 }
2398
chen xu651eec72018-11-11 19:03:44 -08002399 @Override
chen xu864e11c2018-12-06 22:10:03 -08002400 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2401 if (!isSubscriptionMccMnc) {
2402 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2403 }
chen xu651eec72018-11-11 19:03:44 -08002404 final Phone phone = PhoneFactory.getPhone(slotIndex);
2405 if (phone == null) {
2406 return TelephonyManager.UNKNOWN_CARRIER_ID;
2407 }
2408 final long identity = Binder.clearCallingIdentity();
2409 try {
2410 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2411 } finally {
2412 Binder.restoreCallingIdentity(identity);
2413 }
2414 }
2415
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 //
2417 // Internal helper methods.
2418 //
2419
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002420 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2422 *
2423 * @throws SecurityException if the caller does not have the required permission
2424 */
2425 private void enforceModifyPermission() {
2426 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2427 }
2428
Shuo Qian3b6ee772019-11-13 17:43:31 -08002429 private void enforceActiveEmergencySessionPermission() {
2430 mApp.enforceCallingOrSelfPermission(
2431 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2432 }
2433
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002434 /**
2435 * Make sure the caller has the CALL_PHONE permission.
2436 *
2437 * @throws SecurityException if the caller does not have the required permission
2438 */
2439 private void enforceCallPermission() {
2440 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2441 }
2442
Stuart Scott8eef64f2015-04-08 15:13:54 -07002443 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002444 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002445 "ConnectivityService");
2446 }
2447
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 private String createTelUrl(String number) {
2449 if (TextUtils.isEmpty(number)) {
2450 return null;
2451 }
2452
Jake Hambye994d462014-02-03 13:10:13 -08002453 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 }
2455
Ihab Awadf9e92732013-12-05 18:02:52 -08002456 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2458 }
2459
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002460 private static void logv(String msg) {
2461 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2462 }
2463
Ihab Awadf9e92732013-12-05 18:02:52 -08002464 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2466 }
2467
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002468 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002470 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002471 }
2472
Sanket Padawe356d7632015-06-22 14:03:32 -07002473 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002474 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002475 final long identity = Binder.clearCallingIdentity();
2476 try {
2477 final Phone phone = PhoneFactory.getPhone(slotIndex);
2478 if (phone == null) {
2479 return PhoneConstants.PHONE_TYPE_NONE;
2480 } else {
2481 return phone.getPhoneType();
2482 }
2483 } finally {
2484 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 }
2487
2488 /**
2489 * Returns the CDMA ERI icon index to display
2490 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002491 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002492 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2493 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2494 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002495 }
2496
Sanket Padawe356d7632015-06-22 14:03:32 -07002497 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002498 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2499 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002500 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002501 mApp, subId, callingPackage, callingFeatureId,
2502 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002503 return -1;
2504 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 final Phone phone = getPhone(subId);
2509 if (phone != null) {
2510 return phone.getCdmaEriIconIndex();
2511 } else {
2512 return -1;
2513 }
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
2519 /**
2520 * Returns the CDMA ERI icon mode,
2521 * 0 - ON
2522 * 1 - FLASHING
2523 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002524 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002525 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2526 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2527 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002528 }
2529
Sanket Padawe356d7632015-06-22 14:03:32 -07002530 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002531 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2532 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002533 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002534 mApp, subId, callingPackage, callingFeatureId,
2535 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002536 return -1;
2537 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002538
2539 final long identity = Binder.clearCallingIdentity();
2540 try {
2541 final Phone phone = getPhone(subId);
2542 if (phone != null) {
2543 return phone.getCdmaEriIconMode();
2544 } else {
2545 return -1;
2546 }
2547 } finally {
2548 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002550 }
2551
2552 /**
2553 * Returns the CDMA ERI text,
2554 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002555 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002556 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2557 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2558 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002559 }
2560
Sanket Padawe356d7632015-06-22 14:03:32 -07002561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002562 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2563 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002565 mApp, subId, callingPackage, callingFeatureId,
2566 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002567 return null;
2568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 final Phone phone = getPhone(subId);
2573 if (phone != null) {
2574 return phone.getCdmaEriText();
2575 } else {
2576 return null;
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 }
2582
2583 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002584 * Returns the CDMA MDN.
2585 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002586 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002587 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2589 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590
2591 final long identity = Binder.clearCallingIdentity();
2592 try {
2593 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002594 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 return phone.getLine1Number();
2596 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002597 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 return null;
2599 }
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002602 }
2603 }
2604
2605 /**
2606 * Returns the CDMA MIN.
2607 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002608 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002609 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2611 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612
2613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 final Phone phone = getPhone(subId);
2616 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2617 return phone.getCdmaMin();
2618 } else {
2619 return null;
2620 }
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002623 }
2624 }
2625
Hall Liud892bec2018-11-30 14:51:45 -08002626 @Override
2627 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2628 INumberVerificationCallback callback, String callingPackage) {
2629 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2630 != PERMISSION_GRANTED) {
2631 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2632 }
2633 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2634
2635 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2636 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2637 throw new SecurityException("Calling package must be configured in the device config");
2638 }
2639
2640 if (range == null) {
2641 throw new NullPointerException("Range must be non-null");
2642 }
2643
2644 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002645 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002646
2647 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2648 }
2649
Junda Liuca05d5d2014-08-14 22:36:34 -07002650 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 * Returns true if CDMA provisioning needs to run.
2652 */
2653 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 final long identity = Binder.clearCallingIdentity();
2655 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002656 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 } finally {
2658 Binder.restoreCallingIdentity(identity);
2659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660 }
2661
2662 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002663 * Sets the voice mail number of a given subId.
2664 */
2665 @Override
2666 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002667 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668
2669 final long identity = Binder.clearCallingIdentity();
2670 try {
2671 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2672 new Pair<String, String>(alphaTag, number), new Integer(subId));
2673 return success;
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
2676 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002677 }
2678
Ta-wei Yen87c49842016-05-13 21:19:52 -07002679 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002680 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2681 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002682 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2683 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002684 if (!TextUtils.equals(callingPackage, systemDialer)) {
2685 throw new SecurityException("caller must be system dialer");
2686 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2691 if (phoneAccountHandle == null) {
2692 return null;
2693 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002694 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695 } finally {
2696 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002697 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002698 }
2699
2700 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002701 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2702 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002705 mApp, subId, callingPackage, callingFeatureId,
2706 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002707 return null;
2708 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002710 final long identity = Binder.clearCallingIdentity();
2711 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002712 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002713 } finally {
2714 Binder.restoreCallingIdentity(identity);
2715 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002716 }
2717
2718 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002719 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2720 VisualVoicemailSmsFilterSettings settings) {
2721 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722
2723 final long identity = Binder.clearCallingIdentity();
2724 try {
2725 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002726 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 } finally {
2728 Binder.restoreCallingIdentity(identity);
2729 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002730 }
2731
2732 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002733 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735
2736 final long identity = Binder.clearCallingIdentity();
2737 try {
2738 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002739 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740 } finally {
2741 Binder.restoreCallingIdentity(identity);
2742 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002743 }
2744
2745 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002746 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2747 String callingPackage, int subId) {
2748 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002753 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754 } finally {
2755 Binder.restoreCallingIdentity(identity);
2756 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002757 }
2758
2759 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002760 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002761 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002766 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767 } finally {
2768 Binder.restoreCallingIdentity(identity);
2769 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002770 }
2771
2772 @Override
2773 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2774 String number, int port, String text, PendingIntent sentIntent) {
2775 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002776 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002777 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002778 SmsController smsController = PhoneFactory.getSmsController();
2779 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2780 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002781 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002782
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002783 /**
fionaxu0152e512016-11-14 13:36:14 -08002784 * Sets the voice activation state of a given subId.
2785 */
2786 @Override
2787 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2789 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790
2791 final long identity = Binder.clearCallingIdentity();
2792 try {
2793 final Phone phone = getPhone(subId);
2794 if (phone != null) {
2795 phone.setVoiceActivationState(activationState);
2796 } else {
2797 loge("setVoiceActivationState fails with invalid subId: " + subId);
2798 }
2799 } finally {
2800 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002801 }
2802 }
2803
2804 /**
2805 * Sets the data activation state of a given subId.
2806 */
2807 @Override
2808 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2810 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811
2812 final long identity = Binder.clearCallingIdentity();
2813 try {
2814 final Phone phone = getPhone(subId);
2815 if (phone != null) {
2816 phone.setDataActivationState(activationState);
2817 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002818 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819 }
2820 } finally {
2821 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002822 }
2823 }
2824
2825 /**
2826 * Returns the voice activation state of a given subId.
2827 */
2828 @Override
2829 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002830 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002831
fionaxu0152e512016-11-14 13:36:14 -08002832 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833 final long identity = Binder.clearCallingIdentity();
2834 try {
2835 if (phone != null) {
2836 return phone.getVoiceActivationState();
2837 } else {
2838 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2839 }
2840 } finally {
2841 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002842 }
2843 }
2844
2845 /**
2846 * Returns the data activation state of a given subId.
2847 */
2848 @Override
2849 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002850 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851
fionaxu0152e512016-11-14 13:36:14 -08002852 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 if (phone != null) {
2856 return phone.getDataActivationState();
2857 } else {
2858 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2859 }
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002862 }
2863 }
2864
2865 /**
Wink Saville36469e72014-06-11 15:17:00 -07002866 * Returns the unread count of voicemails for a subId
2867 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002868 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002869 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2870 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002871 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002872 mApp, subId, callingPackage, callingFeatureId,
2873 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002874 return 0;
2875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 final long identity = Binder.clearCallingIdentity();
2877 try {
2878 final Phone phone = getPhone(subId);
2879 if (phone != null) {
2880 return phone.getVoiceMessageCount();
2881 } else {
2882 return 0;
2883 }
2884 } finally {
2885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002887 }
2888
2889 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002890 * returns true, if the device is in a state where both voice and data
2891 * are supported simultaneously. This can change based on location or network condition.
2892 */
2893 @Override
2894 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002895 final long identity = Binder.clearCallingIdentity();
2896 try {
2897 final Phone phone = getPhone(subId);
2898 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2899 } finally {
2900 Binder.restoreCallingIdentity(identity);
2901 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002902 }
2903
2904 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002905 * Send the dialer code if called from the current default dialer or the caller has
2906 * carrier privilege.
2907 * @param inputCode The dialer code to send
2908 */
2909 @Override
2910 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002911 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002913 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2914 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002915 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002916 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2917 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919
2920 final long identity = Binder.clearCallingIdentity();
2921 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002922 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923 } finally {
2924 Binder.restoreCallingIdentity(identity);
2925 }
fionaxu235cc5e2017-03-06 22:25:57 -08002926 }
2927
Pengquan Menga1bb6272018-09-06 09:59:22 -07002928 @Override
2929 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002930 if (!isActiveSubscription(subId)) {
2931 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2932 }
2933
Pengquan Menga1bb6272018-09-06 09:59:22 -07002934 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2935 }
2936
Brad Ebinger35c841c2018-10-01 10:40:55 -07002937 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002938 public boolean isInEmergencySmsMode() {
2939 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2940 final long identity = Binder.clearCallingIdentity();
2941 try {
2942 for (Phone phone : PhoneFactory.getPhones()) {
2943 if (phone.isInEmergencySmsMode()) {
2944 return true;
2945 }
2946 }
2947 } finally {
2948 Binder.restoreCallingIdentity(identity);
2949 }
2950 return false;
2951 }
2952
2953 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002954 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2955 throws RemoteException {
2956 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002957 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2958 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2959 "IMS not available on device.");
2960 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002961 final long token = Binder.clearCallingIdentity();
2962 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002964 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002965 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002966 } catch (ImsException e) {
2967 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002968 } finally {
2969 Binder.restoreCallingIdentity(token);
2970 }
2971 }
2972
2973 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002974 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2975 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002976 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2977 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2978 }
Meng Wangafbc5852019-09-19 17:37:13 -07002979 final long token = Binder.clearCallingIdentity();
2980 try {
2981 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2982 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2983 .removeRegistrationCallbackForSubscription(c, subId);
2984 } catch (ImsException e) {
2985 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2986 + "is inactive, ignoring unregister.");
2987 // If the subscription is no longer active, just return, since the callback
2988 // will already have been removed internally.
2989 } finally {
2990 Binder.restoreCallingIdentity(token);
2991 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002992 }
2993
Brad Ebingera34a6c22019-10-22 17:36:18 -07002994 /**
2995 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2996 */
2997 @Override
2998 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2999 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3000 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3001 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3002 "IMS not available on device.");
3003 }
3004 final long token = Binder.clearCallingIdentity();
3005 try {
3006 Phone phone = getPhone(subId);
3007 if (phone == null) {
3008 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3009 + subId + "'");
3010 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3011 }
3012 phone.getImsRegistrationState(regState -> {
3013 try {
3014 consumer.accept((regState == null)
3015 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3016 } catch (RemoteException e) {
3017 // Ignore if the remote process is no longer available to call back.
3018 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3019 }
3020 });
3021 } finally {
3022 Binder.restoreCallingIdentity(token);
3023 }
3024 }
3025
3026 /**
3027 * Get the transport type for the IMS service registration state.
3028 */
3029 @Override
3030 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3031 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3032 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3033 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3034 "IMS not available on device.");
3035 }
3036 final long token = Binder.clearCallingIdentity();
3037 try {
3038 Phone phone = getPhone(subId);
3039 if (phone == null) {
3040 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3041 + subId + "'");
3042 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3043 }
3044 phone.getImsRegistrationTech(regTech -> {
3045 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3046 int regTechConverted = (regTech == null)
3047 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3048 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3049 regTechConverted);
3050 try {
3051 consumer.accept(regTechConverted);
3052 } catch (RemoteException e) {
3053 // Ignore if the remote process is no longer available to call back.
3054 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3055 }
3056 });
3057 } finally {
3058 Binder.restoreCallingIdentity(token);
3059 }
3060 }
3061
Brad Ebinger35c841c2018-10-01 10:40:55 -07003062 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003063 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3064 throws RemoteException {
3065 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003066 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3067 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3068 "IMS not available on device.");
3069 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3071 final long token = Binder.clearCallingIdentity();
3072 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003073 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003074 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003075 } catch (ImsException e) {
3076 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003077 } finally {
3078 Binder.restoreCallingIdentity(token);
3079 }
3080 }
3081
3082 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003083 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3084 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003085 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3086 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3087 }
Meng Wangafbc5852019-09-19 17:37:13 -07003088
3089 final long token = Binder.clearCallingIdentity();
3090 try {
3091 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3092 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003093 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003094 } catch (ImsException e) {
3095 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3096 + "is inactive, ignoring unregister.");
3097 // If the subscription is no longer active, just return, since the callback
3098 // will already have been removed internally.
3099 } finally {
3100 Binder.restoreCallingIdentity(token);
3101 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003102 }
3103
3104 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003105 public boolean isCapable(int subId, int capability, int regTech) {
3106 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003107 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3108 final long token = Binder.clearCallingIdentity();
3109 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003110 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003111 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003112 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003113 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3114 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003115 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003116 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3117 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003118 } finally {
3119 Binder.restoreCallingIdentity(token);
3120 }
3121 }
3122
3123 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003124 public boolean isAvailable(int subId, int capability, int regTech) {
3125 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003126 final long token = Binder.clearCallingIdentity();
3127 try {
3128 Phone phone = getPhone(subId);
3129 if (phone == null) return false;
3130 return phone.isImsCapabilityAvailable(capability, regTech);
3131 } finally {
3132 Binder.restoreCallingIdentity(token);
3133 }
3134 }
3135
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003136 /**
3137 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3138 * subscription.
3139 * @param subId The subscription to use to check the configuration.
3140 * @param callback The callback that will be used to send the result.
3141 * @param capability The MmTelFeature capability that will be used to send the result.
3142 * @param transportType The transport type of the MmTelFeature capability.
3143 */
3144 @Override
3145 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3146 int transportType) {
3147 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3148 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3149 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3150 "IMS not available on device.");
3151 }
3152 final long token = Binder.clearCallingIdentity();
3153 try {
3154 int slotId = getSlotIndex(subId);
3155 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3156 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3157 + subId + "'");
3158 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3159 }
3160 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3161 transportType, aBoolean -> {
3162 try {
3163 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3164 } catch (RemoteException e) {
3165 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3166 + "running. Ignore");
3167 }
3168 });
3169 } finally {
3170 Binder.restoreCallingIdentity(token);
3171 }
3172 }
3173
Brad Ebinger35c841c2018-10-01 10:40:55 -07003174 @Override
3175 public boolean isAdvancedCallingSettingEnabled(int subId) {
3176 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3177 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3178 final long token = Binder.clearCallingIdentity();
3179 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003180 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003181 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003182 } catch (ImsException e) {
3183 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003184 } finally {
3185 Binder.restoreCallingIdentity(token);
3186 }
3187 }
3188
3189 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003190 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003192 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003193 final long identity = Binder.clearCallingIdentity();
3194 try {
3195 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003196 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003197 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003198 } catch (ImsException e) {
3199 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003200 } finally {
3201 Binder.restoreCallingIdentity(identity);
3202 }
3203 }
3204
3205 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003206 public boolean isVtSettingEnabled(int subId) {
3207 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003211 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3212 } catch (ImsException e) {
3213 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003214 } finally {
3215 Binder.restoreCallingIdentity(identity);
3216 }
3217 }
3218
3219 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003220 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003222 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003226 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003227 } catch (ImsException e) {
3228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
3232 }
3233
3234 @Override
3235 public boolean isVoWiFiSettingEnabled(int subId) {
3236 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003240 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003242 } catch (ImsException e) {
3243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 } finally {
3245 Binder.restoreCallingIdentity(identity);
3246 }
3247 }
3248
3249 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003250 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003252 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003253 final long identity = Binder.clearCallingIdentity();
3254 try {
3255 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003256 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003257 } catch (ImsException e) {
3258 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003259 } finally {
3260 Binder.restoreCallingIdentity(identity);
3261 }
3262 }
3263
3264 @Override
3265 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3266 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3267 final long identity = Binder.clearCallingIdentity();
3268 try {
3269 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003270 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003271 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003272 } catch (ImsException e) {
3273 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 } finally {
3275 Binder.restoreCallingIdentity(identity);
3276 }
3277 }
3278
3279 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003280 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003282 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003283 final long identity = Binder.clearCallingIdentity();
3284 try {
3285 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003286 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003287 getSlotIndexOrException(subId)).setWfcRoamingSetting(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 void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3298 "setVoWiFiNonPersistent");
3299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003302 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003303 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003304 } catch (ImsException e) {
3305 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003306 } finally {
3307 Binder.restoreCallingIdentity(identity);
3308 }
3309 }
3310
3311 @Override
3312 public int getVoWiFiModeSetting(int subId) {
3313 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003317 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003318 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
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 setVoWiFiModeSetting(int subId, int mode) {
3328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3329 "setVoWiFiModeSetting");
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 Ebinger35c841c2018-10-01 10:40:55 -07003334 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
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 getVoWiFiRoamingModeSetting(int subId) {
3344 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
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(true /*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 setVoWiFiRoamingModeSetting(int subId, int mode) {
3359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3360 "setVoWiFiRoamingModeSetting");
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, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003366 } catch (ImsException e) {
3367 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003368 } finally {
3369 Binder.restoreCallingIdentity(identity);
3370 }
3371 }
3372
3373 @Override
3374 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3376 "setRttCapabilityEnabled");
3377 final long identity = Binder.clearCallingIdentity();
3378 try {
3379 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003380 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3381 } 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 boolean isTtyOverVolteEnabled(int subId) {
3390 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3391 final long identity = Binder.clearCallingIdentity();
3392 try {
3393 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003394 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003395 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003396 } catch (ImsException e) {
3397 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003398 } finally {
3399 Binder.restoreCallingIdentity(identity);
3400 }
3401 }
3402
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003403 @Override
3404 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3405 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003409 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003410 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003411 } catch (ImsException e) {
3412 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003413 } finally {
3414 Binder.restoreCallingIdentity(identity);
3415 }
3416 }
3417
3418 @Override
3419 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3420 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3421 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003422 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3423 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3424 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003425 try {
3426 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003427 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003428 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003429 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003430 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3431 + "is inactive, ignoring unregister.");
3432 // If the subscription is no longer active, just return, since the callback will already
3433 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003434 } finally {
3435 Binder.restoreCallingIdentity(identity);
3436 }
3437 }
3438
3439 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003440 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3441 boolean isProvisioned) {
3442 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3443 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3444 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3445 }
3446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3447 "setProvisioningStatusForCapability");
3448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3451 Phone phone = getPhone(subId);
3452 if (phone == null) {
3453 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3454 + subId);
3455 return;
3456 }
3457 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3458 return;
3459 }
3460
3461 // this capability requires provisioning, route to the correct API.
3462 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3463 switch (capability) {
3464 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3465 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3466 ims.setVolteProvisioned(isProvisioned);
3467 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3468 ims.setWfcProvisioned(isProvisioned);
3469 }
3470 break;
3471 }
3472 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3473 // There is currently no difference in VT provisioning type.
3474 ims.setVtProvisioned(isProvisioned);
3475 break;
3476 }
3477 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3478 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3479 // change the capability of the feature instead if needed.
3480 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3481 == isProvisioned) {
3482 // No change in provisioning.
3483 return;
3484 }
3485 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3486 try {
3487 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003488 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003489 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3490 + ", Exception" + e.getMessage());
3491 }
3492 break;
3493 }
3494 default: {
3495 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3496 + capability + "', which does not require provisioning.");
3497 }
3498 }
3499
3500 } finally {
3501 Binder.restoreCallingIdentity(identity);
3502 }
3503 }
3504
3505 @Override
3506 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3507 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3508 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3509 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3510 }
3511 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3512 final long identity = Binder.clearCallingIdentity();
3513 try {
3514 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3515 Phone phone = getPhone(subId);
3516 if (phone == null) {
3517 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3518 + subId);
3519 // We will fail with "true" as the provisioning status because this is the default
3520 // if we do not require provisioning.
3521 return true;
3522 }
3523
3524 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3525 return true;
3526 }
3527
3528 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3529 switch (capability) {
3530 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3531 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3532 return ims.isVolteProvisionedOnDevice();
3533 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3534 return ims.isWfcProvisionedOnDevice();
3535 }
3536 // This should never happen, since we are checking tech above to make sure it
3537 // is either LTE or IWLAN.
3538 throw new IllegalArgumentException("Invalid radio technology for voice "
3539 + "capability.");
3540 }
3541 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3542 // There is currently no difference in VT provisioning type.
3543 return ims.isVtProvisionedOnDevice();
3544 }
3545 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3546 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3547 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3548 }
3549 default: {
3550 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3551 + capability + "', which does not require provisioning.");
3552 }
3553 }
3554
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
3558 }
3559
3560 @Override
3561 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3562 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3563 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3564 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3565 }
3566 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3567 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3568 return (provisionedBits & capability) > 0;
3569 }
3570
3571 @Override
3572 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3573 boolean isProvisioned) {
3574 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3575 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3576 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3577 }
3578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3579 "setProvisioningStatusForCapability");
3580 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3581 // If the current provisioning status for capability already matches isProvisioned,
3582 // do nothing.
3583 if (((provisionedBits & capability) > 0) == isProvisioned) {
3584 return;
3585 }
3586 if (isProvisioned) {
3587 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3588 } else {
3589 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3590 }
3591 }
3592
3593 /**
3594 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3595 * technology. The bitfield should mirror the bitfield defined by
3596 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3597 */
3598 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3599 String key = getMmTelProvisioningKey(subId, tech);
3600 // Default is no capabilities are provisioned.
3601 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3602 }
3603
3604 /**
3605 * Sets the MmTel capability provisioning bitfield (defined by
3606 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3607 * technology specified.
3608 *
3609 * Note: This is a synchronous command and should not be called on UI thread.
3610 */
3611 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3612 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3613 String key = getMmTelProvisioningKey(subId, tech);
3614 editor.putInt(key, newField);
3615 editor.commit();
3616 }
3617
3618 private static String getMmTelProvisioningKey(int subId, int tech) {
3619 // resulting key is provision_ims_mmtel_{subId}_{tech}
3620 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3621 }
3622
3623 /**
3624 * Query CarrierConfig to see if the specified capability requires provisioning for the
3625 * carrier associated with the subscription id.
3626 */
3627 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3628 int capability) {
3629 CarrierConfigManager configManager = new CarrierConfigManager(context);
3630 PersistableBundle c = configManager.getConfigForSubId(subId);
3631 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003632 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003633 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3634 false);
3635 boolean requireVoiceVtProvisioning = c.getBoolean(
3636 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3637
3638 // First check to make sure that the capability requires provisioning.
3639 switch (capability) {
3640 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3641 // intentional fallthrough
3642 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3643 if (requireVoiceVtProvisioning) {
3644 // Voice and Video requires provisioning
3645 return true;
3646 }
3647 break;
3648 }
3649 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3650 if (requireUtProvisioning) {
3651 // UT requires provisioning
3652 return true;
3653 }
3654 break;
3655 }
3656 }
3657 return false;
3658 }
3659
3660 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003661 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003662 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3663 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3664 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003665 enforceReadPrivilegedPermission("getImsProvisioningInt");
3666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003669 int slotId = getSlotIndex(subId);
3670 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3671 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3672 + subId + "' for key:" + key);
3673 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3674 }
3675 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003676 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003677 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3678 + subId + "' for key:" + key);
3679 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
3683 }
3684
3685 @Override
3686 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003687 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3688 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3689 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003690 enforceReadPrivilegedPermission("getImsProvisioningString");
3691 final long identity = Binder.clearCallingIdentity();
3692 try {
3693 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003694 int slotId = getSlotIndex(subId);
3695 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3696 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3697 + subId + "' for key:" + key);
3698 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3699 }
3700 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003701 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003702 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3703 + subId + "' for key:" + key);
3704 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003705 } finally {
3706 Binder.restoreCallingIdentity(identity);
3707 }
3708 }
3709
3710 @Override
3711 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003712 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3713 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3714 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3716 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003720 int slotId = getSlotIndex(subId);
3721 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3722 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3723 + subId + "' for key:" + key);
3724 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3725 }
3726 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003727 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003728 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3729 + "' for key:" + key);
3730 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003731 } finally {
3732 Binder.restoreCallingIdentity(identity);
3733 }
3734 }
3735
3736 @Override
3737 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003738 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3739 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3740 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3742 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003746 int slotId = getSlotIndex(subId);
3747 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3748 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3749 + subId + "' for key:" + key);
3750 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3751 }
3752 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003753 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003754 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3755 + "' for key:" + key);
3756 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003757 } finally {
3758 Binder.restoreCallingIdentity(identity);
3759 }
3760 }
3761
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003762 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003763 int slotId = SubscriptionManager.getSlotIndex(subId);
3764 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003765 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3766 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003767 }
3768 return slotId;
3769 }
3770
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003771 private int getSlotIndex(int subId) {
3772 int slotId = SubscriptionManager.getSlotIndex(subId);
3773 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3774 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3775 }
3776 return slotId;
3777 }
3778
Wink Saville36469e72014-06-11 15:17:00 -07003779 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003780 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003781 */
3782 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003783 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3784 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003785 final int targetSdk = getTargetSdk(callingPackage);
3786 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003787 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003788 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003789 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003790 mApp, subId, callingPackage, callingFeatureId,
3791 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003792 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3793 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795 final long identity = Binder.clearCallingIdentity();
3796 try {
3797 final Phone phone = getPhone(subId);
3798 if (phone != null) {
3799 return phone.getServiceState().getDataNetworkType();
3800 } else {
3801 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3802 }
3803 } finally {
3804 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003805 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003806 }
3807
3808 /**
3809 * Returns the data network type
3810 */
3811 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003812 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3813 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3814 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003815 }
3816
3817 /**
3818 * Returns the data network type for a subId
3819 */
3820 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003821 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3822 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003823 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003824 mApp, subId, callingPackage, callingFeatureId,
3825 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003826 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3827 }
3828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003829 final long identity = Binder.clearCallingIdentity();
3830 try {
3831 final Phone phone = getPhone(subId);
3832 if (phone != null) {
3833 return phone.getServiceState().getDataNetworkType();
3834 } else {
3835 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3836 }
3837 } finally {
3838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003840 }
3841
3842 /**
Wink Saville36469e72014-06-11 15:17:00 -07003843 * Returns the Voice network type for a subId
3844 */
3845 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003846 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3847 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003848 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003849 mApp, subId, callingPackage, callingFeatureId,
3850 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003851 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3852 }
3853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003854 final long identity = Binder.clearCallingIdentity();
3855 try {
3856 final Phone phone = getPhone(subId);
3857 if (phone != null) {
3858 return phone.getServiceState().getVoiceNetworkType();
3859 } else {
3860 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3861 }
3862 } finally {
3863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003865 }
3866
3867 /**
3868 * @return true if a ICC card is present
3869 */
3870 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003871 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003872 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3873 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003874 }
3875
3876 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003877 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003878 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003879 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003880 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003881 final long identity = Binder.clearCallingIdentity();
3882 try {
3883 final Phone phone = PhoneFactory.getPhone(slotIndex);
3884 if (phone != null) {
3885 return phone.getIccCard().hasIccCard();
3886 } else {
3887 return false;
3888 }
3889 } finally {
3890 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003892 }
3893
3894 /**
3895 * Return if the current radio is LTE on CDMA. This
3896 * is a tri-state return value as for a period of time
3897 * the mode may be unknown.
3898 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003899 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003900 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003901 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003902 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003903 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003904 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3905 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3906 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003907 }
3908
Sanket Padawe356d7632015-06-22 14:03:32 -07003909 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003910 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3911 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003912 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003913 mApp, subId, callingPackage, callingFeatureId,
3914 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003915 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3916 }
3917
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003918 final long identity = Binder.clearCallingIdentity();
3919 try {
3920 final Phone phone = getPhone(subId);
3921 if (phone == null) {
3922 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3923 } else {
3924 return phone.getLteOnCdmaMode();
3925 }
3926 } finally {
3927 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003928 }
Wink Saville36469e72014-06-11 15:17:00 -07003929 }
3930
Wink Saville36469e72014-06-11 15:17:00 -07003931 /**
3932 * {@hide}
3933 * Returns Default subId, 0 in the case of single standby.
3934 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003935 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003936 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003937 }
3938
Shishir Agrawala9f32182016-04-12 12:00:16 -07003939 private int getSlotForDefaultSubscription() {
3940 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3941 }
3942
Wink Savilleb564aae2014-10-23 10:18:09 -07003943 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003944 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003945 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003946
Pengquan Menge92a50d2018-09-21 15:54:48 -07003947 private boolean isActiveSubscription(int subId) {
3948 return mSubscriptionController.isActiveSubId(subId);
3949 }
3950
Ihab Awadf2177b72013-11-25 13:33:23 -08003951 /**
3952 * @see android.telephony.TelephonyManager.WifiCallingChoices
3953 */
3954 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003955 final long identity = Binder.clearCallingIdentity();
3956 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003957 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003958 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3959 getWhenToMakeWifiCallsDefaultPreference());
3960 } finally {
3961 Binder.restoreCallingIdentity(identity);
3962 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003963 }
3964
3965 /**
3966 * @see android.telephony.TelephonyManager.WifiCallingChoices
3967 */
3968 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003969 final long identity = Binder.clearCallingIdentity();
3970 try {
3971 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003972 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3974 } finally {
3975 Binder.restoreCallingIdentity(identity);
3976 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003977 }
3978
Sailesh Nepald1e68152013-12-12 19:08:02 -08003979 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003980 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003981 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003982 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003983
Jordan Liu4c733742019-02-28 12:03:40 -08003984 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3985 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3986 if (phoneId == -1) {
3987 throw new IllegalArgumentException("Given slot index: " + slotIndex
3988 + " does not correspond to an active phone");
3989 }
3990 return PhoneFactory.getPhone(phoneId);
3991 }
3992
Shishir Agrawal566b7612013-10-28 14:41:00 -07003993 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003994 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3995 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3997 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003998 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003999 if (DBG) {
4000 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4001 }
4002 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4003 p2);
4004 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004005
Jordan Liu4c733742019-02-28 12:03:40 -08004006
4007 @Override
4008 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4009 int slotIndex, String callingPackage, String aid, int p2) {
4010 enforceModifyPermission();
4011 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4012 if (DBG) {
4013 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4014 }
4015 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4016 callingPackage, aid, p2);
4017 }
4018
4019 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4020 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004021 final long identity = Binder.clearCallingIdentity();
4022 try {
4023 if (TextUtils.equals(ISDR_AID, aid)) {
4024 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004025 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4026 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004027 if (bestComponent == null
4028 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4029 loge("The calling package is not allowed to access ISD-R.");
4030 throw new SecurityException(
4031 "The calling package is not allowed to access ISD-R.");
4032 }
Derek Tan740e1672017-06-27 14:56:27 -07004033 }
Derek Tan740e1672017-06-27 14:56:27 -07004034
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004035 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004036 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4037 null /* workSource */);
4038 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004039 return response;
4040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004043 }
4044
4045 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004046 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4048 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004049 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4050 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4051 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004052
Jordan Liu4c733742019-02-28 12:03:40 -08004053 @Override
4054 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4055 enforceModifyPermission();
4056 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4057 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4058 channel);
4059 }
4060
4061 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004062 final long identity = Binder.clearCallingIdentity();
4063 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004064 if (channel < 0) {
4065 return false;
4066 }
Jordan Liu4c733742019-02-28 12:03:40 -08004067 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4068 null /* workSource */);
4069 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070 return success;
4071 } finally {
4072 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004073 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004074 }
4075
4076 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004077 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004078 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4080 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004081 if (DBG) {
4082 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4083 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4084 + p3 + " data=" + data);
4085 }
4086 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4087 command, p1, p2, p3, data);
4088 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004089
Jordan Liu4c733742019-02-28 12:03:40 -08004090 @Override
4091 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4092 int command, int p1, int p2, int p3, String data) {
4093 enforceModifyPermission();
4094 if (DBG) {
4095 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4096 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4097 + p3 + " data=" + data);
4098 }
4099 return iccTransmitApduLogicalChannelWithPermission(
4100 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4101 data);
4102 }
4103
4104 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4105 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004106 final long identity = Binder.clearCallingIdentity();
4107 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004108 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004109 return "";
4110 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004113 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4114 null /* workSource */);
4115 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117 // Append the returned status code to the end of the response payload.
4118 String s = Integer.toHexString(
4119 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4120 if (response.payload != null) {
4121 s = IccUtils.bytesToHexString(response.payload) + s;
4122 }
4123 return s;
4124 } finally {
4125 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004126 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004127 }
Jake Hambye994d462014-02-03 13:10:13 -08004128
Evan Charltonc66da362014-05-16 14:06:40 -07004129 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004130 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4131 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004132 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4133 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004134 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004135 if (DBG) {
4136 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4137 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4138 }
4139 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4140 cla, command, p1, p2, p3, data);
4141 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004142
Jordan Liu4c733742019-02-28 12:03:40 -08004143 @Override
4144 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4145 int command, int p1, int p2, int p3, String data) {
4146 enforceModifyPermission();
4147 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4148 if (DBG) {
4149 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4150 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4151 + " data=" + data);
4152 }
4153
4154 return iccTransmitApduBasicChannelWithPermission(
4155 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4156 p2, p3, data);
4157 }
4158
4159 // open APDU basic channel assuming the caller has sufficient permissions
4160 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4161 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004162 final long identity = Binder.clearCallingIdentity();
4163 try {
4164 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4165 && TextUtils.equals(ISDR_AID, data)) {
4166 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004167 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4168 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004169 if (bestComponent == null
4170 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4171 loge("The calling package is not allowed to select ISD-R.");
4172 throw new SecurityException(
4173 "The calling package is not allowed to select ISD-R.");
4174 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004175 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004176
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004178 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4179 null /* workSource */);
4180 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004182 // Append the returned status code to the end of the response payload.
4183 String s = Integer.toHexString(
4184 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4185 if (response.payload != null) {
4186 s = IccUtils.bytesToHexString(response.payload) + s;
4187 }
4188 return s;
4189 } finally {
4190 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004191 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004192 }
4193
4194 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004195 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004196 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4198 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004200 final long identity = Binder.clearCallingIdentity();
4201 try {
4202 if (DBG) {
4203 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4204 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4205 }
4206
4207 IccIoResult response =
4208 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4209 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4210 subId);
4211
4212 if (DBG) {
4213 log("Exchange SIM_IO [R]" + response);
4214 }
4215
4216 byte[] result = null;
4217 int length = 2;
4218 if (response.payload != null) {
4219 length = 2 + response.payload.length;
4220 result = new byte[length];
4221 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4222 } else {
4223 result = new byte[length];
4224 }
4225
4226 result[length - 1] = (byte) response.sw2;
4227 result[length - 2] = (byte) response.sw1;
4228 return result;
4229 } finally {
4230 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004231 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004232 }
4233
Nathan Haroldb3014052017-01-25 15:57:32 -08004234 /**
4235 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4236 * on a particular subscription
4237 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004238 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4239 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004241 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004242 return null;
4243 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004244
4245 final long identity = Binder.clearCallingIdentity();
4246 try {
4247 if (appType != TelephonyManager.APPTYPE_USIM
4248 && appType != TelephonyManager.APPTYPE_SIM) {
4249 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4250 return null;
4251 }
4252 Object response = sendRequest(
4253 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4254 if (response instanceof String[]) {
4255 return (String[]) response;
4256 }
yincheng zhao2737e882019-09-06 17:06:54 -07004257 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004258 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004259 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 } finally {
4261 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004262 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004263 }
4264
yincheng zhao2737e882019-09-06 17:06:54 -07004265 /**
4266 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4267 * subscription.
4268 *
4269 * @param subId the id of the subscription.
4270 * @param appType the uicc app type, must be USIM or SIM.
4271 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4272 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004273 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004274 * @return number of fplmns that is successfully written to the SIM.
4275 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004276 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4277 String callingFeatureId) {
4278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4279 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004280 if (DBG) logv("no permissions for setForbiddenplmns");
4281 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4282 }
4283 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4284 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4285 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4286 }
4287 if (fplmns == null) {
4288 throw new IllegalArgumentException("Fplmn List provided is null");
4289 }
4290 for (String fplmn : fplmns) {
4291 if (!CellIdentity.isValidPlmn(fplmn)) {
4292 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4293 }
4294 }
4295 final long identity = Binder.clearCallingIdentity();
4296 try {
4297 Object response = sendRequest(
4298 CMD_SET_FORBIDDEN_PLMNS,
4299 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4300 subId);
4301 return (int) response;
4302 } finally {
4303 Binder.restoreCallingIdentity(identity);
4304 }
4305 }
4306
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004307 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004308 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4310 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004311
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004312 final long identity = Binder.clearCallingIdentity();
4313 try {
4314 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4315 if (response.payload == null) {
4316 return "";
4317 }
Evan Charltonc66da362014-05-16 14:06:40 -07004318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004319 // Append the returned status code to the end of the response payload.
4320 String s = Integer.toHexString(
4321 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4322 s = IccUtils.bytesToHexString(response.payload) + s;
4323 return s;
4324 } finally {
4325 Binder.restoreCallingIdentity(identity);
4326 }
Evan Charltonc66da362014-05-16 14:06:40 -07004327 }
4328
Jake Hambye994d462014-02-03 13:10:13 -08004329 /**
4330 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4331 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4332 *
4333 * @param itemID the ID of the item to read
4334 * @return the NV item as a String, or null on error.
4335 */
4336 @Override
4337 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004338 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4340 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004341
4342 final long identity = Binder.clearCallingIdentity();
4343 try {
4344 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004345 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004346 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4347 return value;
4348 } finally {
4349 Binder.restoreCallingIdentity(identity);
4350 }
Jake Hambye994d462014-02-03 13:10:13 -08004351 }
4352
4353 /**
4354 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4355 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4356 *
4357 * @param itemID the ID of the item to read
4358 * @param itemValue the value to write, as a String
4359 * @return true on success; false on any failure
4360 */
4361 @Override
4362 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004363 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4365 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366
4367 final long identity = Binder.clearCallingIdentity();
4368 try {
4369 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4370 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004371 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004372 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4373 return success;
4374 } finally {
4375 Binder.restoreCallingIdentity(identity);
4376 }
Jake Hambye994d462014-02-03 13:10:13 -08004377 }
4378
4379 /**
4380 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4381 * Used for device configuration by some CDMA operators.
4382 *
4383 * @param preferredRoamingList byte array containing the new PRL
4384 * @return true on success; false on any failure
4385 */
4386 @Override
4387 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4389 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004390
4391 final long identity = Binder.clearCallingIdentity();
4392 try {
4393 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4394 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4395 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4396 return success;
4397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
Jake Hambye994d462014-02-03 13:10:13 -08004400 }
4401
4402 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004403 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004404 * Used for device configuration by some CDMA operators.
4405 *
chen xu6dac5ab2018-10-26 17:39:23 -07004406 * @param slotIndex - device slot.
4407 *
Jake Hambye994d462014-02-03 13:10:13 -08004408 * @return true on success; false on any failure
4409 */
4410 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004411 public boolean resetModemConfig(int slotIndex) {
4412 Phone phone = PhoneFactory.getPhone(slotIndex);
4413 if (phone != null) {
4414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4415 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004416
chen xu6dac5ab2018-10-26 17:39:23 -07004417 final long identity = Binder.clearCallingIdentity();
4418 try {
4419 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4420 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4421 return success;
4422 } finally {
4423 Binder.restoreCallingIdentity(identity);
4424 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004425 }
chen xu6dac5ab2018-10-26 17:39:23 -07004426 return false;
4427 }
4428
4429 /**
4430 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4431 *
4432 * @param slotIndex - device slot.
4433 *
4434 * @return true on success; false on any failure
4435 */
4436 @Override
4437 public boolean rebootModem(int slotIndex) {
4438 Phone phone = PhoneFactory.getPhone(slotIndex);
4439 if (phone != null) {
4440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4441 mApp, phone.getSubId(), "rebootModem");
4442
4443 final long identity = Binder.clearCallingIdentity();
4444 try {
4445 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4446 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4447 return success;
4448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
4451 }
4452 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004453 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004454
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004455 public String[] getPcscfAddress(String apnType, String callingPackage,
4456 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004457 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4459 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004460 return new String[0];
4461 }
4462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004463 final long identity = Binder.clearCallingIdentity();
4464 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004465 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
Wink Saville36469e72014-06-11 15:17:00 -07004469 }
4470
Brad Ebinger51f743a2017-01-23 13:50:20 -08004471 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004472 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4473 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004474 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004475 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004476 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477
4478 final long identity = Binder.clearCallingIdentity();
4479 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004480 ImsResolver resolver = PhoneFactory.getImsResolver();
4481 if (resolver == null) {
4482 // may happen if the device does not support IMS.
4483 return;
4484 }
4485 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004489 }
4490
4491 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004492 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4493 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004494 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004495 public void disableIms(int slotId) {
4496 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004497
4498 final long identity = Binder.clearCallingIdentity();
4499 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004500 ImsResolver resolver = PhoneFactory.getImsResolver();
4501 if (resolver == null) {
4502 // may happen if the device does not support IMS.
4503 return;
4504 }
4505 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004506 } finally {
4507 Binder.restoreCallingIdentity(identity);
4508 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004509 }
4510
4511 /**
4512 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4513 * feature or {@link null} if the service is not available. If the feature is available, the
4514 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4515 */
4516 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004517 IImsServiceFeatureCallback callback) {
4518 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519
4520 final long identity = Binder.clearCallingIdentity();
4521 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004522 ImsResolver resolver = PhoneFactory.getImsResolver();
4523 if (resolver == null) {
4524 // may happen if the device does not support IMS.
4525 return null;
4526 }
4527 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528 } finally {
4529 Binder.restoreCallingIdentity(identity);
4530 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004531 }
4532
4533 /**
4534 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4535 * feature during emergency calling or {@link null} if the service is not available. If the
4536 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4537 * listener for feature updates.
4538 */
4539 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4540 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004541
4542 final long identity = Binder.clearCallingIdentity();
4543 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004544 ImsResolver resolver = PhoneFactory.getImsResolver();
4545 if (resolver == null) {
4546 // may happen if the device does not support IMS.
4547 return null;
4548 }
4549 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004553 }
4554
Brad Ebinger5f64b052017-12-14 14:26:15 -08004555 /**
4556 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004557 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004558 */
4559 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4560 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561
4562 final long identity = Binder.clearCallingIdentity();
4563 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004564 ImsResolver resolver = PhoneFactory.getImsResolver();
4565 if (resolver == null) {
4566 // may happen if the device does not support IMS.
4567 return null;
4568 }
4569 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570 } finally {
4571 Binder.restoreCallingIdentity(identity);
4572 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004573 }
4574
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004575 /**
4576 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004577 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004578 */
4579 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4580 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581
4582 final long identity = Binder.clearCallingIdentity();
4583 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004584 ImsResolver resolver = PhoneFactory.getImsResolver();
4585 if (resolver == null) {
4586 // may happen if the device does not support IMS.
4587 return null;
4588 }
4589 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004590 } finally {
4591 Binder.restoreCallingIdentity(identity);
4592 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004593 }
4594
Brad Ebinger884c07b2018-02-15 16:17:40 -08004595 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004596 * Sets the ImsService Package Name that Telephony will bind to.
4597 *
4598 * @param slotId the slot ID that the ImsService should bind for.
4599 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4600 * ImsService is the device default ImsService.
4601 * @param packageName The package name of the application that contains the ImsService to bind
4602 * to.
4603 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4604 * @hide
4605 */
4606 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004607 int[] subIds = SubscriptionManager.getSubId(slotId);
4608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4609 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4610 "setImsService");
4611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004612 final long identity = Binder.clearCallingIdentity();
4613 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004614 ImsResolver resolver = PhoneFactory.getImsResolver();
4615 if (resolver == null) {
4616 // may happen if the device does not support IMS.
4617 return false;
4618 }
4619 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4620 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004621 } finally {
4622 Binder.restoreCallingIdentity(identity);
4623 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004624 }
4625
4626 /**
4627 * Return the ImsService configuration.
4628 *
4629 * @param slotId The slot that the ImsService is associated with.
4630 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4631 * the device default.
4632 * @return the package name of the ImsService configuration.
4633 */
4634 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004635 int[] subIds = SubscriptionManager.getSubId(slotId);
4636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4637 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4638 "getImsService");
4639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004640 final long identity = Binder.clearCallingIdentity();
4641 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004642 ImsResolver resolver = PhoneFactory.getImsResolver();
4643 if (resolver == null) {
4644 // may happen if the device does not support IMS.
4645 return "";
4646 }
4647 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004648 } finally {
4649 Binder.restoreCallingIdentity(identity);
4650 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004651 }
4652
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004653 /**
4654 * Get the MmTelFeature state associated with the requested subscription id.
4655 * @param subId The subscription that the MmTelFeature is associated with.
4656 * @param callback A callback with an integer containing the
4657 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4658 */
4659 @Override
4660 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4661 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4662 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4663 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4664 "IMS not available on device.");
4665 }
4666 final long token = Binder.clearCallingIdentity();
4667 try {
4668 int slotId = getSlotIndex(subId);
4669 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4670 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4671 + subId + "'");
4672 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4673 }
4674 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4675 try {
4676 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4677 } catch (RemoteException e) {
4678 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4679 + "Ignore");
4680 }
4681 });
4682 } finally {
4683 Binder.restoreCallingIdentity(token);
4684 }
4685 }
4686
Wink Saville36469e72014-06-11 15:17:00 -07004687 public void setImsRegistrationState(boolean registered) {
4688 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689
4690 final long identity = Binder.clearCallingIdentity();
4691 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004692 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
Wink Saville36469e72014-06-11 15:17:00 -07004696 }
4697
4698 /**
Stuart Scott54788802015-03-30 13:18:01 -07004699 * Set the network selection mode to automatic.
4700 *
4701 */
4702 @Override
4703 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4705 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004706
Pengquan Menge92a50d2018-09-21 15:54:48 -07004707 if (!isActiveSubscription(subId)) {
4708 return;
4709 }
4710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711 final long identity = Binder.clearCallingIdentity();
4712 try {
4713 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4714 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4715 } finally {
4716 Binder.restoreCallingIdentity(identity);
4717 }
Stuart Scott54788802015-03-30 13:18:01 -07004718 }
4719
Pengquan Mengea84e042018-09-20 14:57:26 -07004720 /**
4721 * Ask the radio to connect to the input network and change selection mode to manual.
4722 *
4723 * @param subId the id of the subscription.
4724 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4725 * the operator to attach to.
4726 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4727 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4728 * normal network selection next time.
4729 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004730 */
4731 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004732 public boolean setNetworkSelectionModeManual(
4733 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4735 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004736
4737 if (!isActiveSubscription(subId)) {
4738 return false;
4739 }
4740
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004741 final long identity = Binder.clearCallingIdentity();
4742 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004743 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004745 if (DBG) {
4746 log("setNetworkSelectionModeManual: subId: " + subId
4747 + " operator: " + operatorInfo);
4748 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004749 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4750 } finally {
4751 Binder.restoreCallingIdentity(identity);
4752 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004753 }
4754
4755 /**
4756 * Scans for available networks.
4757 */
4758 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004759 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4760 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004761 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4762 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004763 LocationAccessPolicy.LocationPermissionResult locationResult =
4764 LocationAccessPolicy.checkLocationPermission(mApp,
4765 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4766 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004767 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004768 .setCallingPid(Binder.getCallingPid())
4769 .setCallingUid(Binder.getCallingUid())
4770 .setMethod("getCellNetworkScanResults")
4771 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4772 .build());
4773 switch (locationResult) {
4774 case DENIED_HARD:
4775 throw new SecurityException("Not allowed to access scan results -- location");
4776 case DENIED_SOFT:
4777 return null;
4778 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004779
Pengquan Menga1bb6272018-09-06 09:59:22 -07004780 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004781 try {
4782 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004783 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004785 } finally {
4786 Binder.restoreCallingIdentity(identity);
4787 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004788 }
4789
4790 /**
yinxub1bed742017-04-17 11:45:04 -07004791 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004792 *
yinxub1bed742017-04-17 11:45:04 -07004793 * @param subId id of the subscription
4794 * @param request contains the radio access networks with bands/channels to scan
4795 * @param messenger callback messenger for scan results or errors
4796 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004797 * @return the id of the requested scan which can be used to stop the scan.
4798 */
4799 @Override
4800 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004801 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4803 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004804 LocationAccessPolicy.LocationPermissionResult locationResult =
4805 LocationAccessPolicy.checkLocationPermission(mApp,
4806 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4807 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004808 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004809 .setCallingPid(Binder.getCallingPid())
4810 .setCallingUid(Binder.getCallingUid())
4811 .setMethod("requestNetworkScan")
4812 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4813 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004814 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004815 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004816 if (e != null) {
4817 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4818 throw e;
4819 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004820 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004821 return TelephonyScanManager.INVALID_SCAN_ID;
4822 }
4823 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824 }
Hall Liu912dfd32019-04-25 14:02:26 -07004825 int callingUid = Binder.getCallingUid();
4826 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004827 final long identity = Binder.clearCallingIdentity();
4828 try {
4829 return mNetworkScanRequestTracker.startNetworkScan(
4830 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004831 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004832 } finally {
4833 Binder.restoreCallingIdentity(identity);
4834 }
yinxu504e1392017-04-12 16:03:22 -07004835 }
4836
Hall Liub2ac8ef2019-02-28 15:56:23 -08004837 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004838 NetworkScanRequest request, int subId) {
4839 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4840 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4841 boolean hasNetworkScanPermission =
4842 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4843 == PERMISSION_GRANTED;
4844
4845 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4846 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4847 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004848 }
4849
4850 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4851 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004852 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4853 return new SecurityException("Specific channels must not be"
4854 + " scanned without location access.");
4855 }
4856 }
4857 }
4858
Hall Liub2ac8ef2019-02-28 15:56:23 -08004859 return null;
4860 }
4861
yinxu504e1392017-04-12 16:03:22 -07004862 /**
4863 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004864 *
4865 * @param subId id of the subscription
4866 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004867 */
4868 @Override
4869 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4871 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004872
Hall Liu912dfd32019-04-25 14:02:26 -07004873 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 final long identity = Binder.clearCallingIdentity();
4875 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004876 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004877 } finally {
4878 Binder.restoreCallingIdentity(identity);
4879 }
yinxu504e1392017-04-12 16:03:22 -07004880 }
4881
4882 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004883 * Get the calculated preferred network type.
4884 * Used for debugging incorrect network type.
4885 *
4886 * @return the preferred network type, defined in RILConstants.java.
4887 */
4888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004889 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004890 final Phone defaultPhone = getDefaultPhone();
4891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004892 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004893 return RILConstants.PREFERRED_NETWORK_MODE;
4894 }
4895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004896 final long identity = Binder.clearCallingIdentity();
4897 try {
4898 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004899 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900 } finally {
4901 Binder.restoreCallingIdentity(identity);
4902 }
Junda Liu84d15a22014-07-02 11:21:04 -07004903 }
4904
4905 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004906 * Get the preferred network type.
4907 * Used for device configuration by some CDMA operators.
4908 *
4909 * @return the preferred network type, defined in RILConstants.java.
4910 */
4911 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004912 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004913 TelephonyPermissions
4914 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4915 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004916
4917 final long identity = Binder.clearCallingIdentity();
4918 try {
4919 if (DBG) log("getPreferredNetworkType");
4920 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4921 int networkType = (result != null ? result[0] : -1);
4922 if (DBG) log("getPreferredNetworkType: " + networkType);
4923 return networkType;
4924 } finally {
4925 Binder.restoreCallingIdentity(identity);
4926 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004927 }
4928
4929 /**
4930 * Set the preferred network type.
4931 * Used for device configuration by some CDMA operators.
4932 *
4933 * @param networkType the preferred network type, defined in RILConstants.java.
4934 * @return true on success; false on any failure.
4935 */
4936 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004937 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4939 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940
4941 final long identity = Binder.clearCallingIdentity();
4942 try {
4943 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4944 Boolean success = (Boolean) sendRequest(
4945 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4946 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4947 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004948 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4950 }
4951 return success;
4952 } finally {
4953 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004954 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004955 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004956
4957 /**
Miaoa84611c2019-03-15 09:21:10 +08004958 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004959 *
Miaoa84611c2019-03-15 09:21:10 +08004960 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004961 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004962 * @hide
4963 */
4964 @Override
SongFerngWangf3c7bf82019-11-07 17:27:26 +08004965 public boolean isTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004966 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004968 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969 try {
Miaoa84611c2019-03-15 09:21:10 +08004970 if (phone != null) {
4971 return phone.hasMatchedTetherApnSetting();
4972 } else {
4973 return false;
4974 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975 } finally {
4976 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004977 }
Junda Liu475951f2014-11-07 16:45:03 -08004978 }
4979
4980 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004981 * Set mobile data enabled
4982 * Used by the user through settings etc to turn on/off mobile data
4983 *
4984 * @param enable {@code true} turn turn data on, else {@code false}
4985 */
4986 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004987 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4989 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004990
4991 final long identity = Binder.clearCallingIdentity();
4992 try {
4993 int phoneId = mSubscriptionController.getPhoneId(subId);
4994 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4995 Phone phone = PhoneFactory.getPhone(phoneId);
4996 if (phone != null) {
4997 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004998 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005000 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 }
5002 } finally {
5003 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005004 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005005 }
5006
5007 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005008 * Get the user enabled state of Mobile Data.
5009 *
5010 * TODO: remove and use isUserDataEnabled.
5011 * This can't be removed now because some vendor codes
5012 * calls through ITelephony directly while they should
5013 * use TelephonyManager.
5014 *
5015 * @return true on enabled
5016 */
5017 @Override
5018 public boolean getDataEnabled(int subId) {
5019 return isUserDataEnabled(subId);
5020 }
5021
5022 /**
5023 * Get whether mobile data is enabled per user setting.
5024 *
5025 * There are other factors deciding whether mobile data is actually enabled, but they are
5026 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005027 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005028 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005029 *
5030 * @return {@code true} if data is enabled else {@code false}
5031 */
5032 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005033 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005034 try {
5035 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5036 null);
5037 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5039 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041
5042 final long identity = Binder.clearCallingIdentity();
5043 try {
5044 int phoneId = mSubscriptionController.getPhoneId(subId);
5045 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5046 Phone phone = PhoneFactory.getPhone(phoneId);
5047 if (phone != null) {
5048 boolean retVal = phone.isUserDataEnabled();
5049 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5050 return retVal;
5051 } else {
5052 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5053 return false;
5054 }
5055 } finally {
5056 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005057 }
5058 }
5059
5060 /**
5061 * Get whether mobile data is enabled.
5062 *
5063 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5064 * whether mobile data is actually enabled.
5065 *
5066 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5067 *
5068 * @return {@code true} if data is enabled else {@code false}
5069 */
5070 @Override
5071 public boolean isDataEnabled(int subId) {
5072 try {
5073 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5074 null);
5075 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5077 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079
5080 final long identity = Binder.clearCallingIdentity();
5081 try {
5082 int phoneId = mSubscriptionController.getPhoneId(subId);
5083 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5084 Phone phone = PhoneFactory.getPhone(phoneId);
5085 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005086 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5088 return retVal;
5089 } else {
5090 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5091 return false;
5092 }
5093 } finally {
5094 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005095 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005096 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005097
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005098 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5099 Phone phone) {
5100 //load access rules from carrier configs, and check those as well: b/139133814
5101 SubscriptionController subController = SubscriptionController.getInstance();
5102 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5103 || subController == null) return privilegeFromSim;
5104
5105 int uid = Binder.getCallingUid();
5106 PackageManager pkgMgr = phone.getContext().getPackageManager();
5107 String[] packages = pkgMgr.getPackagesForUid(uid);
5108
5109 final long identity = Binder.clearCallingIdentity();
5110 try {
5111 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5112 SubscriptionManager subManager = (SubscriptionManager)
5113 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5114 for (String pkg : packages) {
5115 if (subManager.canManageSubscription(subInfo, pkg)) {
5116 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5117 }
5118 }
5119 return privilegeFromSim;
5120 } finally {
5121 Binder.restoreCallingIdentity(identity);
5122 }
5123 }
5124
5125 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5126 String pkgName) {
5127 //load access rules from carrier configs, and check those as well: b/139133814
5128 SubscriptionController subController = SubscriptionController.getInstance();
5129 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5130 || subController == null) return privilegeFromSim;
5131
5132 final long identity = Binder.clearCallingIdentity();
5133 try {
5134 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5135 SubscriptionManager subManager = (SubscriptionManager)
5136 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5137 return subManager.canManageSubscription(subInfo, pkgName)
5138 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5139 } finally {
5140 Binder.restoreCallingIdentity(identity);
5141 }
5142 }
5143
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005144 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005145 public int getCarrierPrivilegeStatus(int subId) {
5146 final Phone phone = getPhone(subId);
5147 if (phone == null) {
5148 loge("getCarrierPrivilegeStatus: Invalid subId");
5149 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5150 }
5151 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005152 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005153 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005154 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5155 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005156
5157 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5158 card.getCarrierPrivilegeStatusForCurrentTransaction(
5159 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005160 }
Junda Liu29340342014-07-10 15:23:27 -07005161
5162 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005163 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5164 final Phone phone = getPhone(subId);
5165 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005166 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005167 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5168 }
5169 UiccProfile profile =
5170 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5171 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005172 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005173 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5174 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005175 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5176 profile.getCarrierPrivilegeStatusForUid(
5177 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005178 }
5179
5180 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005181 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5182 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005183 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005184 }
5185
5186 int phoneId = SubscriptionManager.getPhoneId(subId);
5187 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005188 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005189 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005190 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5191 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005192 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5193 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5194 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005195 }
5196
5197 @Override
5198 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005199 if (TextUtils.isEmpty(pkgName))
5200 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005201 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5202 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5203 UiccCard card = UiccController.getInstance().getUiccCard(i);
5204 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005205 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005206 continue;
5207 }
5208
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005209 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5210 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5211 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005212 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5213 break;
5214 }
5215 }
5216
5217 return result;
Junda Liu29340342014-07-10 15:23:27 -07005218 }
Derek Tan89e89d42014-07-08 17:00:10 -07005219
5220 @Override
Junda Liue64de782015-04-16 17:19:16 -07005221 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5222 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5223 loge("phoneId " + phoneId + " is not valid.");
5224 return null;
5225 }
5226 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005227 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005228 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005229 return null ;
5230 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005231 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005232 }
5233
Amith Yamasani6e118872016-02-19 12:53:51 -08005234 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005235 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005236 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005237 List<String> privilegedPackages = new ArrayList<>();
5238 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005239 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5240 // has UICC in that slot.
5241 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005242 if (card.hasCarrierPrivilegeRules()) {
5243 if (packages == null) {
5244 // Only check packages in user 0 for now
5245 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005246 PackageManager.MATCH_DISABLED_COMPONENTS
5247 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005248 | PackageManager.GET_SIGNING_CERTIFICATES,
5249 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005250 }
5251 for (int p = packages.size() - 1; p >= 0; p--) {
5252 PackageInfo pkgInfo = packages.get(p);
5253 if (pkgInfo != null && pkgInfo.packageName != null
5254 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005255 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005256 privilegedPackages.add(pkgInfo.packageName);
5257 }
5258 }
5259 }
5260 }
5261 return privilegedPackages;
5262 }
5263
chen xuf7e9fe82019-05-09 19:31:02 -07005264 @Override
5265 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5266 List<String> privilegedPackages = new ArrayList<>();
5267 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5268 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5269 }
5270 return privilegedPackages;
5271 }
5272
Wink Savilleb564aae2014-10-23 10:18:09 -07005273 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005274 final Phone phone = getPhone(subId);
5275 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005276 if (card == null) {
5277 loge("getIccId: No UICC");
5278 return null;
5279 }
5280 String iccId = card.getIccId();
5281 if (TextUtils.isEmpty(iccId)) {
5282 loge("getIccId: ICC ID is null or empty.");
5283 return null;
5284 }
5285 return iccId;
5286 }
5287
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005288 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005289 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5290 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005291 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5292 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 final long identity = Binder.clearCallingIdentity();
5295 try {
5296 final String iccId = getIccId(subId);
5297 final Phone phone = getPhone(subId);
5298 if (phone == null) {
5299 return false;
5300 }
5301 final String subscriberId = phone.getSubscriberId();
5302
5303 if (DBG_MERGE) {
5304 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5305 + subscriberId + " to " + number);
5306 }
5307
5308 if (TextUtils.isEmpty(iccId)) {
5309 return false;
5310 }
5311
5312 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5313
5314 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5315 if (alphaTag == null) {
5316 editor.remove(alphaTagPrefKey);
5317 } else {
5318 editor.putString(alphaTagPrefKey, alphaTag);
5319 }
5320
5321 // Record both the line number and IMSI for this ICCID, since we need to
5322 // track all merged IMSIs based on line number
5323 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5324 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5325 if (number == null) {
5326 editor.remove(numberPrefKey);
5327 editor.remove(subscriberPrefKey);
5328 } else {
5329 editor.putString(numberPrefKey, number);
5330 editor.putString(subscriberPrefKey, subscriberId);
5331 }
5332
5333 editor.commit();
5334 return true;
5335 } finally {
5336 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005337 }
Derek Tan7226c842014-07-02 17:42:23 -07005338 }
5339
5340 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005341 public String getLine1NumberForDisplay(int subId, String callingPackage,
5342 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005343 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005344 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005345 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005346 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005347 return null;
5348 }
Derek Tan97ebb422014-09-05 16:55:38 -07005349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350 final long identity = Binder.clearCallingIdentity();
5351 try {
5352 String iccId = getIccId(subId);
5353 if (iccId != null) {
5354 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5355 if (DBG_MERGE) {
5356 log("getLine1NumberForDisplay returning "
5357 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5358 }
5359 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005360 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5362 return null;
5363 } finally {
5364 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005365 }
Derek Tan7226c842014-07-02 17:42:23 -07005366 }
5367
5368 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005369 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5370 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005371 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005372 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005373 return null;
5374 }
Derek Tan97ebb422014-09-05 16:55:38 -07005375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 final long identity = Binder.clearCallingIdentity();
5377 try {
5378 String iccId = getIccId(subId);
5379 if (iccId != null) {
5380 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5381 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5382 }
5383 return null;
5384 } finally {
5385 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005386 }
Derek Tan7226c842014-07-02 17:42:23 -07005387 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005388
5389 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005390 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5391 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005392 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5393 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005394 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005395 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005396 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005397 return null;
5398 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005399
Jordan Liub49b04b2019-05-06 14:45:15 -07005400 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5401 // the process, where TelephonyManager was instantiated.
5402 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005403 final long identity = Binder.clearCallingIdentity();
5404 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005405 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 final TelephonyManager tele = TelephonyManager.from(context);
5407 final SubscriptionManager sub = SubscriptionManager.from(context);
5408
5409 // Figure out what subscribers are currently active
5410 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411
Jordan Liub49b04b2019-05-06 14:45:15 -07005412 // Only consider subs which match the current subId
5413 // This logic can be simplified. See b/131189269 for progress.
5414 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005415 activeSubscriberIds.add(tele.getSubscriberId(subId));
5416 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417
5418 // First pass, find a number override for an active subscriber
5419 String mergeNumber = null;
5420 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5421 for (String key : prefs.keySet()) {
5422 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5423 final String subscriberId = (String) prefs.get(key);
5424 if (activeSubscriberIds.contains(subscriberId)) {
5425 final String iccId = key.substring(
5426 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5427 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5428 mergeNumber = (String) prefs.get(numberKey);
5429 if (DBG_MERGE) {
5430 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5431 + " for active subscriber " + subscriberId);
5432 }
5433 if (!TextUtils.isEmpty(mergeNumber)) {
5434 break;
5435 }
5436 }
5437 }
5438 }
5439
5440 // Shortcut when no active merged subscribers
5441 if (TextUtils.isEmpty(mergeNumber)) {
5442 return null;
5443 }
5444
5445 // Second pass, find all subscribers under that line override
5446 final ArraySet<String> result = new ArraySet<>();
5447 for (String key : prefs.keySet()) {
5448 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5449 final String number = (String) prefs.get(key);
5450 if (mergeNumber.equals(number)) {
5451 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5452 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5453 final String subscriberId = (String) prefs.get(subscriberKey);
5454 if (!TextUtils.isEmpty(subscriberId)) {
5455 result.add(subscriberId);
5456 }
5457 }
5458 }
5459 }
5460
5461 final String[] resultArray = result.toArray(new String[result.size()]);
5462 Arrays.sort(resultArray);
5463 if (DBG_MERGE) {
5464 Slog.d(LOG_TAG,
5465 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5466 }
5467 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005468 } finally {
5469 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005470 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005471 }
5472
5473 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005474 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5475 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5476
5477 final long identity = Binder.clearCallingIdentity();
5478 try {
5479 final TelephonyManager telephonyManager = mApp.getSystemService(
5480 TelephonyManager.class);
5481 String subscriberId = telephonyManager.getSubscriberId(subId);
5482 if (subscriberId == null) {
5483 if (DBG) {
5484 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5485 + subId);
5486 }
5487 return null;
5488 }
5489
5490 final SubscriptionInfo info = SubscriptionController.getInstance()
5491 .getSubscriptionInfo(subId);
5492 final ParcelUuid groupUuid = info.getGroupUuid();
5493 // If it doesn't belong to any group, return just subscriberId of itself.
5494 if (groupUuid == null) {
5495 return new String[]{subscriberId};
5496 }
5497
5498 // Get all subscriberIds from the group.
5499 final List<String> mergedSubscriberIds = new ArrayList<>();
5500 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005501 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5502 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005503 for (SubscriptionInfo subInfo : groupInfos) {
5504 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5505 if (subscriberId != null) {
5506 mergedSubscriberIds.add(subscriberId);
5507 }
5508 }
5509
5510 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5511 } finally {
5512 Binder.restoreCallingIdentity(identity);
5513
5514 }
5515 }
5516
5517 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005518 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005519 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5520 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521
5522 final long identity = Binder.clearCallingIdentity();
5523 try {
5524 final Phone phone = getPhone(subId);
5525 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5526 } finally {
5527 Binder.restoreCallingIdentity(identity);
5528 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005529 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005530
5531 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005532 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005533 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5534 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005535 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536
5537 final long identity = Binder.clearCallingIdentity();
5538 try {
5539 final Phone phone = getPhone(subId);
5540 if (phone == null) {
5541 return false;
5542 }
5543 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5544 cdmaNonRoamingList);
5545 } finally {
5546 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005547 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005548 }
5549
5550 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005551 @Deprecated
5552 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5553 enforceModifyPermission();
5554
5555 int returnValue = 0;
5556 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005557 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005558 if(result.exception == null) {
5559 if (result.result != null) {
5560 byte[] responseData = (byte[])(result.result);
5561 if(responseData.length > oemResp.length) {
5562 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5563 responseData.length + "bytes. Buffer Size is " +
5564 oemResp.length + "bytes.");
5565 }
5566 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5567 returnValue = responseData.length;
5568 }
5569 } else {
5570 CommandException ex = (CommandException) result.exception;
5571 returnValue = ex.getCommandError().ordinal();
5572 if(returnValue > 0) returnValue *= -1;
5573 }
5574 } catch (RuntimeException e) {
5575 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5576 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5577 if(returnValue > 0) returnValue *= -1;
5578 }
5579
5580 return returnValue;
5581 }
5582
5583 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005584 public void setRadioCapability(RadioAccessFamily[] rafs) {
5585 try {
5586 ProxyController.getInstance().setRadioCapability(rafs);
5587 } catch (RuntimeException e) {
5588 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5589 }
5590 }
5591
5592 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005593 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005594 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005595 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005596 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005597 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005598 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 final long identity = Binder.clearCallingIdentity();
5600 try {
chen xub97461a2018-10-26 14:17:57 -07005601 TelephonyPermissions
5602 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5603 mApp, phone.getSubId(), "getRadioAccessFamily");
5604 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
chen xub97461a2018-10-26 14:17:57 -07005608 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005609 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005610
5611 @Override
5612 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005613 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005614 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615
5616 final long identity = Binder.clearCallingIdentity();
5617 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005618 ImsManager.getInstance(defaultPhone.getContext(),
5619 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 } finally {
5621 Binder.restoreCallingIdentity(identity);
5622 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005623 }
5624
5625 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005626 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005627 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5629 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005630 return false;
5631 }
Svet Ganovb320e182015-04-16 12:30:10 -07005632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 // Check the user preference and the system-level IMS setting. Even if the user has
5636 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5637 // In the long run, we may instead need to check if there exists a connection service
5638 // which can support video calling.
5639 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005640 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 return imsManager.isVtEnabledByPlatform()
5642 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5643 && imsManager.isVtEnabledByUser();
5644 } finally {
5645 Binder.restoreCallingIdentity(identity);
5646 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005647 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005648
Andrew Leea1239f22015-03-02 17:44:07 -08005649 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005650 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5651 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005652 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005653 mApp, subId, callingPackage, callingFeatureId,
5654 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655 return false;
5656 }
5657
5658 final long identity = Binder.clearCallingIdentity();
5659 try {
5660 CarrierConfigManager configManager =
5661 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005662 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5664 } finally {
5665 Binder.restoreCallingIdentity(identity);
5666 }
Andrew Leea1239f22015-03-02 17:44:07 -08005667 }
5668
5669 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005670 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005672 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 return false;
5674 }
5675
5676 final long identity = Binder.clearCallingIdentity();
5677 try {
5678 CarrierConfigManager configManager =
5679 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005680 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5682 } finally {
5683 Binder.restoreCallingIdentity(identity);
5684 }
Andrew Leea1239f22015-03-02 17:44:07 -08005685 }
5686
Andrew Lee9431b832015-03-09 18:46:45 -07005687 @Override
5688 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005689 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005690 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005691 }
5692
5693 @Override
5694 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 final long identity = Binder.clearCallingIdentity();
5696 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005697 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
Andrew Lee9431b832015-03-09 18:46:45 -07005701 }
5702
Hall Liuf6668912018-10-31 17:05:23 -07005703 /**
5704 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5705 * support for the feature and device firmware support.
5706 *
5707 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5708 */
5709 @Override
5710 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005712 final Phone phone = getPhone(subscriptionId);
5713 if (phone == null) {
5714 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5715 return false;
5716 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005718 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5720 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005721 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 return isCarrierSupported && isDeviceSupported;
5723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
Hall Liu98187582018-01-22 19:15:32 -08005726 }
5727
Hall Liuf6668912018-10-31 17:05:23 -07005728 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005729 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5730 * RTT setting, will return true if the device and carrier both support RTT.
5731 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005732 */
5733 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734 final long identity = Binder.clearCallingIdentity();
5735 try {
Hall Liuf2daa022019-07-23 18:39:00 -07005736 boolean isRttSupported = isRttSupported(subscriptionId);
5737 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005738 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liuf2daa022019-07-23 18:39:00 -07005739 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5740 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5741 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 } finally {
5743 Binder.restoreCallingIdentity(identity);
5744 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005745 }
5746
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005747 @Deprecated
5748 @Override
5749 public String getDeviceId(String callingPackage) {
5750 return getDeviceIdWithFeature(callingPackage, null);
5751 }
5752
Sanket Padawe7310cc72015-01-14 09:53:20 -08005753 /**
5754 * Returns the unique device ID of phone, for example, the IMEI for
5755 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5756 *
5757 * <p>Requires Permission:
5758 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5759 */
5760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005761 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005762 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005763 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005764 return null;
5765 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005766 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005767 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005768 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005769 return null;
5770 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771
5772 final long identity = Binder.clearCallingIdentity();
5773 try {
5774 return phone.getDeviceId();
5775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005778 }
5779
Ping Sunc67b7c22016-03-02 19:16:45 +08005780 /**
5781 * {@hide}
5782 * Returns the IMS Registration Status on a particular subid
5783 *
5784 * @param subId
5785 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005786 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005787 Phone phone = getPhone(subId);
5788 if (phone != null) {
5789 return phone.isImsRegistered();
5790 } else {
5791 return false;
5792 }
5793 }
5794
Santos Cordon7a1885b2015-02-03 11:15:19 -08005795 @Override
5796 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797 final long identity = Binder.clearCallingIdentity();
5798 try {
5799 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5800 } finally {
5801 Binder.restoreCallingIdentity(identity);
5802 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005803 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005804
Tyler Gunnf70ed162019-04-03 15:28:53 -07005805 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005806 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005807 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005808 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005809 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005810 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5811 }
5812 final long identity = Binder.clearCallingIdentity();
5813 try {
5814 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5815 } finally {
5816 Binder.restoreCallingIdentity(identity);
5817 }
5818 }
5819
5820 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005821 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5822 final long identity = Binder.clearCallingIdentity();
5823 try {
5824 Phone phone = getPhone(subscriptionId);
5825 if (phone == null) {
5826 return null;
5827 }
5828 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5829 } finally {
5830 Binder.restoreCallingIdentity(identity);
5831 }
5832 }
5833
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005834 /**
5835 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005836 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005837 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005838 final long identity = Binder.clearCallingIdentity();
5839 try {
5840 Phone phone = getPhone(subId);
5841 if (phone != null) {
5842 return phone.isWifiCallingEnabled();
5843 } else {
5844 return false;
5845 }
5846 } finally {
5847 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005848 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005849 }
5850
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005851 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005852 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005853 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005854 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005855 final long identity = Binder.clearCallingIdentity();
5856 try {
5857 Phone phone = getPhone(subId);
5858 if (phone != null) {
5859 return phone.isVideoEnabled();
5860 } else {
5861 return false;
5862 }
5863 } finally {
5864 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005865 }
5866 }
5867
5868 /**
5869 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5870 * defined in {@link ImsRegistrationImplBase}.
5871 */
5872 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005873 final long identity = Binder.clearCallingIdentity();
5874 try {
5875 Phone phone = getPhone(subId);
5876 if (phone != null) {
5877 return phone.getImsRegistrationTech();
5878 } else {
5879 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5880 }
5881 } finally {
5882 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005883 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005884 }
5885
Stuart Scott8eef64f2015-04-08 15:13:54 -07005886 @Override
5887 public void factoryReset(int subId) {
5888 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005889 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5890 return;
5891 }
5892
Svet Ganovcc087f82015-05-12 20:35:54 -07005893 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005894
Svet Ganovcc087f82015-05-12 20:35:54 -07005895 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005896 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5897 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005898 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005899 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005900 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005901 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5902 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005903 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005904 // There has been issues when Sms raw table somehow stores orphan
5905 // fragments. They lead to garbled message when new fragments come
5906 // in and combined with those stale ones. In case this happens again,
5907 // user can reset all network settings which will clean up this table.
5908 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005909 // Clean up IMS settings as well here.
5910 int slotId = getSlotIndex(subId);
5911 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5912 ImsManager.getInstance(mApp, slotId).factoryReset();
5913 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005914 } finally {
5915 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005916 }
5917 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005918
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005919 private void cleanUpSmsRawTable(Context context) {
5920 ContentResolver resolver = context.getContentResolver();
5921 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5922 resolver.delete(uri, null, null);
5923 }
5924
Narayan Kamath1c496c22015-04-16 14:40:19 +01005925 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005926 public String getSimLocaleForSubscriber(int subId) {
5927 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5928 final Phone phone = getPhone(subId);
5929 if (phone == null) {
5930 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005931 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005932 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933 final long identity = Binder.clearCallingIdentity();
5934 try {
chen xu5d3637b2019-01-21 23:31:38 -08005935 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005936 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08005937 if (info == null) {
5938 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5939 return null;
5940 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 // Try and fetch the locale from the carrier properties or from the SIM language
5942 // preferences (EF-PL and EF-LI)...
5943 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005945 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5946 if (localeFromDefaultSim != null) {
5947 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5948 if (DBG) log("Using locale from subId: " + subId + " locale: "
5949 + localeFromDefaultSim);
5950 return localeFromDefaultSim.toLanguageTag();
5951 } else {
5952 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953 }
5954 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005955
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 // The SIM language preferences only store a language (e.g. fr = French), not an
5957 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5958 // the SIM and carrier preferences does not include a country we add the country
5959 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005960 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005962 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 return mccLocale.toLanguageTag();
5964 }
5965
5966 if (DBG) log("No locale found - returning null");
5967 return null;
5968 } finally {
5969 Binder.restoreCallingIdentity(identity);
5970 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005971 }
5972
5973 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005974 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
5975 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005976 }
5977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978 /**
5979 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5980 */
5981 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005982 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
5983 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005984 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005985
Chenjie Yu1ba97252018-01-11 18:16:20 -08005986 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07005987 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005988
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005989 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005990 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5991 * representing the state of the modem.
5992 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005993 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5994 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005995 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005996 */
5997 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005998 public void requestModemActivityInfo(ResultReceiver result) {
5999 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006000 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001
6002 final long identity = Binder.clearCallingIdentity();
6003 try {
6004 ModemActivityInfo ret = null;
6005 synchronized (mLastModemActivityInfo) {
6006 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6007 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006008 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006009 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006011 int[] txTimeMs = info.getTransmitTimeMillis();
6012 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006014 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 }
6016 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006017 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6018 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 mLastModemActivityInfo.setIdleTimeMillis(
6020 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006021 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6022 mLastModemActivityInfo.setReceiveTimeMillis(
6023 info.getReceiveTimeMillis() + mLastModemActivityInfo
6024 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006025 }
Chen Xud78231e2019-09-10 18:49:52 -07006026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6028 mLastModemActivityInfo.getSleepTimeMillis(),
6029 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006030 mLastModemActivityInfo.getTransmitTimeMillis(),
6031 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 Bundle bundle = new Bundle();
6034 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6035 result.send(0, bundle);
6036 } finally {
6037 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006038 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006039 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006040
Siddharth Rayb8114062018-06-17 15:02:38 -07006041 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6042 // less than total activity duration.
6043 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6044 if (info == null) {
6045 return false;
6046 }
6047 int activityDurationMs =
6048 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6049 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006050 int[] txTimeMs = info.getTransmitTimeMillis();
6051 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6052 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006053 }
6054 return (info.isValid()
6055 && (info.getSleepTimeMillis() <= activityDurationMs)
6056 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006057 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006058 && (totalTxTimeMs <= activityDurationMs));
6059 }
6060
Jack Yu85bd38a2015-11-09 11:34:32 -08006061 /**
6062 * {@hide}
6063 * Returns the service state information on specified subscription.
6064 */
6065 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006066 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6067 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006069 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006070 return null;
6071 }
6072
Hall Liuf19c44f2018-11-27 14:38:17 -08006073 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6074 LocationAccessPolicy.checkLocationPermission(mApp,
6075 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6076 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006077 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006078 .setCallingPid(Binder.getCallingPid())
6079 .setCallingUid(Binder.getCallingUid())
6080 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006081 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006082 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6083 .build());
6084
6085 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6086 LocationAccessPolicy.checkLocationPermission(mApp,
6087 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6088 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006089 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006090 .setCallingPid(Binder.getCallingPid())
6091 .setCallingUid(Binder.getCallingUid())
6092 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006093 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006094 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6095 .build());
6096 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6097 boolean hasFinePermission =
6098 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6099 boolean hasCoarsePermission =
6100 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006102 final long identity = Binder.clearCallingIdentity();
6103 try {
6104 final Phone phone = getPhone(subId);
6105 if (phone == null) {
6106 return null;
6107 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006108
Hall Liuf19c44f2018-11-27 14:38:17 -08006109 ServiceState ss = phone.getServiceState();
6110
6111 // Scrub out the location info in ServiceState depending on what level of access
6112 // the caller has.
6113 if (hasFinePermission) return ss;
6114 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6115 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 } finally {
6117 Binder.restoreCallingIdentity(identity);
6118 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006119 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006120
6121 /**
6122 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6123 *
6124 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6125 * voicemail ringtone.
6126 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6127 * PhoneAccount.
6128 */
6129 @Override
6130 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 final long identity = Binder.clearCallingIdentity();
6132 try {
6133 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6134 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006135 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006137
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6139 } finally {
6140 Binder.restoreCallingIdentity(identity);
6141 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006142 }
6143
6144 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006145 * Sets the per-account voicemail ringtone.
6146 *
6147 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6148 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6149 *
6150 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6151 * voicemail ringtone.
6152 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6153 * PhoneAccount.
6154 */
6155 @Override
6156 public void setVoicemailRingtoneUri(String callingPackage,
6157 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006158 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006159 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006160 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6161 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6163 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6164 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006165 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166
6167 final long identity = Binder.clearCallingIdentity();
6168 try {
6169 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6170 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006171 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172 }
6173 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6174 } finally {
6175 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006176 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006177 }
6178
6179 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006180 * Returns whether vibration is set for voicemail notification in Phone settings.
6181 *
6182 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6183 * voicemail vibration setting.
6184 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6185 */
6186 @Override
6187 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188 final long identity = Binder.clearCallingIdentity();
6189 try {
6190 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6191 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006192 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006195 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6196 } finally {
6197 Binder.restoreCallingIdentity(identity);
6198 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006199 }
6200
Youhan Wange64578a2016-05-02 15:32:42 -07006201 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006202 * Sets the per-account voicemail vibration.
6203 *
6204 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6205 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6206 *
6207 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6208 * voicemail vibration setting.
6209 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6210 * specific PhoneAccount.
6211 */
6212 @Override
6213 public void setVoicemailVibrationEnabled(String callingPackage,
6214 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006215 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006216 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006217 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6218 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6220 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6221 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006222 }
6223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 final long identity = Binder.clearCallingIdentity();
6225 try {
6226 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6227 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006228 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229 }
6230 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6231 } finally {
6232 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006233 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006234 }
6235
6236 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006237 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6238 *
6239 * @throws SecurityException if the caller does not have the required permission
6240 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006241 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006242 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006243 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006244 }
6245
6246 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006247 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6248 * permission.
6249 *
6250 * @throws SecurityException if the caller does not have the required permission
6251 */
6252 private void enforceSendSmsPermission() {
6253 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6254 }
6255
6256 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006257 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006258 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006259 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006260 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006261 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262 final long identity = Binder.clearCallingIdentity();
6263 try {
6264 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006265 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266 if (componentName == null) {
6267 throw new SecurityException(
6268 "Caller not current active visual voicemail package[null]");
6269 }
6270 String vvmPackage = componentName.getPackageName();
6271 if (!callingPackage.equals(vvmPackage)) {
6272 throw new SecurityException("Caller not current active visual voicemail package["
6273 + vvmPackage + "]");
6274 }
6275 } finally {
6276 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006277 }
6278 }
6279
6280 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006281 * Return the application ID for the app type.
6282 *
6283 * @param subId the subscription ID that this request applies to.
6284 * @param appType the uicc app type.
6285 * @return Application ID for specificied app type, or null if no uicc.
6286 */
6287 @Override
6288 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006289 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006290 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006291
6292 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006293 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294 if (phone == null) {
6295 return null;
6296 }
6297 String aid = null;
6298 try {
6299 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6300 .getApplicationByType(appType).getAid();
6301 } catch (Exception e) {
6302 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6303 }
6304 return aid;
6305 } finally {
6306 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006307 }
Youhan Wange64578a2016-05-02 15:32:42 -07006308 }
6309
Youhan Wang4001d252016-05-11 10:29:41 -07006310 /**
6311 * Return the Electronic Serial Number.
6312 *
6313 * @param subId the subscription ID that this request applies to.
6314 * @return ESN or null if error.
6315 */
6316 @Override
6317 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006318 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006319 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006320
6321 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006322 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006323 if (phone == null) {
6324 return null;
6325 }
6326 String esn = null;
6327 try {
6328 esn = phone.getEsn();
6329 } catch (Exception e) {
6330 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6331 }
6332 return esn;
6333 } finally {
6334 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006335 }
Youhan Wang4001d252016-05-11 10:29:41 -07006336 }
6337
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006338 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006339 * Return the Preferred Roaming List Version.
6340 *
6341 * @param subId the subscription ID that this request applies to.
6342 * @return PRLVersion or null if error.
6343 */
6344 @Override
6345 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006346 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006347 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006348
6349 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006350 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006351 if (phone == null) {
6352 return null;
6353 }
6354 String cdmaPrlVersion = null;
6355 try {
6356 cdmaPrlVersion = phone.getCdmaPrlVersion();
6357 } catch (Exception e) {
6358 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6359 }
6360 return cdmaPrlVersion;
6361 } finally {
6362 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006363 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006364 }
6365
6366 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006367 * Get snapshot of Telephony histograms
6368 * @return List of Telephony histograms
6369 * @hide
6370 */
6371 @Override
6372 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6374 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375
6376 final long identity = Binder.clearCallingIdentity();
6377 try {
6378 return RIL.getTelephonyRILTimingHistograms();
6379 } finally {
6380 Binder.restoreCallingIdentity(identity);
6381 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006382 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006383
6384 /**
6385 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006386 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6387 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006388 * Require system privileges. In the future we may add this to carrier APIs.
6389 *
Michele Berionne482f8202018-11-27 18:57:59 -08006390 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006391 */
6392 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006393 @TelephonyManager.SetCarrierRestrictionResult
6394 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006395 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006396 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006397
Michele Berionne482f8202018-11-27 18:57:59 -08006398 if (carrierRestrictionRules == null) {
6399 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006400 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 final long identity = Binder.clearCallingIdentity();
6403 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006404 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006405 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406 } finally {
6407 Binder.restoreCallingIdentity(identity);
6408 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006409 }
6410
6411 /**
6412 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006413 * Get the allowed carrier list and the excluded carrier list, including the priority between
6414 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006415 * Require system privileges. In the future we may add this to carrier APIs.
6416 *
Michele Berionne482f8202018-11-27 18:57:59 -08006417 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006418 */
6419 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006420 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006421 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006422 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006423
6424 final long identity = Binder.clearCallingIdentity();
6425 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006426 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6427 if (response instanceof CarrierRestrictionRules) {
6428 return (CarrierRestrictionRules) response;
6429 }
6430 // Response is an Exception of some kind,
6431 // which is signalled to the user as a NULL retval
6432 return null;
6433 } catch (Exception e) {
6434 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6435 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006436 } finally {
6437 Binder.restoreCallingIdentity(identity);
6438 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006439 }
6440
fionaxu59545b42016-05-25 15:53:37 -07006441 /**
6442 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6443 * @param subId the subscription ID that this action applies to.
6444 * @param enabled control enable or disable metered apns.
6445 * {@hide}
6446 */
6447 @Override
6448 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6449 enforceModifyPermission();
6450 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006451
6452 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006453 if (phone == null) {
6454 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6455 return;
6456 }
6457 try {
6458 phone.carrierActionSetMeteredApnsEnabled(enabled);
6459 } catch (Exception e) {
6460 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006461 } finally {
6462 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006463 }
6464 }
6465
6466 /**
6467 * Action set from carrier signalling broadcast receivers to enable/disable radio
6468 * @param subId the subscription ID that this action applies to.
6469 * @param enabled control enable or disable radio.
6470 * {@hide}
6471 */
6472 @Override
6473 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6474 enforceModifyPermission();
6475 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006476
6477 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006478 if (phone == null) {
6479 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6480 return;
6481 }
6482 try {
6483 phone.carrierActionSetRadioEnabled(enabled);
6484 } catch (Exception e) {
6485 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006486 } finally {
6487 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006488 }
6489 }
6490
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006491 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006492 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6493 * network status based on which carrier apps could apply actions accordingly,
6494 * enable/disable default url handler for example.
6495 *
6496 * @param subId the subscription ID that this action applies to.
6497 * @param report control start/stop reporting the default network status.
6498 * {@hide}
6499 */
6500 @Override
6501 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6502 enforceModifyPermission();
6503 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006504
6505 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006506 if (phone == null) {
6507 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6508 return;
6509 }
6510 try {
6511 phone.carrierActionReportDefaultNetworkStatus(report);
6512 } catch (Exception e) {
6513 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514 } finally {
6515 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006516 }
6517 }
6518
6519 /**
fionaxud9622282017-07-17 17:51:30 -07006520 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6521 * @param subId the subscription ID that this action applies to.
6522 * {@hide}
6523 */
6524 @Override
6525 public void carrierActionResetAll(int subId) {
6526 enforceModifyPermission();
6527 final Phone phone = getPhone(subId);
6528 if (phone == null) {
6529 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6530 return;
6531 }
6532 try {
6533 phone.carrierActionResetAll();
6534 } catch (Exception e) {
6535 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6536 }
6537 }
6538
6539 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006540 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6541 * bug report is being generated.
6542 */
6543 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006544 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006545 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6546 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006547 writer.println("Permission Denial: can't dump Phone from pid="
6548 + Binder.getCallingPid()
6549 + ", uid=" + Binder.getCallingUid()
6550 + "without permission "
6551 + android.Manifest.permission.DUMP);
6552 return;
6553 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006554 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006555 }
Jack Yueb89b242016-06-22 13:27:47 -07006556
Brad Ebingerdac2f002018-04-03 15:17:52 -07006557 @Override
6558 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6559 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6560 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006561 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6562 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006563 }
6564
Jack Yueb89b242016-06-22 13:27:47 -07006565 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006566 * Get aggregated video call data usage since boot.
6567 *
6568 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6569 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006570 * {@hide}
6571 */
6572 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006573 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006574 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6575 null);
6576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006577 final long identity = Binder.clearCallingIdentity();
6578 try {
6579 // NetworkStatsService keeps tracking the active network interface and identity. It
6580 // records the delta with the corresponding network identity.
6581 // We just return the total video call data usage snapshot since boot.
6582 Phone phone = getPhone(subId);
6583 if (phone != null) {
6584 return phone.getVtDataUsage(perUidStats);
6585 }
6586 return null;
6587 } finally {
6588 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006589 }
Jack Yueb89b242016-06-22 13:27:47 -07006590 }
Jack Yu75ab2952016-07-08 14:29:33 -07006591
6592 /**
6593 * Policy control of data connection. Usually used when data limit is passed.
6594 * @param enabled True if enabling the data, otherwise disabling.
6595 * @param subId Subscription index
6596 * {@hide}
6597 */
6598 @Override
6599 public void setPolicyDataEnabled(boolean enabled, int subId) {
6600 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601
6602 final long identity = Binder.clearCallingIdentity();
6603 try {
6604 Phone phone = getPhone(subId);
6605 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006606 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607 }
6608 } finally {
6609 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006610 }
6611 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006612
6613 /**
6614 * Get Client request stats
6615 * @return List of Client Request Stats
6616 * @hide
6617 */
6618 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006619 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6620 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006622 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006623 return null;
6624 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006625 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006627 final long identity = Binder.clearCallingIdentity();
6628 try {
6629 if (phone != null) {
6630 return phone.getClientRequestStats();
6631 }
6632
6633 return null;
6634 } finally {
6635 Binder.restoreCallingIdentity(identity);
6636 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006637 }
6638
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006639 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006640 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006641 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006642 }
Jack Yueb4124c2017-02-16 15:32:43 -08006643
6644 /**
Grace Chen70990072017-03-24 17:21:30 -07006645 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006646 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006647 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006648 * @param state State of SIM (power down, power up, pass through)
6649 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6650 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6651 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006652 *
6653 **/
6654 @Override
Grace Chen70990072017-03-24 17:21:30 -07006655 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006656 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006657 Phone phone = PhoneFactory.getPhone(slotIndex);
6658
vagdeviaf9a5b92018-08-15 16:01:53 -07006659 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6660
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006661 final long identity = Binder.clearCallingIdentity();
6662 try {
6663 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006664 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665 }
6666 } finally {
6667 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006668 }
6669 }
Shuo Qiandd210312017-04-12 22:11:33 +00006670
Tyler Gunn65d45c22017-06-05 11:22:26 -07006671 private boolean isUssdApiAllowed(int subId) {
6672 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006673 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006674 if (configManager == null) {
6675 return false;
6676 }
6677 PersistableBundle pb = configManager.getConfigForSubId(subId);
6678 if (pb == null) {
6679 return false;
6680 }
6681 return pb.getBoolean(
6682 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6683 }
6684
Shuo Qiandd210312017-04-12 22:11:33 +00006685 /**
6686 * Check if phone is in emergency callback mode
6687 * @return true if phone is in emergency callback mode
6688 * @param subId sub id
6689 */
goneil9c5f4872017-12-05 14:07:56 -08006690 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006691 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006692 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006693 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694
6695 final long identity = Binder.clearCallingIdentity();
6696 try {
6697 if (phone != null) {
6698 return phone.isInEcm();
6699 } else {
6700 return false;
6701 }
6702 } finally {
6703 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006704 }
6705 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006706
6707 /**
6708 * Get the current signal strength information for the given subscription.
6709 * Because this information is not updated when the device is in a low power state
6710 * it should not be relied-upon to be current.
6711 * @param subId Subscription index
6712 * @return the most recent cached signal strength info from the modem
6713 */
6714 @Override
6715 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 final long identity = Binder.clearCallingIdentity();
6717 try {
6718 Phone p = getPhone(subId);
6719 if (p == null) {
6720 return null;
6721 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723 return p.getSignalStrength();
6724 } finally {
6725 Binder.restoreCallingIdentity(identity);
6726 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006727 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006728
Pengquan Meng77b7f132018-08-22 14:49:57 -07006729 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006730 * Get the current modem radio state for the given slot.
6731 * @param slotIndex slot index.
6732 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006733 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006734 * @return the current radio power state from the modem
6735 */
6736 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006737 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006738 Phone phone = PhoneFactory.getPhone(slotIndex);
6739 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006740 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6741 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006742 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6743 }
6744
6745 final long identity = Binder.clearCallingIdentity();
6746 try {
6747 return phone.getRadioPowerState();
6748 } finally {
6749 Binder.restoreCallingIdentity(identity);
6750 }
6751 }
6752 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6753 }
6754
6755 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006756 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6757 *
6758 * <p>Requires one of the following permissions:
6759 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6760 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6761 * privileges.
6762 *
6763 * @param subId subscription id
6764 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6765 * {@code false}.
6766 */
6767 @Override
6768 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006769 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6770 null /* message */);
6771
Pengquan Menga1bb6272018-09-06 09:59:22 -07006772 boolean isEnabled = false;
6773 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006774 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006775 Phone phone = getPhone(subId);
6776 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006777 } catch (Exception e) {
6778 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6779 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006780 } finally {
6781 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006782 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006783 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006784 }
6785
6786
6787 /**
6788 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6789 *
6790 * <p> Requires permission:
6791 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6792 * privileges.
6793 *
6794 * @param subId subscription id
6795 * @param isEnabled {@code true} means enable, {@code false} means disable.
6796 */
6797 @Override
6798 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6800 mApp, subId, "setDataRoamingEnabled");
6801
Pengquan Menga1bb6272018-09-06 09:59:22 -07006802 final long identity = Binder.clearCallingIdentity();
6803 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006804 Phone phone = getPhone(subId);
6805 if (phone != null) {
6806 phone.setDataRoamingEnabled(isEnabled);
6807 }
6808 } finally {
6809 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006810 }
6811 }
6812
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006813 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006814 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006815 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6816 mApp, subId, "isManualNetworkSelectionAllowed");
6817
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006818 boolean isAllowed = true;
6819 final long identity = Binder.clearCallingIdentity();
6820 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006821 Phone phone = getPhone(subId);
6822 if (phone != null) {
6823 isAllowed = phone.isCspPlmnEnabled();
6824 }
6825 } finally {
6826 Binder.restoreCallingIdentity(identity);
6827 }
6828 return isAllowed;
6829 }
6830
6831 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006832 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006833 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006834 try {
6835 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006836 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006837 } catch (SecurityException e) {
6838 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6839 // has carrier privileges on an active UICC
6840 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6841 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006842 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006843 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006844 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006845
6846 final long identity = Binder.clearCallingIdentity();
6847 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006848 UiccController uiccController = UiccController.getInstance();
6849 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006850 if (hasReadPermission) {
6851 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006852 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006853
6854 // Remove private info if the caller doesn't have access
6855 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6856 for (UiccCardInfo cardInfo : cardInfos) {
6857 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6858 // is available
6859 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6860 if (card == null || card.getUiccProfile() == null) {
6861 // assume no access if the card or profile is unavailable
6862 filteredInfos.add(cardInfo.getUnprivileged());
6863 continue;
6864 }
6865 UiccProfile profile = card.getUiccProfile();
6866 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6867 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6868 filteredInfos.add(cardInfo);
6869 } else {
6870 filteredInfos.add(cardInfo.getUnprivileged());
6871 }
6872 }
6873 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006874 } finally {
6875 Binder.restoreCallingIdentity(identity);
6876 }
6877 }
6878
6879 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006880 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006881 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006883 final long identity = Binder.clearCallingIdentity();
6884 try {
6885 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6886 if (slots == null) {
6887 Rlog.i(LOG_TAG, "slots is null.");
6888 return null;
6889 }
6890
6891 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6892 for (int i = 0; i < slots.length; i++) {
6893 UiccSlot slot = slots[i];
6894 if (slot == null) {
6895 continue;
6896 }
6897
Jordan Liu7be7e652019-05-06 18:55:02 +00006898 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006899 UiccCard card = slot.getUiccCard();
6900 if (card != null) {
6901 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006902 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006903 cardId = slot.getEid();
6904 if (TextUtils.isEmpty(cardId)) {
6905 cardId = slot.getIccId();
6906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907 }
6908
Jordan Liu857451f2019-05-09 16:35:35 -07006909 if (cardId != null) {
6910 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6911 // if cardId is an EID, it's all digits so this is fine
6912 cardId = IccUtils.stripTrailingFs(cardId);
6913 }
6914
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006915 int cardState = 0;
6916 switch (slot.getCardState()) {
6917 case CARDSTATE_ABSENT:
6918 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6919 break;
6920 case CARDSTATE_PRESENT:
6921 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6922 break;
6923 case CARDSTATE_ERROR:
6924 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6925 break;
6926 case CARDSTATE_RESTRICTED:
6927 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6928 break;
6929 default:
6930 break;
6931
6932 }
6933
6934 infos[i] = new UiccSlotInfo(
6935 slot.isActive(),
6936 slot.isEuicc(),
6937 cardId,
6938 cardState,
6939 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006940 slot.isExtendedApduSupported(),
6941 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006942 }
6943 return infos;
6944 } finally {
6945 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006946 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006947 }
6948
6949 @Override
6950 public boolean switchSlots(int[] physicalSlots) {
6951 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952
6953 final long identity = Binder.clearCallingIdentity();
6954 try {
6955 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6956 } finally {
6957 Binder.restoreCallingIdentity(identity);
6958 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006959 }
Jack Yu4c988042018-02-27 15:30:01 -08006960
6961 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006962 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006963 final long identity = Binder.clearCallingIdentity();
6964 try {
6965 return UiccController.getInstance().getCardIdForDefaultEuicc();
6966 } finally {
6967 Binder.restoreCallingIdentity(identity);
6968 }
6969 }
6970
6971 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006972 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6973 enforceModifyPermission();
6974 final Phone phone = getPhone(subId);
6975 if (phone == null) {
6976 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6977 return;
6978 }
6979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006980 final long identity = Binder.clearCallingIdentity();
6981 try {
6982 phone.setRadioIndicationUpdateMode(filters, mode);
6983 } finally {
6984 Binder.restoreCallingIdentity(identity);
6985 }
Jack Yu4c988042018-02-27 15:30:01 -08006986 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006987
6988 /**
goneil47ffb6e2018-04-06 15:40:58 -07006989 * A test API to reload the UICC profile.
6990 *
6991 * <p>Requires that the calling app has permission
6992 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6993 * @hide
6994 */
6995 @Override
6996 public void refreshUiccProfile(int subId) {
6997 enforceModifyPermission();
6998
6999 final long identity = Binder.clearCallingIdentity();
7000 try {
7001 Phone phone = getPhone(subId);
7002 if (phone == null) {
7003 return;
7004 }
7005 UiccCard uiccCard = phone.getUiccCard();
7006 if (uiccCard == null) {
7007 return;
7008 }
7009 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7010 if (uiccProfile == null) {
7011 return;
7012 }
7013 uiccProfile.refresh();
7014 } finally {
7015 Binder.restoreCallingIdentity(identity);
7016 }
7017 }
7018
7019 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007020 * Returns false if the mobile data is disabled by default, otherwise return true.
7021 */
7022 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007023 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007024 }
7025
7026 /**
7027 * Returns true if the data roaming is enabled by default, i.e the system property
7028 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7029 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7030 */
7031 private boolean getDefaultDataRoamingEnabled(int subId) {
7032 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007033 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007034 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007035 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7036 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7037 return isDataRoamingEnabled;
7038 }
7039
7040 /**
7041 * Returns the default network type for the given {@code subId}, if the default network type is
7042 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7043 */
7044 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007045 List<Integer> list = TelephonyProperties.default_network();
7046 int phoneId = mSubscriptionController.getPhoneId(subId);
7047 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7048 return list.get(phoneId);
7049 }
7050 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007051 }
fionaxua13278b2018-03-21 00:08:13 -07007052
7053 @Override
7054 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007055 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007056 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057
7058 final long identity = Binder.clearCallingIdentity();
7059 try {
7060 final Phone phone = getPhone(subId);
7061 if (phone == null) {
7062 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7063 return;
7064 }
chen xueaba88a2019-03-15 13:15:10 -07007065 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7066 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067 } finally {
7068 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007069 }
fionaxua13278b2018-03-21 00:08:13 -07007070 }
7071
7072 @Override
7073 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007074 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075
7076 final long identity = Binder.clearCallingIdentity();
7077 try {
7078 final Phone phone = getPhone(subId);
7079 if (phone == null) {
7080 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7081 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7082 }
7083 return phone.getCarrierIdListVersion();
7084 } finally {
7085 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007086 }
fionaxua13278b2018-03-21 00:08:13 -07007087 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007088
7089 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007090 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7091 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007092 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007093 mApp, subId, callingPackage, callingFeatureId,
7094 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007095 return -1;
7096 }
7097
7098 final long identity = Binder.clearCallingIdentity();
7099 try {
7100 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7101 } finally {
7102 Binder.restoreCallingIdentity(identity);
7103 }
7104 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007105
7106 @Override
7107 public int getCdmaRoamingMode(int subId) {
7108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7109 mApp, subId, "getCdmaRoamingMode");
7110
7111 final long identity = Binder.clearCallingIdentity();
7112 try {
7113 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7114 } finally {
7115 Binder.restoreCallingIdentity(identity);
7116 }
7117 }
7118
7119 @Override
7120 public boolean setCdmaRoamingMode(int subId, int mode) {
7121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7122 mApp, subId, "setCdmaRoamingMode");
7123
7124 final long identity = Binder.clearCallingIdentity();
7125 try {
7126 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7127 } finally {
7128 Binder.restoreCallingIdentity(identity);
7129 }
7130 }
7131
7132 @Override
7133 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7135 mApp, subId, "setCdmaSubscriptionMode");
7136
7137 final long identity = Binder.clearCallingIdentity();
7138 try {
7139 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7140 } finally {
7141 Binder.restoreCallingIdentity(identity);
7142 }
7143 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007144
sqianc5eccab2018-10-19 18:46:41 -07007145 @Override
sqian8c685422019-02-22 15:55:18 -08007146 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007147 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007149 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7150 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007151 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7152 }
7153 final long identity = Binder.clearCallingIdentity();
7154 try {
sqian854d44b2018-12-12 16:48:18 -08007155 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7156 for (Phone phone: PhoneFactory.getPhones()) {
7157 if (phone.getEmergencyNumberTracker() != null
7158 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7159 emergencyNumberListInternal.put(
7160 phone.getSubId(),
7161 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7162 }
sqian11b7a0e2018-12-05 18:48:28 -08007163 }
sqian854d44b2018-12-12 16:48:18 -08007164 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007165 } finally {
7166 Binder.restoreCallingIdentity(identity);
7167 }
sqianc5eccab2018-10-19 18:46:41 -07007168 }
7169
7170 @Override
sqian8c685422019-02-22 15:55:18 -08007171 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007172 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007173 if (!exactMatch) {
7174 TelephonyPermissions
7175 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007176 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007177 }
7178 final long identity = Binder.clearCallingIdentity();
7179 try {
sqian854d44b2018-12-12 16:48:18 -08007180 for (Phone phone: PhoneFactory.getPhones()) {
7181 if (phone.getEmergencyNumberTracker() != null
7182 && phone.getEmergencyNumberTracker() != null) {
7183 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7184 number, exactMatch)) {
7185 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007186 }
7187 }
sqian11b7a0e2018-12-05 18:48:28 -08007188 }
7189 return false;
7190 } finally {
7191 Binder.restoreCallingIdentity(identity);
7192 }
7193 }
7194
sqianf4ca7ed2019-01-15 18:32:07 -08007195 /**
7196 * Update emergency number list for test mode.
7197 */
7198 @Override
7199 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7200 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7201 "updateEmergencyNumberListTestMode");
7202
7203 final long identity = Binder.clearCallingIdentity();
7204 try {
7205 for (Phone phone: PhoneFactory.getPhones()) {
7206 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7207 if (tracker != null) {
7208 tracker.executeEmergencyNumberTestModeCommand(action, num);
7209 }
7210 }
7211 } finally {
7212 Binder.restoreCallingIdentity(identity);
7213 }
7214 }
7215
7216 /**
7217 * Get the full emergency number list for test mode.
7218 */
7219 @Override
7220 public List<String> getEmergencyNumberListTestMode() {
7221 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7222 "getEmergencyNumberListTestMode");
7223
7224 final long identity = Binder.clearCallingIdentity();
7225 try {
7226 Set<String> emergencyNumbers = new HashSet<>();
7227 for (Phone phone: PhoneFactory.getPhones()) {
7228 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7229 if (tracker != null) {
7230 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7231 emergencyNumbers.add(num.getNumber());
7232 }
7233 }
7234 }
7235 return new ArrayList<>(emergencyNumbers);
7236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
7239 }
7240
chen xud6b45bd2018-10-30 22:27:10 -07007241 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007242 public int getEmergencyNumberDbVersion(int subId) {
7243 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7244
7245 final long identity = Binder.clearCallingIdentity();
7246 try {
7247 final Phone phone = getPhone(subId);
7248 if (phone == null) {
7249 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7250 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7251 }
7252 return phone.getEmergencyNumberDbVersion();
7253 } finally {
7254 Binder.restoreCallingIdentity(identity);
7255 }
7256 }
7257
7258 @Override
7259 public void notifyOtaEmergencyNumberDbInstalled() {
7260 enforceModifyPermission();
7261
7262 final long identity = Binder.clearCallingIdentity();
7263 try {
7264 for (Phone phone: PhoneFactory.getPhones()) {
7265 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7266 if (tracker != null) {
7267 tracker.updateOtaEmergencyNumberDatabase();
7268 }
7269 }
7270 } finally {
7271 Binder.restoreCallingIdentity(identity);
7272 }
7273 }
7274
7275 @Override
7276 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7277 enforceActiveEmergencySessionPermission();
7278
7279 final long identity = Binder.clearCallingIdentity();
7280 try {
7281 for (Phone phone: PhoneFactory.getPhones()) {
7282 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7283 if (tracker != null) {
7284 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7285 }
7286 }
7287 } finally {
7288 Binder.restoreCallingIdentity(identity);
7289 }
7290 }
7291
7292 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007293 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7294 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7295 Phone phone = getPhone(subId);
7296 if (phone == null) {
7297 return null;
7298 }
7299 final long identity = Binder.clearCallingIdentity();
7300 try {
7301 UiccProfile profile = UiccController.getInstance()
7302 .getUiccProfileForPhone(phone.getPhoneId());
7303 if (profile != null) {
7304 return profile.getCertsFromCarrierPrivilegeAccessRules();
7305 }
7306 } finally {
7307 Binder.restoreCallingIdentity(identity);
7308 }
7309 return null;
7310 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007311
7312 /**
7313 * Enable or disable a modem stack.
7314 */
7315 @Override
7316 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7317 enforceModifyPermission();
7318
7319 final long identity = Binder.clearCallingIdentity();
7320 try {
7321 Phone phone = PhoneFactory.getPhone(slotIndex);
7322 if (phone == null) {
7323 return false;
7324 } else {
7325 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7326 }
7327 } finally {
7328 Binder.restoreCallingIdentity(identity);
7329 }
7330 }
Michelecea4cf22018-12-21 15:00:11 -08007331
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007332 /**
7333 * Whether a modem stack is enabled or not.
7334 */
7335 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007336 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7337 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007338 Phone phone = PhoneFactory.getPhone(slotIndex);
7339 if (phone == null) return false;
7340
7341 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007342 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7343 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007344 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7345 }
7346
7347 final long identity = Binder.clearCallingIdentity();
7348 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007349 try {
7350 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7351 } catch (NoSuchElementException ex) {
7352 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7353 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007354 } finally {
7355 Binder.restoreCallingIdentity(identity);
7356 }
7357 }
7358
Michelecea4cf22018-12-21 15:00:11 -08007359 @Override
Michele0ea7d782019-03-19 14:58:42 -07007360 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007361 enforceModifyPermission();
7362
7363 final long identity = Binder.clearCallingIdentity();
7364 try {
7365 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007366 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007367 .commit();
7368 } finally {
7369 Binder.restoreCallingIdentity(identity);
7370 }
7371 }
7372
7373 @Override
Michele0ea7d782019-03-19 14:58:42 -07007374 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007375 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007376 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007377 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7378 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007379 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007380 }
Michelecea4cf22018-12-21 15:00:11 -08007381
7382 final long identity = Binder.clearCallingIdentity();
7383 try {
Michele0ea7d782019-03-19 14:58:42 -07007384 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007385 } finally {
7386 Binder.restoreCallingIdentity(identity);
7387 }
7388 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007389
Michele0ea7d782019-03-19 14:58:42 -07007390 @TelephonyManager.IsMultiSimSupportedResult
7391 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007392 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7393 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7394 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007395 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7396 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007397 }
7398 // Check if the hardware supports multisim functionality. If usage of multisim is not
7399 // supported by the modem, indicate that it is restricted.
7400 PhoneCapability staticCapability =
7401 mPhoneConfigurationManager.getStaticPhoneCapability();
7402 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007403 loge("isMultiSimSupportedInternal: no static configuration available");
7404 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007405 }
7406 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007407 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7408 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007409 }
7410 // Check if support of multiple SIMs is restricted by carrier
7411 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007412 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007413 }
7414
Michele0ea7d782019-03-19 14:58:42 -07007415 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007416 }
7417
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007418 /**
7419 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007420 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7421 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7422 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007423 * @param numOfSims number of active sims we want to switch to
7424 */
7425 @Override
7426 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007427 if (numOfSims == 1) {
7428 enforceModifyPermission();
7429 } else {
7430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7431 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7432 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007433 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007434
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007435 try {
Michele30b57b22019-03-01 12:01:14 -08007436 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007437 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007438 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7439 return;
7440 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007441 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7442 } finally {
7443 Binder.restoreCallingIdentity(identity);
7444 }
7445 }
7446
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007447 @Override
7448 public boolean isApplicationOnUicc(int subId, int appType) {
7449 enforceReadPrivilegedPermission("isApplicationOnUicc");
7450 Phone phone = getPhone(subId);
7451 if (phone == null) {
7452 return false;
7453 }
7454 final long identity = Binder.clearCallingIdentity();
7455 try {
7456 UiccCard uiccCard = phone.getUiccCard();
7457 if (uiccCard == null) {
7458 return false;
7459 }
7460 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7461 if (uiccProfile == null) {
7462 return false;
7463 }
7464 if (TelephonyManager.APPTYPE_SIM <= appType
7465 && appType <= TelephonyManager.APPTYPE_ISIM) {
7466 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7467 }
7468 return false;
7469 } finally {
7470 Binder.restoreCallingIdentity(identity);
7471 }
7472 }
7473
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007474 /**
chen xub4baa772019-04-03 10:23:41 -07007475 * Get whether making changes to modem configurations will trigger reboot.
7476 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007477 */
7478 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007479 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7480 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007482 mApp, subId, callingPackage, callingFeatureId,
7483 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007484 return false;
7485 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007486 final long identity = Binder.clearCallingIdentity();
7487 try {
7488 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7489 } finally {
7490 Binder.restoreCallingIdentity(identity);
7491 }
7492 }
7493
Nathan Harold29f5f052019-02-15 13:41:57 -08007494 private void updateModemStateMetrics() {
7495 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7496 // TODO: check the state for each modem if the api is ready.
7497 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7498 }
7499
Pengquan Meng3889a572019-01-23 11:16:29 -08007500 @Override
7501 public int[] getSlotsMapping() {
7502 enforceReadPrivilegedPermission("getSlotsMapping");
7503
7504 final long identity = Binder.clearCallingIdentity();
7505 try {
7506 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7507 // All logical slots should have a mapping to a physical slot.
7508 int[] logicalSlotsMapping = new int[phoneCount];
7509 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7510 for (int i = 0; i < slotInfos.length; i++) {
7511 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7512 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7513 }
7514 }
7515 return logicalSlotsMapping;
7516 } finally {
7517 Binder.restoreCallingIdentity(identity);
7518 }
7519 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007520
7521 /**
7522 * Get the IRadio HAL Version
7523 */
7524 @Override
7525 public int getRadioHalVersion() {
7526 Phone phone = getDefaultPhone();
7527 if (phone == null) return -1;
7528 HalVersion hv = phone.getHalVersion();
7529 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7530 return hv.major * 100 + hv.minor;
7531 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007532
7533 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007534 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7535 * corresponding network requests on a subId.
7536 *
7537 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007538 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007539 * 2) APN is un-metered for this subscription, or
7540 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7541 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7542 *
7543 * @return whether data is allowed for a apn type.
7544 *
7545 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007546 */
7547 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007548 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007549 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7550 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007551
7552 // Now that all security checks passes, perform the operation as ourselves.
7553 final long identity = Binder.clearCallingIdentity();
7554 try {
7555 Phone phone = getPhone(subId);
7556 if (phone == null) return false;
7557
Jack Yu41407ee2019-05-13 16:54:09 -07007558 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007559 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7560 } finally {
7561 Binder.restoreCallingIdentity(identity);
7562 }
7563 }
7564
7565 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007566 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007567 enforceReadPrivilegedPermission("isApnMetered");
7568
7569 // Now that all security checks passes, perform the operation as ourselves.
7570 final long identity = Binder.clearCallingIdentity();
7571 try {
7572 Phone phone = getPhone(subId);
7573 if (phone == null) return true; // By default return true.
7574
Jack Yu41407ee2019-05-13 16:54:09 -07007575 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007576 } finally {
7577 Binder.restoreCallingIdentity(identity);
7578 }
7579 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007580
7581 @Override
7582 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7583 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7584 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7585 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7586 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7587 }
7588 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7589 Intent intent = new Intent();
7590 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7591 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7592 // Bring up choose default SMS subscription dialog right now
7593 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7594 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7595 mApp.startActivity(intent);
7596 }
chen xud5ca2d52019-05-28 15:20:57 -07007597
7598 @Override
7599 public String getMmsUAProfUrl(int subId) {
7600 //TODO investigate if this API should require proper permission check in R b/133791609
7601 final long identity = Binder.clearCallingIdentity();
7602 try {
7603 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7604 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7605 } finally {
7606 Binder.restoreCallingIdentity(identity);
7607 }
7608 }
7609
7610 @Override
7611 public String getMmsUserAgent(int subId) {
7612 //TODO investigate if this API should require proper permission check in R b/133791609
7613 final long identity = Binder.clearCallingIdentity();
7614 try {
7615 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7616 .getString(com.android.internal.R.string.config_mms_user_agent);
7617 } finally {
7618 Binder.restoreCallingIdentity(identity);
7619 }
7620 }
Jack Yub07d4972019-05-28 16:12:25 -07007621
7622 @Override
7623 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7624 enforceModifyPermission();
7625
7626 // Now that all security checks passes, perform the operation as ourselves.
7627 final long identity = Binder.clearCallingIdentity();
7628 try {
7629 Phone phone = getPhone(subId);
7630 if (phone == null) return false;
7631
7632 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7633 } finally {
7634 Binder.restoreCallingIdentity(identity);
7635 }
7636 }
7637
7638 @Override
7639 public boolean isDataAllowedInVoiceCall(int subId) {
7640 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7641
7642 // Now that all security checks passes, perform the operation as ourselves.
7643 final long identity = Binder.clearCallingIdentity();
7644 try {
7645 Phone phone = getPhone(subId);
7646 if (phone == null) return false;
7647
7648 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7649 } finally {
7650 Binder.restoreCallingIdentity(identity);
7651 }
7652 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007653
7654 /**
7655 * Updates whether conference event pacakge handling is enabled.
7656 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7657 * otherwise.
7658 */
7659 @Override
7660 public void setCepEnabled(boolean isCepEnabled) {
7661 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7662
7663 final long identity = Binder.clearCallingIdentity();
7664 try {
7665 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7666 for (Phone phone : PhoneFactory.getPhones()) {
7667 Phone defaultPhone = phone.getImsPhone();
7668 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7669 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7670 ImsPhoneCallTracker imsPhoneCallTracker =
7671 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7672 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7673 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7674 + imsPhone.getMsisdn());
7675 }
7676 }
7677 } finally {
7678 Binder.restoreCallingIdentity(identity);
7679 }
7680 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007681}