blob: 3e1b6a5f437cd6383899cadec5f27c13de52f135 [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
2429 /**
2430 * Make sure the caller has the CALL_PHONE permission.
2431 *
2432 * @throws SecurityException if the caller does not have the required permission
2433 */
2434 private void enforceCallPermission() {
2435 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2436 }
2437
Stuart Scott8eef64f2015-04-08 15:13:54 -07002438 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002439 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002440 "ConnectivityService");
2441 }
2442
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 private String createTelUrl(String number) {
2444 if (TextUtils.isEmpty(number)) {
2445 return null;
2446 }
2447
Jake Hambye994d462014-02-03 13:10:13 -08002448 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 }
2450
Ihab Awadf9e92732013-12-05 18:02:52 -08002451 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2453 }
2454
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002455 private static void logv(String msg) {
2456 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2457 }
2458
Ihab Awadf9e92732013-12-05 18:02:52 -08002459 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2461 }
2462
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002463 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002465 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002466 }
2467
Sanket Padawe356d7632015-06-22 14:03:32 -07002468 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002469 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470 final long identity = Binder.clearCallingIdentity();
2471 try {
2472 final Phone phone = PhoneFactory.getPhone(slotIndex);
2473 if (phone == null) {
2474 return PhoneConstants.PHONE_TYPE_NONE;
2475 } else {
2476 return phone.getPhoneType();
2477 }
2478 } finally {
2479 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 }
2482
2483 /**
2484 * Returns the CDMA ERI icon index to display
2485 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002486 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002487 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2488 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2489 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002490 }
2491
Sanket Padawe356d7632015-06-22 14:03:32 -07002492 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002493 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2494 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002495 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002496 mApp, subId, callingPackage, callingFeatureId,
2497 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002498 return -1;
2499 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500
2501 final long identity = Binder.clearCallingIdentity();
2502 try {
2503 final Phone phone = getPhone(subId);
2504 if (phone != null) {
2505 return phone.getCdmaEriIconIndex();
2506 } else {
2507 return -1;
2508 }
2509 } finally {
2510 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002511 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002512 }
2513
2514 /**
2515 * Returns the CDMA ERI icon mode,
2516 * 0 - ON
2517 * 1 - FLASHING
2518 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002519 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002520 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2521 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2522 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002523 }
2524
Sanket Padawe356d7632015-06-22 14:03:32 -07002525 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002526 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2527 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002528 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002529 mApp, subId, callingPackage, callingFeatureId,
2530 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002531 return -1;
2532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533
2534 final long identity = Binder.clearCallingIdentity();
2535 try {
2536 final Phone phone = getPhone(subId);
2537 if (phone != null) {
2538 return phone.getCdmaEriIconMode();
2539 } else {
2540 return -1;
2541 }
2542 } finally {
2543 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002545 }
2546
2547 /**
2548 * Returns the CDMA ERI text,
2549 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002550 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002551 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2552 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2553 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002554 }
2555
Sanket Padawe356d7632015-06-22 14:03:32 -07002556 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002557 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2558 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002560 mApp, subId, callingPackage, callingFeatureId,
2561 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002562 return null;
2563 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564
2565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 final Phone phone = getPhone(subId);
2568 if (phone != null) {
2569 return phone.getCdmaEriText();
2570 } else {
2571 return null;
2572 }
2573 } finally {
2574 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002575 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 }
2577
2578 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002579 * Returns the CDMA MDN.
2580 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002581 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002582 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2584 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002585
2586 final long identity = Binder.clearCallingIdentity();
2587 try {
2588 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002589 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590 return phone.getLine1Number();
2591 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002592 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002593 return null;
2594 }
2595 } finally {
2596 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002597 }
2598 }
2599
2600 /**
2601 * Returns the CDMA MIN.
2602 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002603 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002604 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2606 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607
2608 final long identity = Binder.clearCallingIdentity();
2609 try {
2610 final Phone phone = getPhone(subId);
2611 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2612 return phone.getCdmaMin();
2613 } else {
2614 return null;
2615 }
2616 } finally {
2617 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002618 }
2619 }
2620
Hall Liud892bec2018-11-30 14:51:45 -08002621 @Override
2622 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2623 INumberVerificationCallback callback, String callingPackage) {
2624 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2625 != PERMISSION_GRANTED) {
2626 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2627 }
2628 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2629
2630 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2631 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2632 throw new SecurityException("Calling package must be configured in the device config");
2633 }
2634
2635 if (range == null) {
2636 throw new NullPointerException("Range must be non-null");
2637 }
2638
2639 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002640 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002641
2642 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2643 }
2644
Junda Liuca05d5d2014-08-14 22:36:34 -07002645 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002646 * Returns true if CDMA provisioning needs to run.
2647 */
2648 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649 final long identity = Binder.clearCallingIdentity();
2650 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002651 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652 } finally {
2653 Binder.restoreCallingIdentity(identity);
2654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 }
2656
2657 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002658 * Sets the voice mail number of a given subId.
2659 */
2660 @Override
2661 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002662 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663
2664 final long identity = Binder.clearCallingIdentity();
2665 try {
2666 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2667 new Pair<String, String>(alphaTag, number), new Integer(subId));
2668 return success;
2669 } finally {
2670 Binder.restoreCallingIdentity(identity);
2671 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002672 }
2673
Ta-wei Yen87c49842016-05-13 21:19:52 -07002674 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002675 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2676 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002677 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2678 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002679 if (!TextUtils.equals(callingPackage, systemDialer)) {
2680 throw new SecurityException("caller must be system dialer");
2681 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682
2683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2686 if (phoneAccountHandle == null) {
2687 return null;
2688 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002689 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690 } finally {
2691 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002692 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002693 }
2694
2695 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002696 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2697 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002698 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002700 mApp, subId, callingPackage, callingFeatureId,
2701 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002702 return null;
2703 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002705 final long identity = Binder.clearCallingIdentity();
2706 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002707 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002708 } finally {
2709 Binder.restoreCallingIdentity(identity);
2710 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002711 }
2712
2713 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002714 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2715 VisualVoicemailSmsFilterSettings settings) {
2716 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717
2718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002721 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 } finally {
2723 Binder.restoreCallingIdentity(identity);
2724 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002725 }
2726
2727 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002728 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2729 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730
2731 final long identity = Binder.clearCallingIdentity();
2732 try {
2733 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002734 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 } finally {
2736 Binder.restoreCallingIdentity(identity);
2737 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002738 }
2739
2740 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002741 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2742 String callingPackage, int subId) {
2743 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744
2745 final long identity = Binder.clearCallingIdentity();
2746 try {
2747 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002748 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749 } finally {
2750 Binder.restoreCallingIdentity(identity);
2751 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002752 }
2753
2754 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002755 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002756 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757
2758 final long identity = Binder.clearCallingIdentity();
2759 try {
2760 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002761 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762 } finally {
2763 Binder.restoreCallingIdentity(identity);
2764 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002765 }
2766
2767 @Override
2768 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2769 String number, int port, String text, PendingIntent sentIntent) {
2770 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002771 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002772 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002773 SmsController smsController = PhoneFactory.getSmsController();
2774 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2775 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002776 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002777
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002778 /**
fionaxu0152e512016-11-14 13:36:14 -08002779 * Sets the voice activation state of a given subId.
2780 */
2781 @Override
2782 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2784 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785
2786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 final Phone phone = getPhone(subId);
2789 if (phone != null) {
2790 phone.setVoiceActivationState(activationState);
2791 } else {
2792 loge("setVoiceActivationState fails with invalid subId: " + subId);
2793 }
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002796 }
2797 }
2798
2799 /**
2800 * Sets the data activation state of a given subId.
2801 */
2802 @Override
2803 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2805 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806
2807 final long identity = Binder.clearCallingIdentity();
2808 try {
2809 final Phone phone = getPhone(subId);
2810 if (phone != null) {
2811 phone.setDataActivationState(activationState);
2812 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002813 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814 }
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002817 }
2818 }
2819
2820 /**
2821 * Returns the voice activation state of a given subId.
2822 */
2823 @Override
2824 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002825 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826
fionaxu0152e512016-11-14 13:36:14 -08002827 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828 final long identity = Binder.clearCallingIdentity();
2829 try {
2830 if (phone != null) {
2831 return phone.getVoiceActivationState();
2832 } else {
2833 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2834 }
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002837 }
2838 }
2839
2840 /**
2841 * Returns the data activation state of a given subId.
2842 */
2843 @Override
2844 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002845 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846
fionaxu0152e512016-11-14 13:36:14 -08002847 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 if (phone != null) {
2851 return phone.getDataActivationState();
2852 } else {
2853 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2854 }
2855 } finally {
2856 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002857 }
2858 }
2859
2860 /**
Wink Saville36469e72014-06-11 15:17:00 -07002861 * Returns the unread count of voicemails for a subId
2862 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002863 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002864 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2865 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002866 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002867 mApp, subId, callingPackage, callingFeatureId,
2868 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002869 return 0;
2870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 final Phone phone = getPhone(subId);
2874 if (phone != null) {
2875 return phone.getVoiceMessageCount();
2876 } else {
2877 return 0;
2878 }
2879 } finally {
2880 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002882 }
2883
2884 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002885 * returns true, if the device is in a state where both voice and data
2886 * are supported simultaneously. This can change based on location or network condition.
2887 */
2888 @Override
2889 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 final Phone phone = getPhone(subId);
2893 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2894 } finally {
2895 Binder.restoreCallingIdentity(identity);
2896 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002897 }
2898
2899 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002900 * Send the dialer code if called from the current default dialer or the caller has
2901 * carrier privilege.
2902 * @param inputCode The dialer code to send
2903 */
2904 @Override
2905 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002906 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002907 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002908 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2909 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002910 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002911 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2912 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002914
2915 final long identity = Binder.clearCallingIdentity();
2916 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002917 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002918 } finally {
2919 Binder.restoreCallingIdentity(identity);
2920 }
fionaxu235cc5e2017-03-06 22:25:57 -08002921 }
2922
Pengquan Menga1bb6272018-09-06 09:59:22 -07002923 @Override
2924 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002925 if (!isActiveSubscription(subId)) {
2926 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2927 }
2928
Pengquan Menga1bb6272018-09-06 09:59:22 -07002929 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2930 }
2931
Brad Ebinger35c841c2018-10-01 10:40:55 -07002932 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002933 public boolean isInEmergencySmsMode() {
2934 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2935 final long identity = Binder.clearCallingIdentity();
2936 try {
2937 for (Phone phone : PhoneFactory.getPhones()) {
2938 if (phone.isInEmergencySmsMode()) {
2939 return true;
2940 }
2941 }
2942 } finally {
2943 Binder.restoreCallingIdentity(identity);
2944 }
2945 return false;
2946 }
2947
2948 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002949 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2950 throws RemoteException {
2951 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002952 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2953 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2954 "IMS not available on device.");
2955 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002956 final long token = Binder.clearCallingIdentity();
2957 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002958 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002959 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002960 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002961 } catch (ImsException e) {
2962 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002963 } finally {
2964 Binder.restoreCallingIdentity(token);
2965 }
2966 }
2967
2968 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002969 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2970 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002971 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2972 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2973 }
Meng Wangafbc5852019-09-19 17:37:13 -07002974 final long token = Binder.clearCallingIdentity();
2975 try {
2976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2977 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2978 .removeRegistrationCallbackForSubscription(c, subId);
2979 } catch (ImsException e) {
2980 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2981 + "is inactive, ignoring unregister.");
2982 // If the subscription is no longer active, just return, since the callback
2983 // will already have been removed internally.
2984 } finally {
2985 Binder.restoreCallingIdentity(token);
2986 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002987 }
2988
Brad Ebingera34a6c22019-10-22 17:36:18 -07002989 /**
2990 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2991 */
2992 @Override
2993 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2994 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2995 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2996 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2997 "IMS not available on device.");
2998 }
2999 final long token = Binder.clearCallingIdentity();
3000 try {
3001 Phone phone = getPhone(subId);
3002 if (phone == null) {
3003 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3004 + subId + "'");
3005 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3006 }
3007 phone.getImsRegistrationState(regState -> {
3008 try {
3009 consumer.accept((regState == null)
3010 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3011 } catch (RemoteException e) {
3012 // Ignore if the remote process is no longer available to call back.
3013 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3014 }
3015 });
3016 } finally {
3017 Binder.restoreCallingIdentity(token);
3018 }
3019 }
3020
3021 /**
3022 * Get the transport type for the IMS service registration state.
3023 */
3024 @Override
3025 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3026 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3027 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3028 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3029 "IMS not available on device.");
3030 }
3031 final long token = Binder.clearCallingIdentity();
3032 try {
3033 Phone phone = getPhone(subId);
3034 if (phone == null) {
3035 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3036 + subId + "'");
3037 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3038 }
3039 phone.getImsRegistrationTech(regTech -> {
3040 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3041 int regTechConverted = (regTech == null)
3042 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3043 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3044 regTechConverted);
3045 try {
3046 consumer.accept(regTechConverted);
3047 } catch (RemoteException e) {
3048 // Ignore if the remote process is no longer available to call back.
3049 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3050 }
3051 });
3052 } finally {
3053 Binder.restoreCallingIdentity(token);
3054 }
3055 }
3056
Brad Ebinger35c841c2018-10-01 10:40:55 -07003057 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003058 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3059 throws RemoteException {
3060 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003061 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3062 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3063 "IMS not available on device.");
3064 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003065 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3066 final long token = Binder.clearCallingIdentity();
3067 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003068 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003069 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003070 } catch (ImsException e) {
3071 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003072 } finally {
3073 Binder.restoreCallingIdentity(token);
3074 }
3075 }
3076
3077 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003078 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3079 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003080 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3081 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3082 }
Meng Wangafbc5852019-09-19 17:37:13 -07003083
3084 final long token = Binder.clearCallingIdentity();
3085 try {
3086 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3087 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003088 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003089 } catch (ImsException e) {
3090 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3091 + "is inactive, ignoring unregister.");
3092 // If the subscription is no longer active, just return, since the callback
3093 // will already have been removed internally.
3094 } finally {
3095 Binder.restoreCallingIdentity(token);
3096 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003097 }
3098
3099 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003100 public boolean isCapable(int subId, int capability, int regTech) {
3101 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3103 final long token = Binder.clearCallingIdentity();
3104 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003105 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003106 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003107 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3109 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003110 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003111 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3112 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003113 } finally {
3114 Binder.restoreCallingIdentity(token);
3115 }
3116 }
3117
3118 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003119 public boolean isAvailable(int subId, int capability, int regTech) {
3120 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003121 final long token = Binder.clearCallingIdentity();
3122 try {
3123 Phone phone = getPhone(subId);
3124 if (phone == null) return false;
3125 return phone.isImsCapabilityAvailable(capability, regTech);
3126 } finally {
3127 Binder.restoreCallingIdentity(token);
3128 }
3129 }
3130
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003131 /**
3132 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3133 * subscription.
3134 * @param subId The subscription to use to check the configuration.
3135 * @param callback The callback that will be used to send the result.
3136 * @param capability The MmTelFeature capability that will be used to send the result.
3137 * @param transportType The transport type of the MmTelFeature capability.
3138 */
3139 @Override
3140 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3141 int transportType) {
3142 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3143 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3144 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3145 "IMS not available on device.");
3146 }
3147 final long token = Binder.clearCallingIdentity();
3148 try {
3149 int slotId = getSlotIndex(subId);
3150 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3151 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3152 + subId + "'");
3153 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3154 }
3155 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3156 transportType, aBoolean -> {
3157 try {
3158 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3159 } catch (RemoteException e) {
3160 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3161 + "running. Ignore");
3162 }
3163 });
3164 } finally {
3165 Binder.restoreCallingIdentity(token);
3166 }
3167 }
3168
Brad Ebinger35c841c2018-10-01 10:40:55 -07003169 @Override
3170 public boolean isAdvancedCallingSettingEnabled(int subId) {
3171 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3172 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3173 final long token = Binder.clearCallingIdentity();
3174 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003175 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003176 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003177 } catch (ImsException e) {
3178 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003179 } finally {
3180 Binder.restoreCallingIdentity(token);
3181 }
3182 }
3183
3184 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003185 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003187 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003188 final long identity = Binder.clearCallingIdentity();
3189 try {
3190 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003191 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003192 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003193 } catch (ImsException e) {
3194 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003195 } finally {
3196 Binder.restoreCallingIdentity(identity);
3197 }
3198 }
3199
3200 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003201 public boolean isVtSettingEnabled(int subId) {
3202 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003206 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3207 } catch (ImsException e) {
3208 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003209 } finally {
3210 Binder.restoreCallingIdentity(identity);
3211 }
3212 }
3213
3214 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003215 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003217 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003218 final long identity = Binder.clearCallingIdentity();
3219 try {
3220 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003221 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003222 } catch (ImsException e) {
3223 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003224 } finally {
3225 Binder.restoreCallingIdentity(identity);
3226 }
3227 }
3228
3229 @Override
3230 public boolean isVoWiFiSettingEnabled(int subId) {
3231 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3232 final long identity = Binder.clearCallingIdentity();
3233 try {
3234 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003235 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003236 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003237 } catch (ImsException e) {
3238 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003239 } finally {
3240 Binder.restoreCallingIdentity(identity);
3241 }
3242 }
3243
3244 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003245 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003247 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 final long identity = Binder.clearCallingIdentity();
3249 try {
3250 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003251 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003252 } catch (ImsException e) {
3253 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003254 } finally {
3255 Binder.restoreCallingIdentity(identity);
3256 }
3257 }
3258
3259 @Override
3260 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3261 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3262 final long identity = Binder.clearCallingIdentity();
3263 try {
3264 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003265 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003266 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003267 } catch (ImsException e) {
3268 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003269 } finally {
3270 Binder.restoreCallingIdentity(identity);
3271 }
3272 }
3273
3274 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003275 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003277 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003281 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003282 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003283 } catch (ImsException e) {
3284 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003285 } finally {
3286 Binder.restoreCallingIdentity(identity);
3287 }
3288 }
3289
3290 @Override
3291 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3293 "setVoWiFiNonPersistent");
3294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003297 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003298 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003299 } catch (ImsException e) {
3300 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003301 } finally {
3302 Binder.restoreCallingIdentity(identity);
3303 }
3304 }
3305
3306 @Override
3307 public int getVoWiFiModeSetting(int subId) {
3308 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003312 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003313 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003314 } catch (ImsException e) {
3315 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003316 } finally {
3317 Binder.restoreCallingIdentity(identity);
3318 }
3319 }
3320
3321 @Override
3322 public void setVoWiFiModeSetting(int subId, int mode) {
3323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3324 "setVoWiFiModeSetting");
3325 final long identity = Binder.clearCallingIdentity();
3326 try {
3327 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003328 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003329 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003330 } catch (ImsException e) {
3331 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003332 } finally {
3333 Binder.restoreCallingIdentity(identity);
3334 }
3335 }
3336
3337 @Override
3338 public int getVoWiFiRoamingModeSetting(int subId) {
3339 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3340 final long identity = Binder.clearCallingIdentity();
3341 try {
3342 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003343 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003344 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003345 } catch (ImsException e) {
3346 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
3350 }
3351
3352 @Override
3353 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3355 "setVoWiFiRoamingModeSetting");
3356 final long identity = Binder.clearCallingIdentity();
3357 try {
3358 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003359 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003360 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003361 } catch (ImsException e) {
3362 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 } finally {
3364 Binder.restoreCallingIdentity(identity);
3365 }
3366 }
3367
3368 @Override
3369 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3371 "setRttCapabilityEnabled");
3372 final long identity = Binder.clearCallingIdentity();
3373 try {
3374 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003375 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3376 } catch (ImsException e) {
3377 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003378 } finally {
3379 Binder.restoreCallingIdentity(identity);
3380 }
3381 }
3382
3383 @Override
3384 public boolean isTtyOverVolteEnabled(int subId) {
3385 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003389 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003390 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003391 } catch (ImsException e) {
3392 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003393 } finally {
3394 Binder.restoreCallingIdentity(identity);
3395 }
3396 }
3397
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003398 @Override
3399 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3400 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3401 final long identity = Binder.clearCallingIdentity();
3402 try {
3403 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003404 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003405 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003406 } catch (ImsException e) {
3407 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003408 } finally {
3409 Binder.restoreCallingIdentity(identity);
3410 }
3411 }
3412
3413 @Override
3414 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3415 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3416 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003417 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3418 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3419 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003420 try {
3421 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003422 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003423 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003424 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003425 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3426 + "is inactive, ignoring unregister.");
3427 // If the subscription is no longer active, just return, since the callback will already
3428 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003429 } finally {
3430 Binder.restoreCallingIdentity(identity);
3431 }
3432 }
3433
3434 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003435 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3436 boolean isProvisioned) {
3437 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3438 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3439 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3440 }
3441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3442 "setProvisioningStatusForCapability");
3443 final long identity = Binder.clearCallingIdentity();
3444 try {
3445 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3446 Phone phone = getPhone(subId);
3447 if (phone == null) {
3448 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3449 + subId);
3450 return;
3451 }
3452 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3453 return;
3454 }
3455
3456 // this capability requires provisioning, route to the correct API.
3457 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3458 switch (capability) {
3459 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3460 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3461 ims.setVolteProvisioned(isProvisioned);
3462 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3463 ims.setWfcProvisioned(isProvisioned);
3464 }
3465 break;
3466 }
3467 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3468 // There is currently no difference in VT provisioning type.
3469 ims.setVtProvisioned(isProvisioned);
3470 break;
3471 }
3472 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3473 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3474 // change the capability of the feature instead if needed.
3475 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3476 == isProvisioned) {
3477 // No change in provisioning.
3478 return;
3479 }
3480 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3481 try {
3482 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003483 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003484 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3485 + ", Exception" + e.getMessage());
3486 }
3487 break;
3488 }
3489 default: {
3490 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3491 + capability + "', which does not require provisioning.");
3492 }
3493 }
3494
3495 } finally {
3496 Binder.restoreCallingIdentity(identity);
3497 }
3498 }
3499
3500 @Override
3501 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3502 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3503 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3504 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3505 }
3506 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3510 Phone phone = getPhone(subId);
3511 if (phone == null) {
3512 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3513 + subId);
3514 // We will fail with "true" as the provisioning status because this is the default
3515 // if we do not require provisioning.
3516 return true;
3517 }
3518
3519 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3520 return true;
3521 }
3522
3523 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3524 switch (capability) {
3525 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3526 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3527 return ims.isVolteProvisionedOnDevice();
3528 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3529 return ims.isWfcProvisionedOnDevice();
3530 }
3531 // This should never happen, since we are checking tech above to make sure it
3532 // is either LTE or IWLAN.
3533 throw new IllegalArgumentException("Invalid radio technology for voice "
3534 + "capability.");
3535 }
3536 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3537 // There is currently no difference in VT provisioning type.
3538 return ims.isVtProvisionedOnDevice();
3539 }
3540 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3541 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3542 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3543 }
3544 default: {
3545 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3546 + capability + "', which does not require provisioning.");
3547 }
3548 }
3549
3550 } finally {
3551 Binder.restoreCallingIdentity(identity);
3552 }
3553 }
3554
3555 @Override
3556 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3557 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3558 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3559 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3560 }
3561 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3562 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3563 return (provisionedBits & capability) > 0;
3564 }
3565
3566 @Override
3567 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3568 boolean isProvisioned) {
3569 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3570 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3571 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3572 }
3573 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3574 "setProvisioningStatusForCapability");
3575 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3576 // If the current provisioning status for capability already matches isProvisioned,
3577 // do nothing.
3578 if (((provisionedBits & capability) > 0) == isProvisioned) {
3579 return;
3580 }
3581 if (isProvisioned) {
3582 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3583 } else {
3584 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3585 }
3586 }
3587
3588 /**
3589 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3590 * technology. The bitfield should mirror the bitfield defined by
3591 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3592 */
3593 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3594 String key = getMmTelProvisioningKey(subId, tech);
3595 // Default is no capabilities are provisioned.
3596 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3597 }
3598
3599 /**
3600 * Sets the MmTel capability provisioning bitfield (defined by
3601 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3602 * technology specified.
3603 *
3604 * Note: This is a synchronous command and should not be called on UI thread.
3605 */
3606 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3607 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3608 String key = getMmTelProvisioningKey(subId, tech);
3609 editor.putInt(key, newField);
3610 editor.commit();
3611 }
3612
3613 private static String getMmTelProvisioningKey(int subId, int tech) {
3614 // resulting key is provision_ims_mmtel_{subId}_{tech}
3615 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3616 }
3617
3618 /**
3619 * Query CarrierConfig to see if the specified capability requires provisioning for the
3620 * carrier associated with the subscription id.
3621 */
3622 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3623 int capability) {
3624 CarrierConfigManager configManager = new CarrierConfigManager(context);
3625 PersistableBundle c = configManager.getConfigForSubId(subId);
3626 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003627 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003628 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3629 false);
3630 boolean requireVoiceVtProvisioning = c.getBoolean(
3631 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3632
3633 // First check to make sure that the capability requires provisioning.
3634 switch (capability) {
3635 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3636 // intentional fallthrough
3637 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3638 if (requireVoiceVtProvisioning) {
3639 // Voice and Video requires provisioning
3640 return true;
3641 }
3642 break;
3643 }
3644 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3645 if (requireUtProvisioning) {
3646 // UT requires provisioning
3647 return true;
3648 }
3649 break;
3650 }
3651 }
3652 return false;
3653 }
3654
3655 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003656 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003657 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3658 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3659 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003660 enforceReadPrivilegedPermission("getImsProvisioningInt");
3661 final long identity = Binder.clearCallingIdentity();
3662 try {
3663 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003664 int slotId = getSlotIndex(subId);
3665 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3666 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3667 + subId + "' for key:" + key);
3668 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3669 }
3670 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003671 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003672 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3673 + subId + "' for key:" + key);
3674 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003675 } finally {
3676 Binder.restoreCallingIdentity(identity);
3677 }
3678 }
3679
3680 @Override
3681 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003682 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3683 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3684 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003685 enforceReadPrivilegedPermission("getImsProvisioningString");
3686 final long identity = Binder.clearCallingIdentity();
3687 try {
3688 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003689 int slotId = getSlotIndex(subId);
3690 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3691 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3692 + subId + "' for key:" + key);
3693 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3694 }
3695 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003696 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003697 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3698 + subId + "' for key:" + key);
3699 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003700 } finally {
3701 Binder.restoreCallingIdentity(identity);
3702 }
3703 }
3704
3705 @Override
3706 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003707 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3708 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3709 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3711 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003712 final long identity = Binder.clearCallingIdentity();
3713 try {
3714 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003715 int slotId = getSlotIndex(subId);
3716 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3717 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3718 + subId + "' for key:" + key);
3719 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3720 }
3721 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003722 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003723 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3724 + "' for key:" + key);
3725 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
3729 }
3730
3731 @Override
3732 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003733 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3734 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3735 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3737 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003738 final long identity = Binder.clearCallingIdentity();
3739 try {
3740 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003741 int slotId = getSlotIndex(subId);
3742 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3743 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3744 + subId + "' for key:" + key);
3745 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3746 }
3747 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003748 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003749 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3750 + "' for key:" + key);
3751 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003752 } finally {
3753 Binder.restoreCallingIdentity(identity);
3754 }
3755 }
3756
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003757 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003758 int slotId = SubscriptionManager.getSlotIndex(subId);
3759 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003760 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3761 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003762 }
3763 return slotId;
3764 }
3765
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003766 private int getSlotIndex(int subId) {
3767 int slotId = SubscriptionManager.getSlotIndex(subId);
3768 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3769 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3770 }
3771 return slotId;
3772 }
3773
Wink Saville36469e72014-06-11 15:17:00 -07003774 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003775 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003776 */
3777 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003778 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3779 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003780 final int targetSdk = getTargetSdk(callingPackage);
3781 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003782 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003783 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003784 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003785 mApp, subId, callingPackage, callingFeatureId,
3786 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003787 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3788 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790 final long identity = Binder.clearCallingIdentity();
3791 try {
3792 final Phone phone = getPhone(subId);
3793 if (phone != null) {
3794 return phone.getServiceState().getDataNetworkType();
3795 } else {
3796 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3797 }
3798 } finally {
3799 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003800 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003801 }
3802
3803 /**
3804 * Returns the data network type
3805 */
3806 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003807 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3808 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3809 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003810 }
3811
3812 /**
3813 * Returns the data network type for a subId
3814 */
3815 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003816 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3817 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003818 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003819 mApp, subId, callingPackage, callingFeatureId,
3820 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003821 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3822 }
3823
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003824 final long identity = Binder.clearCallingIdentity();
3825 try {
3826 final Phone phone = getPhone(subId);
3827 if (phone != null) {
3828 return phone.getServiceState().getDataNetworkType();
3829 } else {
3830 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3831 }
3832 } finally {
3833 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003834 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003835 }
3836
3837 /**
Wink Saville36469e72014-06-11 15:17:00 -07003838 * Returns the Voice network type for a subId
3839 */
3840 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003841 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3842 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003843 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003844 mApp, subId, callingPackage, callingFeatureId,
3845 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003846 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3847 }
3848
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003849 final long identity = Binder.clearCallingIdentity();
3850 try {
3851 final Phone phone = getPhone(subId);
3852 if (phone != null) {
3853 return phone.getServiceState().getVoiceNetworkType();
3854 } else {
3855 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3856 }
3857 } finally {
3858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003860 }
3861
3862 /**
3863 * @return true if a ICC card is present
3864 */
3865 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003866 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003867 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3868 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003869 }
3870
3871 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003872 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003873 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003874 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003875 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003876 final long identity = Binder.clearCallingIdentity();
3877 try {
3878 final Phone phone = PhoneFactory.getPhone(slotIndex);
3879 if (phone != null) {
3880 return phone.getIccCard().hasIccCard();
3881 } else {
3882 return false;
3883 }
3884 } finally {
3885 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003887 }
3888
3889 /**
3890 * Return if the current radio is LTE on CDMA. This
3891 * is a tri-state return value as for a period of time
3892 * the mode may be unknown.
3893 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003894 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003895 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003896 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003897 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003898 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003899 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3900 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3901 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003902 }
3903
Sanket Padawe356d7632015-06-22 14:03:32 -07003904 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003905 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3906 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003907 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003908 mApp, subId, callingPackage, callingFeatureId,
3909 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003910 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3911 }
3912
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 final Phone phone = getPhone(subId);
3916 if (phone == null) {
3917 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3918 } else {
3919 return phone.getLteOnCdmaMode();
3920 }
3921 } finally {
3922 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003923 }
Wink Saville36469e72014-06-11 15:17:00 -07003924 }
3925
Wink Saville36469e72014-06-11 15:17:00 -07003926 /**
3927 * {@hide}
3928 * Returns Default subId, 0 in the case of single standby.
3929 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003930 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003931 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003932 }
3933
Shishir Agrawala9f32182016-04-12 12:00:16 -07003934 private int getSlotForDefaultSubscription() {
3935 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3936 }
3937
Wink Savilleb564aae2014-10-23 10:18:09 -07003938 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003939 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003940 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003941
Pengquan Menge92a50d2018-09-21 15:54:48 -07003942 private boolean isActiveSubscription(int subId) {
3943 return mSubscriptionController.isActiveSubId(subId);
3944 }
3945
Ihab Awadf2177b72013-11-25 13:33:23 -08003946 /**
3947 * @see android.telephony.TelephonyManager.WifiCallingChoices
3948 */
3949 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003950 final long identity = Binder.clearCallingIdentity();
3951 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003952 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3954 getWhenToMakeWifiCallsDefaultPreference());
3955 } finally {
3956 Binder.restoreCallingIdentity(identity);
3957 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003958 }
3959
3960 /**
3961 * @see android.telephony.TelephonyManager.WifiCallingChoices
3962 */
3963 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003964 final long identity = Binder.clearCallingIdentity();
3965 try {
3966 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003967 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003968 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3969 } finally {
3970 Binder.restoreCallingIdentity(identity);
3971 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003972 }
3973
Sailesh Nepald1e68152013-12-12 19:08:02 -08003974 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003975 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003976 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003977 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003978
Jordan Liu4c733742019-02-28 12:03:40 -08003979 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3980 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3981 if (phoneId == -1) {
3982 throw new IllegalArgumentException("Given slot index: " + slotIndex
3983 + " does not correspond to an active phone");
3984 }
3985 return PhoneFactory.getPhone(phoneId);
3986 }
3987
Shishir Agrawal566b7612013-10-28 14:41:00 -07003988 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003989 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3990 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3992 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003993 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003994 if (DBG) {
3995 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3996 }
3997 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3998 p2);
3999 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004000
Jordan Liu4c733742019-02-28 12:03:40 -08004001
4002 @Override
4003 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4004 int slotIndex, String callingPackage, String aid, int p2) {
4005 enforceModifyPermission();
4006 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4007 if (DBG) {
4008 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4009 }
4010 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4011 callingPackage, aid, p2);
4012 }
4013
4014 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4015 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 if (TextUtils.equals(ISDR_AID, aid)) {
4019 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004020 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4021 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004022 if (bestComponent == null
4023 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4024 loge("The calling package is not allowed to access ISD-R.");
4025 throw new SecurityException(
4026 "The calling package is not allowed to access ISD-R.");
4027 }
Derek Tan740e1672017-06-27 14:56:27 -07004028 }
Derek Tan740e1672017-06-27 14:56:27 -07004029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004030 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004031 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4032 null /* workSource */);
4033 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004034 return response;
4035 } finally {
4036 Binder.restoreCallingIdentity(identity);
4037 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004038 }
4039
4040 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004041 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4043 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004044 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4045 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4046 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004047
Jordan Liu4c733742019-02-28 12:03:40 -08004048 @Override
4049 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4050 enforceModifyPermission();
4051 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4052 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4053 channel);
4054 }
4055
4056 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004057 final long identity = Binder.clearCallingIdentity();
4058 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004059 if (channel < 0) {
4060 return false;
4061 }
Jordan Liu4c733742019-02-28 12:03:40 -08004062 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4063 null /* workSource */);
4064 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004065 return success;
4066 } finally {
4067 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004068 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004069 }
4070
4071 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004072 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004073 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4075 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004076 if (DBG) {
4077 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4078 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4079 + p3 + " data=" + data);
4080 }
4081 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4082 command, p1, p2, p3, data);
4083 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004084
Jordan Liu4c733742019-02-28 12:03:40 -08004085 @Override
4086 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4087 int command, int p1, int p2, int p3, String data) {
4088 enforceModifyPermission();
4089 if (DBG) {
4090 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4091 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4092 + p3 + " data=" + data);
4093 }
4094 return iccTransmitApduLogicalChannelWithPermission(
4095 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4096 data);
4097 }
4098
4099 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4100 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101 final long identity = Binder.clearCallingIdentity();
4102 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004103 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104 return "";
4105 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004107 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004108 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4109 null /* workSource */);
4110 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112 // Append the returned status code to the end of the response payload.
4113 String s = Integer.toHexString(
4114 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4115 if (response.payload != null) {
4116 s = IccUtils.bytesToHexString(response.payload) + s;
4117 }
4118 return s;
4119 } finally {
4120 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004121 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004122 }
Jake Hambye994d462014-02-03 13:10:13 -08004123
Evan Charltonc66da362014-05-16 14:06:40 -07004124 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004125 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4126 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004127 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4128 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004129 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004130 if (DBG) {
4131 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4132 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4133 }
4134 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4135 cla, command, p1, p2, p3, data);
4136 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004137
Jordan Liu4c733742019-02-28 12:03:40 -08004138 @Override
4139 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4140 int command, int p1, int p2, int p3, String data) {
4141 enforceModifyPermission();
4142 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4143 if (DBG) {
4144 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4145 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4146 + " data=" + data);
4147 }
4148
4149 return iccTransmitApduBasicChannelWithPermission(
4150 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4151 p2, p3, data);
4152 }
4153
4154 // open APDU basic channel assuming the caller has sufficient permissions
4155 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4156 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004157 final long identity = Binder.clearCallingIdentity();
4158 try {
4159 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4160 && TextUtils.equals(ISDR_AID, data)) {
4161 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004162 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4163 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004164 if (bestComponent == null
4165 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4166 loge("The calling package is not allowed to select ISD-R.");
4167 throw new SecurityException(
4168 "The calling package is not allowed to select ISD-R.");
4169 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004170 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004172 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004173 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4174 null /* workSource */);
4175 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004176
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177 // Append the returned status code to the end of the response payload.
4178 String s = Integer.toHexString(
4179 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4180 if (response.payload != null) {
4181 s = IccUtils.bytesToHexString(response.payload) + s;
4182 }
4183 return s;
4184 } finally {
4185 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004186 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004187 }
4188
4189 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004190 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004191 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004192 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4193 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 if (DBG) {
4198 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4199 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4200 }
4201
4202 IccIoResult response =
4203 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4204 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4205 subId);
4206
4207 if (DBG) {
4208 log("Exchange SIM_IO [R]" + response);
4209 }
4210
4211 byte[] result = null;
4212 int length = 2;
4213 if (response.payload != null) {
4214 length = 2 + response.payload.length;
4215 result = new byte[length];
4216 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4217 } else {
4218 result = new byte[length];
4219 }
4220
4221 result[length - 1] = (byte) response.sw2;
4222 result[length - 2] = (byte) response.sw1;
4223 return result;
4224 } finally {
4225 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004226 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004227 }
4228
Nathan Haroldb3014052017-01-25 15:57:32 -08004229 /**
4230 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4231 * on a particular subscription
4232 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004233 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4234 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004236 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004237 return null;
4238 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004239
4240 final long identity = Binder.clearCallingIdentity();
4241 try {
4242 if (appType != TelephonyManager.APPTYPE_USIM
4243 && appType != TelephonyManager.APPTYPE_SIM) {
4244 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4245 return null;
4246 }
4247 Object response = sendRequest(
4248 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4249 if (response instanceof String[]) {
4250 return (String[]) response;
4251 }
yincheng zhao2737e882019-09-06 17:06:54 -07004252 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004254 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004255 } finally {
4256 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004257 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004258 }
4259
yincheng zhao2737e882019-09-06 17:06:54 -07004260 /**
4261 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4262 * subscription.
4263 *
4264 * @param subId the id of the subscription.
4265 * @param appType the uicc app type, must be USIM or SIM.
4266 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4267 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004268 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004269 * @return number of fplmns that is successfully written to the SIM.
4270 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004271 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4272 String callingFeatureId) {
4273 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4274 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004275 if (DBG) logv("no permissions for setForbiddenplmns");
4276 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4277 }
4278 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4279 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4280 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4281 }
4282 if (fplmns == null) {
4283 throw new IllegalArgumentException("Fplmn List provided is null");
4284 }
4285 for (String fplmn : fplmns) {
4286 if (!CellIdentity.isValidPlmn(fplmn)) {
4287 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4288 }
4289 }
4290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 Object response = sendRequest(
4293 CMD_SET_FORBIDDEN_PLMNS,
4294 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4295 subId);
4296 return (int) response;
4297 } finally {
4298 Binder.restoreCallingIdentity(identity);
4299 }
4300 }
4301
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004302 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004303 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4305 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307 final long identity = Binder.clearCallingIdentity();
4308 try {
4309 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4310 if (response.payload == null) {
4311 return "";
4312 }
Evan Charltonc66da362014-05-16 14:06:40 -07004313
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004314 // Append the returned status code to the end of the response payload.
4315 String s = Integer.toHexString(
4316 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4317 s = IccUtils.bytesToHexString(response.payload) + s;
4318 return s;
4319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
Evan Charltonc66da362014-05-16 14:06:40 -07004322 }
4323
Jake Hambye994d462014-02-03 13:10:13 -08004324 /**
4325 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4326 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4327 *
4328 * @param itemID the ID of the item to read
4329 * @return the NV item as a String, or null on error.
4330 */
4331 @Override
4332 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004333 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4335 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004336
4337 final long identity = Binder.clearCallingIdentity();
4338 try {
4339 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004340 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004341 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4342 return value;
4343 } finally {
4344 Binder.restoreCallingIdentity(identity);
4345 }
Jake Hambye994d462014-02-03 13:10:13 -08004346 }
4347
4348 /**
4349 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4350 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4351 *
4352 * @param itemID the ID of the item to read
4353 * @param itemValue the value to write, as a String
4354 * @return true on success; false on any failure
4355 */
4356 @Override
4357 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004358 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4360 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004361
4362 final long identity = Binder.clearCallingIdentity();
4363 try {
4364 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4365 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004366 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4368 return success;
4369 } finally {
4370 Binder.restoreCallingIdentity(identity);
4371 }
Jake Hambye994d462014-02-03 13:10:13 -08004372 }
4373
4374 /**
4375 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4376 * Used for device configuration by some CDMA operators.
4377 *
4378 * @param preferredRoamingList byte array containing the new PRL
4379 * @return true on success; false on any failure
4380 */
4381 @Override
4382 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4384 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004385
4386 final long identity = Binder.clearCallingIdentity();
4387 try {
4388 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4389 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4390 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4391 return success;
4392 } finally {
4393 Binder.restoreCallingIdentity(identity);
4394 }
Jake Hambye994d462014-02-03 13:10:13 -08004395 }
4396
4397 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004398 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004399 * Used for device configuration by some CDMA operators.
4400 *
chen xu6dac5ab2018-10-26 17:39:23 -07004401 * @param slotIndex - device slot.
4402 *
Jake Hambye994d462014-02-03 13:10:13 -08004403 * @return true on success; false on any failure
4404 */
4405 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004406 public boolean resetModemConfig(int slotIndex) {
4407 Phone phone = PhoneFactory.getPhone(slotIndex);
4408 if (phone != null) {
4409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4410 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004411
chen xu6dac5ab2018-10-26 17:39:23 -07004412 final long identity = Binder.clearCallingIdentity();
4413 try {
4414 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4415 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4416 return success;
4417 } finally {
4418 Binder.restoreCallingIdentity(identity);
4419 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420 }
chen xu6dac5ab2018-10-26 17:39:23 -07004421 return false;
4422 }
4423
4424 /**
4425 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4426 *
4427 * @param slotIndex - device slot.
4428 *
4429 * @return true on success; false on any failure
4430 */
4431 @Override
4432 public boolean rebootModem(int slotIndex) {
4433 Phone phone = PhoneFactory.getPhone(slotIndex);
4434 if (phone != null) {
4435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4436 mApp, phone.getSubId(), "rebootModem");
4437
4438 final long identity = Binder.clearCallingIdentity();
4439 try {
4440 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4441 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4442 return success;
4443 } finally {
4444 Binder.restoreCallingIdentity(identity);
4445 }
4446 }
4447 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004448 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004449
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004450 public String[] getPcscfAddress(String apnType, String callingPackage,
4451 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004452 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004453 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4454 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004455 return new String[0];
4456 }
4457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458 final long identity = Binder.clearCallingIdentity();
4459 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004460 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004461 } finally {
4462 Binder.restoreCallingIdentity(identity);
4463 }
Wink Saville36469e72014-06-11 15:17:00 -07004464 }
4465
Brad Ebinger51f743a2017-01-23 13:50:20 -08004466 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004467 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4468 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004469 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004470 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004471 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472
4473 final long identity = Binder.clearCallingIdentity();
4474 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004475 ImsResolver resolver = PhoneFactory.getImsResolver();
4476 if (resolver == null) {
4477 // may happen if the device does not support IMS.
4478 return;
4479 }
4480 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004484 }
4485
4486 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004487 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4488 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004489 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004490 public void disableIms(int slotId) {
4491 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492
4493 final long identity = Binder.clearCallingIdentity();
4494 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004495 ImsResolver resolver = PhoneFactory.getImsResolver();
4496 if (resolver == null) {
4497 // may happen if the device does not support IMS.
4498 return;
4499 }
4500 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004504 }
4505
4506 /**
4507 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4508 * feature or {@link null} if the service is not available. If the feature is available, the
4509 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4510 */
4511 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004512 IImsServiceFeatureCallback callback) {
4513 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514
4515 final long identity = Binder.clearCallingIdentity();
4516 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004517 ImsResolver resolver = PhoneFactory.getImsResolver();
4518 if (resolver == null) {
4519 // may happen if the device does not support IMS.
4520 return null;
4521 }
4522 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004523 } finally {
4524 Binder.restoreCallingIdentity(identity);
4525 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004526 }
4527
4528 /**
4529 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4530 * feature during emergency calling or {@link null} if the service is not available. If the
4531 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4532 * listener for feature updates.
4533 */
4534 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4535 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004536
4537 final long identity = Binder.clearCallingIdentity();
4538 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004539 ImsResolver resolver = PhoneFactory.getImsResolver();
4540 if (resolver == null) {
4541 // may happen if the device does not support IMS.
4542 return null;
4543 }
4544 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004545 } finally {
4546 Binder.restoreCallingIdentity(identity);
4547 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004548 }
4549
Brad Ebinger5f64b052017-12-14 14:26:15 -08004550 /**
4551 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004552 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004553 */
4554 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556
4557 final long identity = Binder.clearCallingIdentity();
4558 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004559 ImsResolver resolver = PhoneFactory.getImsResolver();
4560 if (resolver == null) {
4561 // may happen if the device does not support IMS.
4562 return null;
4563 }
4564 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004565 } finally {
4566 Binder.restoreCallingIdentity(identity);
4567 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004568 }
4569
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004570 /**
4571 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004572 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004573 */
4574 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4575 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004576
4577 final long identity = Binder.clearCallingIdentity();
4578 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004579 ImsResolver resolver = PhoneFactory.getImsResolver();
4580 if (resolver == null) {
4581 // may happen if the device does not support IMS.
4582 return null;
4583 }
4584 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004585 } finally {
4586 Binder.restoreCallingIdentity(identity);
4587 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004588 }
4589
Brad Ebinger884c07b2018-02-15 16:17:40 -08004590 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004591 * Sets the ImsService Package Name that Telephony will bind to.
4592 *
4593 * @param slotId the slot ID that the ImsService should bind for.
4594 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4595 * ImsService is the device default ImsService.
4596 * @param packageName The package name of the application that contains the ImsService to bind
4597 * to.
4598 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4599 * @hide
4600 */
4601 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004602 int[] subIds = SubscriptionManager.getSubId(slotId);
4603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4604 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4605 "setImsService");
4606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004607 final long identity = Binder.clearCallingIdentity();
4608 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004609 ImsResolver resolver = PhoneFactory.getImsResolver();
4610 if (resolver == null) {
4611 // may happen if the device does not support IMS.
4612 return false;
4613 }
4614 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4615 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616 } finally {
4617 Binder.restoreCallingIdentity(identity);
4618 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004619 }
4620
4621 /**
4622 * Return the ImsService configuration.
4623 *
4624 * @param slotId The slot that the ImsService is associated with.
4625 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4626 * the device default.
4627 * @return the package name of the ImsService configuration.
4628 */
4629 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004630 int[] subIds = SubscriptionManager.getSubId(slotId);
4631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4632 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4633 "getImsService");
4634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635 final long identity = Binder.clearCallingIdentity();
4636 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004637 ImsResolver resolver = PhoneFactory.getImsResolver();
4638 if (resolver == null) {
4639 // may happen if the device does not support IMS.
4640 return "";
4641 }
4642 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004643 } finally {
4644 Binder.restoreCallingIdentity(identity);
4645 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004646 }
4647
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004648 /**
4649 * Get the MmTelFeature state associated with the requested subscription id.
4650 * @param subId The subscription that the MmTelFeature is associated with.
4651 * @param callback A callback with an integer containing the
4652 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4653 */
4654 @Override
4655 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4656 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4657 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4658 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4659 "IMS not available on device.");
4660 }
4661 final long token = Binder.clearCallingIdentity();
4662 try {
4663 int slotId = getSlotIndex(subId);
4664 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4665 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4666 + subId + "'");
4667 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4668 }
4669 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4670 try {
4671 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4672 } catch (RemoteException e) {
4673 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4674 + "Ignore");
4675 }
4676 });
4677 } finally {
4678 Binder.restoreCallingIdentity(token);
4679 }
4680 }
4681
Wink Saville36469e72014-06-11 15:17:00 -07004682 public void setImsRegistrationState(boolean registered) {
4683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004684
4685 final long identity = Binder.clearCallingIdentity();
4686 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004687 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004688 } finally {
4689 Binder.restoreCallingIdentity(identity);
4690 }
Wink Saville36469e72014-06-11 15:17:00 -07004691 }
4692
4693 /**
Stuart Scott54788802015-03-30 13:18:01 -07004694 * Set the network selection mode to automatic.
4695 *
4696 */
4697 @Override
4698 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4700 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004701
Pengquan Menge92a50d2018-09-21 15:54:48 -07004702 if (!isActiveSubscription(subId)) {
4703 return;
4704 }
4705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004706 final long identity = Binder.clearCallingIdentity();
4707 try {
4708 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4709 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4710 } finally {
4711 Binder.restoreCallingIdentity(identity);
4712 }
Stuart Scott54788802015-03-30 13:18:01 -07004713 }
4714
Pengquan Mengea84e042018-09-20 14:57:26 -07004715 /**
4716 * Ask the radio to connect to the input network and change selection mode to manual.
4717 *
4718 * @param subId the id of the subscription.
4719 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4720 * the operator to attach to.
4721 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4722 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4723 * normal network selection next time.
4724 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004725 */
4726 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004727 public boolean setNetworkSelectionModeManual(
4728 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4730 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004731
4732 if (!isActiveSubscription(subId)) {
4733 return false;
4734 }
4735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004736 final long identity = Binder.clearCallingIdentity();
4737 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004738 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004739 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004740 if (DBG) {
4741 log("setNetworkSelectionModeManual: subId: " + subId
4742 + " operator: " + operatorInfo);
4743 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4745 } finally {
4746 Binder.restoreCallingIdentity(identity);
4747 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004748 }
4749
4750 /**
4751 * Scans for available networks.
4752 */
4753 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004754 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4755 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4757 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004758 LocationAccessPolicy.LocationPermissionResult locationResult =
4759 LocationAccessPolicy.checkLocationPermission(mApp,
4760 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4761 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004762 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004763 .setCallingPid(Binder.getCallingPid())
4764 .setCallingUid(Binder.getCallingUid())
4765 .setMethod("getCellNetworkScanResults")
4766 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4767 .build());
4768 switch (locationResult) {
4769 case DENIED_HARD:
4770 throw new SecurityException("Not allowed to access scan results -- location");
4771 case DENIED_SOFT:
4772 return null;
4773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774
Pengquan Menga1bb6272018-09-06 09:59:22 -07004775 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776 try {
4777 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004778 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004779 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004780 } finally {
4781 Binder.restoreCallingIdentity(identity);
4782 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004783 }
4784
4785 /**
yinxub1bed742017-04-17 11:45:04 -07004786 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004787 *
yinxub1bed742017-04-17 11:45:04 -07004788 * @param subId id of the subscription
4789 * @param request contains the radio access networks with bands/channels to scan
4790 * @param messenger callback messenger for scan results or errors
4791 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004792 * @return the id of the requested scan which can be used to stop the scan.
4793 */
4794 @Override
4795 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004796 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4798 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004799 LocationAccessPolicy.LocationPermissionResult locationResult =
4800 LocationAccessPolicy.checkLocationPermission(mApp,
4801 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4802 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004803 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004804 .setCallingPid(Binder.getCallingPid())
4805 .setCallingUid(Binder.getCallingUid())
4806 .setMethod("requestNetworkScan")
4807 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4808 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004809 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004810 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004811 if (e != null) {
4812 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4813 throw e;
4814 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004815 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004816 return TelephonyScanManager.INVALID_SCAN_ID;
4817 }
4818 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819 }
Hall Liu912dfd32019-04-25 14:02:26 -07004820 int callingUid = Binder.getCallingUid();
4821 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004822 final long identity = Binder.clearCallingIdentity();
4823 try {
4824 return mNetworkScanRequestTracker.startNetworkScan(
4825 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004826 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004827 } finally {
4828 Binder.restoreCallingIdentity(identity);
4829 }
yinxu504e1392017-04-12 16:03:22 -07004830 }
4831
Hall Liub2ac8ef2019-02-28 15:56:23 -08004832 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004833 NetworkScanRequest request, int subId) {
4834 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4835 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4836 boolean hasNetworkScanPermission =
4837 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4838 == PERMISSION_GRANTED;
4839
4840 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4841 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4842 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004843 }
4844
4845 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4846 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004847 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4848 return new SecurityException("Specific channels must not be"
4849 + " scanned without location access.");
4850 }
4851 }
4852 }
4853
Hall Liub2ac8ef2019-02-28 15:56:23 -08004854 return null;
4855 }
4856
yinxu504e1392017-04-12 16:03:22 -07004857 /**
4858 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004859 *
4860 * @param subId id of the subscription
4861 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004862 */
4863 @Override
4864 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4866 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004867
Hall Liu912dfd32019-04-25 14:02:26 -07004868 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869 final long identity = Binder.clearCallingIdentity();
4870 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004871 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004872 } finally {
4873 Binder.restoreCallingIdentity(identity);
4874 }
yinxu504e1392017-04-12 16:03:22 -07004875 }
4876
4877 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004878 * Get the calculated preferred network type.
4879 * Used for debugging incorrect network type.
4880 *
4881 * @return the preferred network type, defined in RILConstants.java.
4882 */
4883 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004884 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004885 final Phone defaultPhone = getDefaultPhone();
4886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004887 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004888 return RILConstants.PREFERRED_NETWORK_MODE;
4889 }
4890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891 final long identity = Binder.clearCallingIdentity();
4892 try {
4893 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004894 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895 } finally {
4896 Binder.restoreCallingIdentity(identity);
4897 }
Junda Liu84d15a22014-07-02 11:21:04 -07004898 }
4899
4900 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004901 * Get the preferred network type.
4902 * Used for device configuration by some CDMA operators.
4903 *
4904 * @return the preferred network type, defined in RILConstants.java.
4905 */
4906 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004907 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004908 TelephonyPermissions
4909 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4910 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004911
4912 final long identity = Binder.clearCallingIdentity();
4913 try {
4914 if (DBG) log("getPreferredNetworkType");
4915 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4916 int networkType = (result != null ? result[0] : -1);
4917 if (DBG) log("getPreferredNetworkType: " + networkType);
4918 return networkType;
4919 } finally {
4920 Binder.restoreCallingIdentity(identity);
4921 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004922 }
4923
4924 /**
4925 * Set the preferred network type.
4926 * Used for device configuration by some CDMA operators.
4927 *
4928 * @param networkType the preferred network type, defined in RILConstants.java.
4929 * @return true on success; false on any failure.
4930 */
4931 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004932 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4934 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935
4936 final long identity = Binder.clearCallingIdentity();
4937 try {
4938 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4939 Boolean success = (Boolean) sendRequest(
4940 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4941 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4942 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004943 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4945 }
4946 return success;
4947 } finally {
4948 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004949 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004950 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004951
4952 /**
Miaoa84611c2019-03-15 09:21:10 +08004953 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004954 *
Miaoa84611c2019-03-15 09:21:10 +08004955 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004956 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004957 * @hide
4958 */
4959 @Override
SongFerngWangf3c7bf82019-11-07 17:27:26 +08004960 public boolean isTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004961 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004963 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964 try {
Miaoa84611c2019-03-15 09:21:10 +08004965 if (phone != null) {
4966 return phone.hasMatchedTetherApnSetting();
4967 } else {
4968 return false;
4969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 } finally {
4971 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004972 }
Junda Liu475951f2014-11-07 16:45:03 -08004973 }
4974
4975 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004976 * Set mobile data enabled
4977 * Used by the user through settings etc to turn on/off mobile data
4978 *
4979 * @param enable {@code true} turn turn data on, else {@code false}
4980 */
4981 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004982 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4984 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985
4986 final long identity = Binder.clearCallingIdentity();
4987 try {
4988 int phoneId = mSubscriptionController.getPhoneId(subId);
4989 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4990 Phone phone = PhoneFactory.getPhone(phoneId);
4991 if (phone != null) {
4992 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004993 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004995 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996 }
4997 } finally {
4998 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004999 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005000 }
5001
5002 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005003 * Get the user enabled state of Mobile Data.
5004 *
5005 * TODO: remove and use isUserDataEnabled.
5006 * This can't be removed now because some vendor codes
5007 * calls through ITelephony directly while they should
5008 * use TelephonyManager.
5009 *
5010 * @return true on enabled
5011 */
5012 @Override
5013 public boolean getDataEnabled(int subId) {
5014 return isUserDataEnabled(subId);
5015 }
5016
5017 /**
5018 * Get whether mobile data is enabled per user setting.
5019 *
5020 * There are other factors deciding whether mobile data is actually enabled, but they are
5021 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005022 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005023 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005024 *
5025 * @return {@code true} if data is enabled else {@code false}
5026 */
5027 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005028 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005029 try {
5030 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5031 null);
5032 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5034 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036
5037 final long identity = Binder.clearCallingIdentity();
5038 try {
5039 int phoneId = mSubscriptionController.getPhoneId(subId);
5040 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5041 Phone phone = PhoneFactory.getPhone(phoneId);
5042 if (phone != null) {
5043 boolean retVal = phone.isUserDataEnabled();
5044 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5045 return retVal;
5046 } else {
5047 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5048 return false;
5049 }
5050 } finally {
5051 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005052 }
5053 }
5054
5055 /**
5056 * Get whether mobile data is enabled.
5057 *
5058 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5059 * whether mobile data is actually enabled.
5060 *
5061 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5062 *
5063 * @return {@code true} if data is enabled else {@code false}
5064 */
5065 @Override
5066 public boolean isDataEnabled(int subId) {
5067 try {
5068 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5069 null);
5070 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5072 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074
5075 final long identity = Binder.clearCallingIdentity();
5076 try {
5077 int phoneId = mSubscriptionController.getPhoneId(subId);
5078 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5079 Phone phone = PhoneFactory.getPhone(phoneId);
5080 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005081 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005082 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5083 return retVal;
5084 } else {
5085 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5086 return false;
5087 }
5088 } finally {
5089 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005090 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005091 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005092
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005093 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5094 Phone phone) {
5095 //load access rules from carrier configs, and check those as well: b/139133814
5096 SubscriptionController subController = SubscriptionController.getInstance();
5097 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5098 || subController == null) return privilegeFromSim;
5099
5100 int uid = Binder.getCallingUid();
5101 PackageManager pkgMgr = phone.getContext().getPackageManager();
5102 String[] packages = pkgMgr.getPackagesForUid(uid);
5103
5104 final long identity = Binder.clearCallingIdentity();
5105 try {
5106 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5107 SubscriptionManager subManager = (SubscriptionManager)
5108 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5109 for (String pkg : packages) {
5110 if (subManager.canManageSubscription(subInfo, pkg)) {
5111 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5112 }
5113 }
5114 return privilegeFromSim;
5115 } finally {
5116 Binder.restoreCallingIdentity(identity);
5117 }
5118 }
5119
5120 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5121 String pkgName) {
5122 //load access rules from carrier configs, and check those as well: b/139133814
5123 SubscriptionController subController = SubscriptionController.getInstance();
5124 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5125 || subController == null) return privilegeFromSim;
5126
5127 final long identity = Binder.clearCallingIdentity();
5128 try {
5129 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5130 SubscriptionManager subManager = (SubscriptionManager)
5131 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5132 return subManager.canManageSubscription(subInfo, pkgName)
5133 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5134 } finally {
5135 Binder.restoreCallingIdentity(identity);
5136 }
5137 }
5138
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005139 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005140 public int getCarrierPrivilegeStatus(int subId) {
5141 final Phone phone = getPhone(subId);
5142 if (phone == null) {
5143 loge("getCarrierPrivilegeStatus: Invalid subId");
5144 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5145 }
5146 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005147 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005148 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005149 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5150 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005151
5152 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5153 card.getCarrierPrivilegeStatusForCurrentTransaction(
5154 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005155 }
Junda Liu29340342014-07-10 15:23:27 -07005156
5157 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005158 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5159 final Phone phone = getPhone(subId);
5160 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005161 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005162 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5163 }
5164 UiccProfile profile =
5165 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5166 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005167 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005168 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5169 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005170 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5171 profile.getCarrierPrivilegeStatusForUid(
5172 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005173 }
5174
5175 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005176 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5177 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005178 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005179 }
5180
5181 int phoneId = SubscriptionManager.getPhoneId(subId);
5182 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005183 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005184 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005185 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5186 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005187 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5188 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5189 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005190 }
5191
5192 @Override
5193 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005194 if (TextUtils.isEmpty(pkgName))
5195 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005196 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5197 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5198 UiccCard card = UiccController.getInstance().getUiccCard(i);
5199 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005200 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005201 continue;
5202 }
5203
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005204 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5205 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5206 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005207 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5208 break;
5209 }
5210 }
5211
5212 return result;
Junda Liu29340342014-07-10 15:23:27 -07005213 }
Derek Tan89e89d42014-07-08 17:00:10 -07005214
5215 @Override
Junda Liue64de782015-04-16 17:19:16 -07005216 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5217 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5218 loge("phoneId " + phoneId + " is not valid.");
5219 return null;
5220 }
5221 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005222 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005223 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005224 return null ;
5225 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005226 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005227 }
5228
Amith Yamasani6e118872016-02-19 12:53:51 -08005229 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005230 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005231 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005232 List<String> privilegedPackages = new ArrayList<>();
5233 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005234 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5235 // has UICC in that slot.
5236 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005237 if (card.hasCarrierPrivilegeRules()) {
5238 if (packages == null) {
5239 // Only check packages in user 0 for now
5240 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005241 PackageManager.MATCH_DISABLED_COMPONENTS
5242 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005243 | PackageManager.GET_SIGNING_CERTIFICATES,
5244 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005245 }
5246 for (int p = packages.size() - 1; p >= 0; p--) {
5247 PackageInfo pkgInfo = packages.get(p);
5248 if (pkgInfo != null && pkgInfo.packageName != null
5249 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005250 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005251 privilegedPackages.add(pkgInfo.packageName);
5252 }
5253 }
5254 }
5255 }
5256 return privilegedPackages;
5257 }
5258
chen xuf7e9fe82019-05-09 19:31:02 -07005259 @Override
5260 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5261 List<String> privilegedPackages = new ArrayList<>();
5262 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5263 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5264 }
5265 return privilegedPackages;
5266 }
5267
Wink Savilleb564aae2014-10-23 10:18:09 -07005268 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005269 final Phone phone = getPhone(subId);
5270 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005271 if (card == null) {
5272 loge("getIccId: No UICC");
5273 return null;
5274 }
5275 String iccId = card.getIccId();
5276 if (TextUtils.isEmpty(iccId)) {
5277 loge("getIccId: ICC ID is null or empty.");
5278 return null;
5279 }
5280 return iccId;
5281 }
5282
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005283 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005284 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5285 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005286 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5287 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 final long identity = Binder.clearCallingIdentity();
5290 try {
5291 final String iccId = getIccId(subId);
5292 final Phone phone = getPhone(subId);
5293 if (phone == null) {
5294 return false;
5295 }
5296 final String subscriberId = phone.getSubscriberId();
5297
5298 if (DBG_MERGE) {
5299 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5300 + subscriberId + " to " + number);
5301 }
5302
5303 if (TextUtils.isEmpty(iccId)) {
5304 return false;
5305 }
5306
5307 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5308
5309 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5310 if (alphaTag == null) {
5311 editor.remove(alphaTagPrefKey);
5312 } else {
5313 editor.putString(alphaTagPrefKey, alphaTag);
5314 }
5315
5316 // Record both the line number and IMSI for this ICCID, since we need to
5317 // track all merged IMSIs based on line number
5318 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5319 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5320 if (number == null) {
5321 editor.remove(numberPrefKey);
5322 editor.remove(subscriberPrefKey);
5323 } else {
5324 editor.putString(numberPrefKey, number);
5325 editor.putString(subscriberPrefKey, subscriberId);
5326 }
5327
5328 editor.commit();
5329 return true;
5330 } finally {
5331 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005332 }
Derek Tan7226c842014-07-02 17:42:23 -07005333 }
5334
5335 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005336 public String getLine1NumberForDisplay(int subId, String callingPackage,
5337 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005338 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005339 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005340 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005341 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005342 return null;
5343 }
Derek Tan97ebb422014-09-05 16:55:38 -07005344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345 final long identity = Binder.clearCallingIdentity();
5346 try {
5347 String iccId = getIccId(subId);
5348 if (iccId != null) {
5349 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5350 if (DBG_MERGE) {
5351 log("getLine1NumberForDisplay returning "
5352 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5353 }
5354 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5357 return null;
5358 } finally {
5359 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005360 }
Derek Tan7226c842014-07-02 17:42:23 -07005361 }
5362
5363 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005364 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5365 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005366 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005367 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005368 return null;
5369 }
Derek Tan97ebb422014-09-05 16:55:38 -07005370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371 final long identity = Binder.clearCallingIdentity();
5372 try {
5373 String iccId = getIccId(subId);
5374 if (iccId != null) {
5375 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5376 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5377 }
5378 return null;
5379 } finally {
5380 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005381 }
Derek Tan7226c842014-07-02 17:42:23 -07005382 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005383
5384 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005385 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5386 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005387 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5388 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005390 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005391 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005392 return null;
5393 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005394
Jordan Liub49b04b2019-05-06 14:45:15 -07005395 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5396 // the process, where TelephonyManager was instantiated.
5397 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005398 final long identity = Binder.clearCallingIdentity();
5399 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005400 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401 final TelephonyManager tele = TelephonyManager.from(context);
5402 final SubscriptionManager sub = SubscriptionManager.from(context);
5403
5404 // Figure out what subscribers are currently active
5405 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406
Jordan Liub49b04b2019-05-06 14:45:15 -07005407 // Only consider subs which match the current subId
5408 // This logic can be simplified. See b/131189269 for progress.
5409 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005410 activeSubscriberIds.add(tele.getSubscriberId(subId));
5411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005412
5413 // First pass, find a number override for an active subscriber
5414 String mergeNumber = null;
5415 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5416 for (String key : prefs.keySet()) {
5417 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5418 final String subscriberId = (String) prefs.get(key);
5419 if (activeSubscriberIds.contains(subscriberId)) {
5420 final String iccId = key.substring(
5421 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5422 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5423 mergeNumber = (String) prefs.get(numberKey);
5424 if (DBG_MERGE) {
5425 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5426 + " for active subscriber " + subscriberId);
5427 }
5428 if (!TextUtils.isEmpty(mergeNumber)) {
5429 break;
5430 }
5431 }
5432 }
5433 }
5434
5435 // Shortcut when no active merged subscribers
5436 if (TextUtils.isEmpty(mergeNumber)) {
5437 return null;
5438 }
5439
5440 // Second pass, find all subscribers under that line override
5441 final ArraySet<String> result = new ArraySet<>();
5442 for (String key : prefs.keySet()) {
5443 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5444 final String number = (String) prefs.get(key);
5445 if (mergeNumber.equals(number)) {
5446 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5447 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5448 final String subscriberId = (String) prefs.get(subscriberKey);
5449 if (!TextUtils.isEmpty(subscriberId)) {
5450 result.add(subscriberId);
5451 }
5452 }
5453 }
5454 }
5455
5456 final String[] resultArray = result.toArray(new String[result.size()]);
5457 Arrays.sort(resultArray);
5458 if (DBG_MERGE) {
5459 Slog.d(LOG_TAG,
5460 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5461 }
5462 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005463 } finally {
5464 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005465 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005466 }
5467
5468 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005469 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5470 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5471
5472 final long identity = Binder.clearCallingIdentity();
5473 try {
5474 final TelephonyManager telephonyManager = mApp.getSystemService(
5475 TelephonyManager.class);
5476 String subscriberId = telephonyManager.getSubscriberId(subId);
5477 if (subscriberId == null) {
5478 if (DBG) {
5479 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5480 + subId);
5481 }
5482 return null;
5483 }
5484
5485 final SubscriptionInfo info = SubscriptionController.getInstance()
5486 .getSubscriptionInfo(subId);
5487 final ParcelUuid groupUuid = info.getGroupUuid();
5488 // If it doesn't belong to any group, return just subscriberId of itself.
5489 if (groupUuid == null) {
5490 return new String[]{subscriberId};
5491 }
5492
5493 // Get all subscriberIds from the group.
5494 final List<String> mergedSubscriberIds = new ArrayList<>();
5495 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005496 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5497 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005498 for (SubscriptionInfo subInfo : groupInfos) {
5499 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5500 if (subscriberId != null) {
5501 mergedSubscriberIds.add(subscriberId);
5502 }
5503 }
5504
5505 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5506 } finally {
5507 Binder.restoreCallingIdentity(identity);
5508
5509 }
5510 }
5511
5512 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005513 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005514 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5515 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516
5517 final long identity = Binder.clearCallingIdentity();
5518 try {
5519 final Phone phone = getPhone(subId);
5520 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5521 } finally {
5522 Binder.restoreCallingIdentity(identity);
5523 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005524 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005525
5526 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005527 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005528 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5529 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005530 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531
5532 final long identity = Binder.clearCallingIdentity();
5533 try {
5534 final Phone phone = getPhone(subId);
5535 if (phone == null) {
5536 return false;
5537 }
5538 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5539 cdmaNonRoamingList);
5540 } finally {
5541 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005542 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005543 }
5544
5545 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005546 @Deprecated
5547 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5548 enforceModifyPermission();
5549
5550 int returnValue = 0;
5551 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005552 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005553 if(result.exception == null) {
5554 if (result.result != null) {
5555 byte[] responseData = (byte[])(result.result);
5556 if(responseData.length > oemResp.length) {
5557 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5558 responseData.length + "bytes. Buffer Size is " +
5559 oemResp.length + "bytes.");
5560 }
5561 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5562 returnValue = responseData.length;
5563 }
5564 } else {
5565 CommandException ex = (CommandException) result.exception;
5566 returnValue = ex.getCommandError().ordinal();
5567 if(returnValue > 0) returnValue *= -1;
5568 }
5569 } catch (RuntimeException e) {
5570 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5571 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5572 if(returnValue > 0) returnValue *= -1;
5573 }
5574
5575 return returnValue;
5576 }
5577
5578 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005579 public void setRadioCapability(RadioAccessFamily[] rafs) {
5580 try {
5581 ProxyController.getInstance().setRadioCapability(rafs);
5582 } catch (RuntimeException e) {
5583 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5584 }
5585 }
5586
5587 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005588 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005589 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005590 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005591 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005592 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594 final long identity = Binder.clearCallingIdentity();
5595 try {
chen xub97461a2018-10-26 14:17:57 -07005596 TelephonyPermissions
5597 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5598 mApp, phone.getSubId(), "getRadioAccessFamily");
5599 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005600 } finally {
5601 Binder.restoreCallingIdentity(identity);
5602 }
chen xub97461a2018-10-26 14:17:57 -07005603 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005604 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005605
5606 @Override
5607 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005608 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005609 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610
5611 final long identity = Binder.clearCallingIdentity();
5612 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005613 ImsManager.getInstance(defaultPhone.getContext(),
5614 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 } finally {
5616 Binder.restoreCallingIdentity(identity);
5617 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005618 }
5619
5620 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005621 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005622 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5624 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005625 return false;
5626 }
Svet Ganovb320e182015-04-16 12:30:10 -07005627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628 final long identity = Binder.clearCallingIdentity();
5629 try {
5630 // Check the user preference and the system-level IMS setting. Even if the user has
5631 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5632 // In the long run, we may instead need to check if there exists a connection service
5633 // which can support video calling.
5634 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005635 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636 return imsManager.isVtEnabledByPlatform()
5637 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5638 && imsManager.isVtEnabledByUser();
5639 } finally {
5640 Binder.restoreCallingIdentity(identity);
5641 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005642 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005643
Andrew Leea1239f22015-03-02 17:44:07 -08005644 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005645 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5646 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005647 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005648 mApp, subId, callingPackage, callingFeatureId,
5649 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005650 return false;
5651 }
5652
5653 final long identity = Binder.clearCallingIdentity();
5654 try {
5655 CarrierConfigManager configManager =
5656 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005657 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
Andrew Leea1239f22015-03-02 17:44:07 -08005662 }
5663
5664 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005665 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005667 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668 return false;
5669 }
5670
5671 final long identity = Binder.clearCallingIdentity();
5672 try {
5673 CarrierConfigManager configManager =
5674 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005675 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5677 } finally {
5678 Binder.restoreCallingIdentity(identity);
5679 }
Andrew Leea1239f22015-03-02 17:44:07 -08005680 }
5681
Andrew Lee9431b832015-03-09 18:46:45 -07005682 @Override
5683 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005684 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005685 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005686 }
5687
5688 @Override
5689 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690 final long identity = Binder.clearCallingIdentity();
5691 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005692 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693 } finally {
5694 Binder.restoreCallingIdentity(identity);
5695 }
Andrew Lee9431b832015-03-09 18:46:45 -07005696 }
5697
Hall Liuf6668912018-10-31 17:05:23 -07005698 /**
5699 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5700 * support for the feature and device firmware support.
5701 *
5702 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5703 */
5704 @Override
5705 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005707 final Phone phone = getPhone(subscriptionId);
5708 if (phone == null) {
5709 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5710 return false;
5711 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005713 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5715 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005716 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 return isCarrierSupported && isDeviceSupported;
5718 } finally {
5719 Binder.restoreCallingIdentity(identity);
5720 }
Hall Liu98187582018-01-22 19:15:32 -08005721 }
5722
Hall Liuf6668912018-10-31 17:05:23 -07005723 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005724 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5725 * RTT setting, will return true if the device and carrier both support RTT.
5726 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005727 */
5728 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729 final long identity = Binder.clearCallingIdentity();
5730 try {
Hall Liuf2daa022019-07-23 18:39:00 -07005731 boolean isRttSupported = isRttSupported(subscriptionId);
5732 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005733 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liuf2daa022019-07-23 18:39:00 -07005734 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5735 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5736 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005740 }
5741
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005742 @Deprecated
5743 @Override
5744 public String getDeviceId(String callingPackage) {
5745 return getDeviceIdWithFeature(callingPackage, null);
5746 }
5747
Sanket Padawe7310cc72015-01-14 09:53:20 -08005748 /**
5749 * Returns the unique device ID of phone, for example, the IMEI for
5750 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5751 *
5752 * <p>Requires Permission:
5753 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5754 */
5755 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005756 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005757 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005758 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005759 return null;
5760 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005761 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005762 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005763 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005764 return null;
5765 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766
5767 final long identity = Binder.clearCallingIdentity();
5768 try {
5769 return phone.getDeviceId();
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005773 }
5774
Ping Sunc67b7c22016-03-02 19:16:45 +08005775 /**
5776 * {@hide}
5777 * Returns the IMS Registration Status on a particular subid
5778 *
5779 * @param subId
5780 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005781 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005782 Phone phone = getPhone(subId);
5783 if (phone != null) {
5784 return phone.isImsRegistered();
5785 } else {
5786 return false;
5787 }
5788 }
5789
Santos Cordon7a1885b2015-02-03 11:15:19 -08005790 @Override
5791 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792 final long identity = Binder.clearCallingIdentity();
5793 try {
5794 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5795 } finally {
5796 Binder.restoreCallingIdentity(identity);
5797 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005798 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005799
Tyler Gunnf70ed162019-04-03 15:28:53 -07005800 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005801 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005802 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005804 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005805 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5806 }
5807 final long identity = Binder.clearCallingIdentity();
5808 try {
5809 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5810 } finally {
5811 Binder.restoreCallingIdentity(identity);
5812 }
5813 }
5814
5815 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005816 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5817 final long identity = Binder.clearCallingIdentity();
5818 try {
5819 Phone phone = getPhone(subscriptionId);
5820 if (phone == null) {
5821 return null;
5822 }
5823 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5824 } finally {
5825 Binder.restoreCallingIdentity(identity);
5826 }
5827 }
5828
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005829 /**
5830 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005831 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005832 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833 final long identity = Binder.clearCallingIdentity();
5834 try {
5835 Phone phone = getPhone(subId);
5836 if (phone != null) {
5837 return phone.isWifiCallingEnabled();
5838 } else {
5839 return false;
5840 }
5841 } finally {
5842 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005843 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005844 }
5845
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005846 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005847 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005848 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005849 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850 final long identity = Binder.clearCallingIdentity();
5851 try {
5852 Phone phone = getPhone(subId);
5853 if (phone != null) {
5854 return phone.isVideoEnabled();
5855 } else {
5856 return false;
5857 }
5858 } finally {
5859 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005860 }
5861 }
5862
5863 /**
5864 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5865 * defined in {@link ImsRegistrationImplBase}.
5866 */
5867 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868 final long identity = Binder.clearCallingIdentity();
5869 try {
5870 Phone phone = getPhone(subId);
5871 if (phone != null) {
5872 return phone.getImsRegistrationTech();
5873 } else {
5874 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5875 }
5876 } finally {
5877 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005878 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005879 }
5880
Stuart Scott8eef64f2015-04-08 15:13:54 -07005881 @Override
5882 public void factoryReset(int subId) {
5883 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005884 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5885 return;
5886 }
5887
Svet Ganovcc087f82015-05-12 20:35:54 -07005888 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005889
Svet Ganovcc087f82015-05-12 20:35:54 -07005890 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005891 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5892 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005893 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005894 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005895 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005896 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5897 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005898 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005899 // There has been issues when Sms raw table somehow stores orphan
5900 // fragments. They lead to garbled message when new fragments come
5901 // in and combined with those stale ones. In case this happens again,
5902 // user can reset all network settings which will clean up this table.
5903 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005904 // Clean up IMS settings as well here.
5905 int slotId = getSlotIndex(subId);
5906 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5907 ImsManager.getInstance(mApp, slotId).factoryReset();
5908 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005909 } finally {
5910 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005911 }
5912 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005913
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005914 private void cleanUpSmsRawTable(Context context) {
5915 ContentResolver resolver = context.getContentResolver();
5916 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5917 resolver.delete(uri, null, null);
5918 }
5919
Narayan Kamath1c496c22015-04-16 14:40:19 +01005920 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005921 public String getSimLocaleForSubscriber(int subId) {
5922 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5923 final Phone phone = getPhone(subId);
5924 if (phone == null) {
5925 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005926 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005927 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928 final long identity = Binder.clearCallingIdentity();
5929 try {
chen xu5d3637b2019-01-21 23:31:38 -08005930 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005931 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08005932 if (info == null) {
5933 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5934 return null;
5935 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936 // Try and fetch the locale from the carrier properties or from the SIM language
5937 // preferences (EF-PL and EF-LI)...
5938 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005940 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5941 if (localeFromDefaultSim != null) {
5942 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5943 if (DBG) log("Using locale from subId: " + subId + " locale: "
5944 + localeFromDefaultSim);
5945 return localeFromDefaultSim.toLanguageTag();
5946 } else {
5947 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 }
5949 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 // The SIM language preferences only store a language (e.g. fr = French), not an
5952 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5953 // the SIM and carrier preferences does not include a country we add the country
5954 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005955 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005957 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 return mccLocale.toLanguageTag();
5959 }
5960
5961 if (DBG) log("No locale found - returning null");
5962 return null;
5963 } finally {
5964 Binder.restoreCallingIdentity(identity);
5965 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005966 }
5967
5968 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005969 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
5970 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005971 }
5972
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005973 /**
5974 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5975 */
5976 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005977 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
5978 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005979 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005980
Chenjie Yu1ba97252018-01-11 18:16:20 -08005981 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07005982 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005983
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005984 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005985 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5986 * representing the state of the modem.
5987 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005988 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5989 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005990 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005991 */
5992 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005993 public void requestModemActivityInfo(ResultReceiver result) {
5994 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005995 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996
5997 final long identity = Binder.clearCallingIdentity();
5998 try {
5999 ModemActivityInfo ret = null;
6000 synchronized (mLastModemActivityInfo) {
6001 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6002 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006003 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006004 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006006 int[] txTimeMs = info.getTransmitTimeMillis();
6007 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006009 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010 }
6011 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006012 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6013 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 mLastModemActivityInfo.setIdleTimeMillis(
6015 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006016 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6017 mLastModemActivityInfo.setReceiveTimeMillis(
6018 info.getReceiveTimeMillis() + mLastModemActivityInfo
6019 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006020 }
Chen Xud78231e2019-09-10 18:49:52 -07006021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6023 mLastModemActivityInfo.getSleepTimeMillis(),
6024 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006025 mLastModemActivityInfo.getTransmitTimeMillis(),
6026 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006027 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028 Bundle bundle = new Bundle();
6029 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6030 result.send(0, bundle);
6031 } finally {
6032 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006033 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006034 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006035
Siddharth Rayb8114062018-06-17 15:02:38 -07006036 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6037 // less than total activity duration.
6038 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6039 if (info == null) {
6040 return false;
6041 }
6042 int activityDurationMs =
6043 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6044 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006045 int[] txTimeMs = info.getTransmitTimeMillis();
6046 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6047 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006048 }
6049 return (info.isValid()
6050 && (info.getSleepTimeMillis() <= activityDurationMs)
6051 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006052 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006053 && (totalTxTimeMs <= activityDurationMs));
6054 }
6055
Jack Yu85bd38a2015-11-09 11:34:32 -08006056 /**
6057 * {@hide}
6058 * Returns the service state information on specified subscription.
6059 */
6060 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006061 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6062 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006063 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006064 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006065 return null;
6066 }
6067
Hall Liuf19c44f2018-11-27 14:38:17 -08006068 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6069 LocationAccessPolicy.checkLocationPermission(mApp,
6070 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6071 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006072 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006073 .setCallingPid(Binder.getCallingPid())
6074 .setCallingUid(Binder.getCallingUid())
6075 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006076 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006077 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6078 .build());
6079
6080 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6081 LocationAccessPolicy.checkLocationPermission(mApp,
6082 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6083 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006084 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006085 .setCallingPid(Binder.getCallingPid())
6086 .setCallingUid(Binder.getCallingUid())
6087 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006088 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006089 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6090 .build());
6091 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6092 boolean hasFinePermission =
6093 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6094 boolean hasCoarsePermission =
6095 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097 final long identity = Binder.clearCallingIdentity();
6098 try {
6099 final Phone phone = getPhone(subId);
6100 if (phone == null) {
6101 return null;
6102 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006103
Hall Liuf19c44f2018-11-27 14:38:17 -08006104 ServiceState ss = phone.getServiceState();
6105
6106 // Scrub out the location info in ServiceState depending on what level of access
6107 // the caller has.
6108 if (hasFinePermission) return ss;
6109 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6110 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111 } finally {
6112 Binder.restoreCallingIdentity(identity);
6113 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006114 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006115
6116 /**
6117 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6118 *
6119 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6120 * voicemail ringtone.
6121 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6122 * PhoneAccount.
6123 */
6124 @Override
6125 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006126 final long identity = Binder.clearCallingIdentity();
6127 try {
6128 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6129 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006130 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6134 } finally {
6135 Binder.restoreCallingIdentity(identity);
6136 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006137 }
6138
6139 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006140 * Sets the per-account voicemail ringtone.
6141 *
6142 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6143 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6144 *
6145 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6146 * voicemail ringtone.
6147 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6148 * PhoneAccount.
6149 */
6150 @Override
6151 public void setVoicemailRingtoneUri(String callingPackage,
6152 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006153 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006154 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006155 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6156 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6158 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6159 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006160 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006161
6162 final long identity = Binder.clearCallingIdentity();
6163 try {
6164 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6165 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006166 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006167 }
6168 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6169 } finally {
6170 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006171 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006172 }
6173
6174 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006175 * Returns whether vibration is set for voicemail notification in Phone settings.
6176 *
6177 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6178 * voicemail vibration setting.
6179 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6180 */
6181 @Override
6182 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006183 final long identity = Binder.clearCallingIdentity();
6184 try {
6185 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6186 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006187 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6191 } finally {
6192 Binder.restoreCallingIdentity(identity);
6193 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006194 }
6195
Youhan Wange64578a2016-05-02 15:32:42 -07006196 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006197 * Sets the per-account voicemail vibration.
6198 *
6199 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6200 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6201 *
6202 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6203 * voicemail vibration setting.
6204 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6205 * specific PhoneAccount.
6206 */
6207 @Override
6208 public void setVoicemailVibrationEnabled(String callingPackage,
6209 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006210 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006211 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006212 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6213 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6215 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6216 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006217 }
6218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219 final long identity = Binder.clearCallingIdentity();
6220 try {
6221 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6222 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006223 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 }
6225 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6226 } finally {
6227 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006228 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006229 }
6230
6231 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006232 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6233 *
6234 * @throws SecurityException if the caller does not have the required permission
6235 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006236 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006237 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006238 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006239 }
6240
6241 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006242 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6243 * permission.
6244 *
6245 * @throws SecurityException if the caller does not have the required permission
6246 */
6247 private void enforceSendSmsPermission() {
6248 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6249 }
6250
6251 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006252 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006253 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006254 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006255 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006256 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257 final long identity = Binder.clearCallingIdentity();
6258 try {
6259 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006260 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006261 if (componentName == null) {
6262 throw new SecurityException(
6263 "Caller not current active visual voicemail package[null]");
6264 }
6265 String vvmPackage = componentName.getPackageName();
6266 if (!callingPackage.equals(vvmPackage)) {
6267 throw new SecurityException("Caller not current active visual voicemail package["
6268 + vvmPackage + "]");
6269 }
6270 } finally {
6271 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006272 }
6273 }
6274
6275 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006276 * Return the application ID for the app type.
6277 *
6278 * @param subId the subscription ID that this request applies to.
6279 * @param appType the uicc app type.
6280 * @return Application ID for specificied app type, or null if no uicc.
6281 */
6282 @Override
6283 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006284 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006285 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286
6287 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006288 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 if (phone == null) {
6290 return null;
6291 }
6292 String aid = null;
6293 try {
6294 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6295 .getApplicationByType(appType).getAid();
6296 } catch (Exception e) {
6297 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6298 }
6299 return aid;
6300 } finally {
6301 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006302 }
Youhan Wange64578a2016-05-02 15:32:42 -07006303 }
6304
Youhan Wang4001d252016-05-11 10:29:41 -07006305 /**
6306 * Return the Electronic Serial Number.
6307 *
6308 * @param subId the subscription ID that this request applies to.
6309 * @return ESN or null if error.
6310 */
6311 @Override
6312 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006313 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006314 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315
6316 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006317 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006318 if (phone == null) {
6319 return null;
6320 }
6321 String esn = null;
6322 try {
6323 esn = phone.getEsn();
6324 } catch (Exception e) {
6325 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6326 }
6327 return esn;
6328 } finally {
6329 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006330 }
Youhan Wang4001d252016-05-11 10:29:41 -07006331 }
6332
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006333 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006334 * Return the Preferred Roaming List Version.
6335 *
6336 * @param subId the subscription ID that this request applies to.
6337 * @return PRLVersion or null if error.
6338 */
6339 @Override
6340 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006341 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006342 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343
6344 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006345 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 if (phone == null) {
6347 return null;
6348 }
6349 String cdmaPrlVersion = null;
6350 try {
6351 cdmaPrlVersion = phone.getCdmaPrlVersion();
6352 } catch (Exception e) {
6353 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6354 }
6355 return cdmaPrlVersion;
6356 } finally {
6357 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006358 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006359 }
6360
6361 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006362 * Get snapshot of Telephony histograms
6363 * @return List of Telephony histograms
6364 * @hide
6365 */
6366 @Override
6367 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6369 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006370
6371 final long identity = Binder.clearCallingIdentity();
6372 try {
6373 return RIL.getTelephonyRILTimingHistograms();
6374 } finally {
6375 Binder.restoreCallingIdentity(identity);
6376 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006377 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006378
6379 /**
6380 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006381 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6382 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006383 * Require system privileges. In the future we may add this to carrier APIs.
6384 *
Michele Berionne482f8202018-11-27 18:57:59 -08006385 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006386 */
6387 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006388 @TelephonyManager.SetCarrierRestrictionResult
6389 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006390 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006391 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006392
Michele Berionne482f8202018-11-27 18:57:59 -08006393 if (carrierRestrictionRules == null) {
6394 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006395 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397 final long identity = Binder.clearCallingIdentity();
6398 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006399 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006400 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 } finally {
6402 Binder.restoreCallingIdentity(identity);
6403 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006404 }
6405
6406 /**
6407 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006408 * Get the allowed carrier list and the excluded carrier list, including the priority between
6409 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006410 * Require system privileges. In the future we may add this to carrier APIs.
6411 *
Michele Berionne482f8202018-11-27 18:57:59 -08006412 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006413 */
6414 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006415 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006416 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006417 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006418
6419 final long identity = Binder.clearCallingIdentity();
6420 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006421 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6422 if (response instanceof CarrierRestrictionRules) {
6423 return (CarrierRestrictionRules) response;
6424 }
6425 // Response is an Exception of some kind,
6426 // which is signalled to the user as a NULL retval
6427 return null;
6428 } catch (Exception e) {
6429 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6430 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006431 } finally {
6432 Binder.restoreCallingIdentity(identity);
6433 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006434 }
6435
fionaxu59545b42016-05-25 15:53:37 -07006436 /**
6437 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6438 * @param subId the subscription ID that this action applies to.
6439 * @param enabled control enable or disable metered apns.
6440 * {@hide}
6441 */
6442 @Override
6443 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6444 enforceModifyPermission();
6445 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006446
6447 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006448 if (phone == null) {
6449 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6450 return;
6451 }
6452 try {
6453 phone.carrierActionSetMeteredApnsEnabled(enabled);
6454 } catch (Exception e) {
6455 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006456 } finally {
6457 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006458 }
6459 }
6460
6461 /**
6462 * Action set from carrier signalling broadcast receivers to enable/disable radio
6463 * @param subId the subscription ID that this action applies to.
6464 * @param enabled control enable or disable radio.
6465 * {@hide}
6466 */
6467 @Override
6468 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6469 enforceModifyPermission();
6470 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006471
6472 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006473 if (phone == null) {
6474 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6475 return;
6476 }
6477 try {
6478 phone.carrierActionSetRadioEnabled(enabled);
6479 } catch (Exception e) {
6480 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481 } finally {
6482 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006483 }
6484 }
6485
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006486 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006487 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6488 * network status based on which carrier apps could apply actions accordingly,
6489 * enable/disable default url handler for example.
6490 *
6491 * @param subId the subscription ID that this action applies to.
6492 * @param report control start/stop reporting the default network status.
6493 * {@hide}
6494 */
6495 @Override
6496 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6497 enforceModifyPermission();
6498 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006499
6500 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006501 if (phone == null) {
6502 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6503 return;
6504 }
6505 try {
6506 phone.carrierActionReportDefaultNetworkStatus(report);
6507 } catch (Exception e) {
6508 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006509 } finally {
6510 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006511 }
6512 }
6513
6514 /**
fionaxud9622282017-07-17 17:51:30 -07006515 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6516 * @param subId the subscription ID that this action applies to.
6517 * {@hide}
6518 */
6519 @Override
6520 public void carrierActionResetAll(int subId) {
6521 enforceModifyPermission();
6522 final Phone phone = getPhone(subId);
6523 if (phone == null) {
6524 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6525 return;
6526 }
6527 try {
6528 phone.carrierActionResetAll();
6529 } catch (Exception e) {
6530 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6531 }
6532 }
6533
6534 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006535 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6536 * bug report is being generated.
6537 */
6538 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006539 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006540 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6541 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006542 writer.println("Permission Denial: can't dump Phone from pid="
6543 + Binder.getCallingPid()
6544 + ", uid=" + Binder.getCallingUid()
6545 + "without permission "
6546 + android.Manifest.permission.DUMP);
6547 return;
6548 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006549 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006550 }
Jack Yueb89b242016-06-22 13:27:47 -07006551
Brad Ebingerdac2f002018-04-03 15:17:52 -07006552 @Override
6553 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6554 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6555 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006556 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6557 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006558 }
6559
Jack Yueb89b242016-06-22 13:27:47 -07006560 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006561 * Get aggregated video call data usage since boot.
6562 *
6563 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6564 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006565 * {@hide}
6566 */
6567 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006568 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006569 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6570 null);
6571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 final long identity = Binder.clearCallingIdentity();
6573 try {
6574 // NetworkStatsService keeps tracking the active network interface and identity. It
6575 // records the delta with the corresponding network identity.
6576 // We just return the total video call data usage snapshot since boot.
6577 Phone phone = getPhone(subId);
6578 if (phone != null) {
6579 return phone.getVtDataUsage(perUidStats);
6580 }
6581 return null;
6582 } finally {
6583 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006584 }
Jack Yueb89b242016-06-22 13:27:47 -07006585 }
Jack Yu75ab2952016-07-08 14:29:33 -07006586
6587 /**
6588 * Policy control of data connection. Usually used when data limit is passed.
6589 * @param enabled True if enabling the data, otherwise disabling.
6590 * @param subId Subscription index
6591 * {@hide}
6592 */
6593 @Override
6594 public void setPolicyDataEnabled(boolean enabled, int subId) {
6595 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006596
6597 final long identity = Binder.clearCallingIdentity();
6598 try {
6599 Phone phone = getPhone(subId);
6600 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006601 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 }
6603 } finally {
6604 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006605 }
6606 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006607
6608 /**
6609 * Get Client request stats
6610 * @return List of Client Request Stats
6611 * @hide
6612 */
6613 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006614 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6615 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006617 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006618 return null;
6619 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006620 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622 final long identity = Binder.clearCallingIdentity();
6623 try {
6624 if (phone != null) {
6625 return phone.getClientRequestStats();
6626 }
6627
6628 return null;
6629 } finally {
6630 Binder.restoreCallingIdentity(identity);
6631 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006632 }
6633
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006634 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006635 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006636 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006637 }
Jack Yueb4124c2017-02-16 15:32:43 -08006638
6639 /**
Grace Chen70990072017-03-24 17:21:30 -07006640 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006641 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006642 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006643 * @param state State of SIM (power down, power up, pass through)
6644 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6645 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6646 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006647 *
6648 **/
6649 @Override
Grace Chen70990072017-03-24 17:21:30 -07006650 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006651 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006652 Phone phone = PhoneFactory.getPhone(slotIndex);
6653
vagdeviaf9a5b92018-08-15 16:01:53 -07006654 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656 final long identity = Binder.clearCallingIdentity();
6657 try {
6658 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006659 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006660 }
6661 } finally {
6662 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006663 }
6664 }
Shuo Qiandd210312017-04-12 22:11:33 +00006665
Tyler Gunn65d45c22017-06-05 11:22:26 -07006666 private boolean isUssdApiAllowed(int subId) {
6667 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006668 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006669 if (configManager == null) {
6670 return false;
6671 }
6672 PersistableBundle pb = configManager.getConfigForSubId(subId);
6673 if (pb == null) {
6674 return false;
6675 }
6676 return pb.getBoolean(
6677 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6678 }
6679
Shuo Qiandd210312017-04-12 22:11:33 +00006680 /**
6681 * Check if phone is in emergency callback mode
6682 * @return true if phone is in emergency callback mode
6683 * @param subId sub id
6684 */
goneil9c5f4872017-12-05 14:07:56 -08006685 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006686 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006687 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006688 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006689
6690 final long identity = Binder.clearCallingIdentity();
6691 try {
6692 if (phone != null) {
6693 return phone.isInEcm();
6694 } else {
6695 return false;
6696 }
6697 } finally {
6698 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006699 }
6700 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006701
6702 /**
6703 * Get the current signal strength information for the given subscription.
6704 * Because this information is not updated when the device is in a low power state
6705 * it should not be relied-upon to be current.
6706 * @param subId Subscription index
6707 * @return the most recent cached signal strength info from the modem
6708 */
6709 @Override
6710 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711 final long identity = Binder.clearCallingIdentity();
6712 try {
6713 Phone p = getPhone(subId);
6714 if (p == null) {
6715 return null;
6716 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718 return p.getSignalStrength();
6719 } finally {
6720 Binder.restoreCallingIdentity(identity);
6721 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006722 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006723
Pengquan Meng77b7f132018-08-22 14:49:57 -07006724 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006725 * Get the current modem radio state for the given slot.
6726 * @param slotIndex slot index.
6727 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006728 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006729 * @return the current radio power state from the modem
6730 */
6731 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006732 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006733 Phone phone = PhoneFactory.getPhone(slotIndex);
6734 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6736 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006737 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6738 }
6739
6740 final long identity = Binder.clearCallingIdentity();
6741 try {
6742 return phone.getRadioPowerState();
6743 } finally {
6744 Binder.restoreCallingIdentity(identity);
6745 }
6746 }
6747 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6748 }
6749
6750 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006751 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6752 *
6753 * <p>Requires one of the following permissions:
6754 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6755 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6756 * privileges.
6757 *
6758 * @param subId subscription id
6759 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6760 * {@code false}.
6761 */
6762 @Override
6763 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006764 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6765 null /* message */);
6766
Pengquan Menga1bb6272018-09-06 09:59:22 -07006767 boolean isEnabled = false;
6768 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006769 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006770 Phone phone = getPhone(subId);
6771 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006772 } catch (Exception e) {
6773 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6774 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006775 } finally {
6776 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006777 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006778 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006779 }
6780
6781
6782 /**
6783 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6784 *
6785 * <p> Requires permission:
6786 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6787 * privileges.
6788 *
6789 * @param subId subscription id
6790 * @param isEnabled {@code true} means enable, {@code false} means disable.
6791 */
6792 @Override
6793 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6795 mApp, subId, "setDataRoamingEnabled");
6796
Pengquan Menga1bb6272018-09-06 09:59:22 -07006797 final long identity = Binder.clearCallingIdentity();
6798 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006799 Phone phone = getPhone(subId);
6800 if (phone != null) {
6801 phone.setDataRoamingEnabled(isEnabled);
6802 }
6803 } finally {
6804 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006805 }
6806 }
6807
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006808 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006809 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006810 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6811 mApp, subId, "isManualNetworkSelectionAllowed");
6812
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006813 boolean isAllowed = true;
6814 final long identity = Binder.clearCallingIdentity();
6815 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006816 Phone phone = getPhone(subId);
6817 if (phone != null) {
6818 isAllowed = phone.isCspPlmnEnabled();
6819 }
6820 } finally {
6821 Binder.restoreCallingIdentity(identity);
6822 }
6823 return isAllowed;
6824 }
6825
6826 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006827 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006828 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006829 try {
6830 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006831 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006832 } catch (SecurityException e) {
6833 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6834 // has carrier privileges on an active UICC
6835 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6836 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006837 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006838 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006839 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006840
6841 final long identity = Binder.clearCallingIdentity();
6842 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006843 UiccController uiccController = UiccController.getInstance();
6844 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006845 if (hasReadPermission) {
6846 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006847 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006848
6849 // Remove private info if the caller doesn't have access
6850 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6851 for (UiccCardInfo cardInfo : cardInfos) {
6852 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6853 // is available
6854 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6855 if (card == null || card.getUiccProfile() == null) {
6856 // assume no access if the card or profile is unavailable
6857 filteredInfos.add(cardInfo.getUnprivileged());
6858 continue;
6859 }
6860 UiccProfile profile = card.getUiccProfile();
6861 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6862 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6863 filteredInfos.add(cardInfo);
6864 } else {
6865 filteredInfos.add(cardInfo.getUnprivileged());
6866 }
6867 }
6868 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006869 } finally {
6870 Binder.restoreCallingIdentity(identity);
6871 }
6872 }
6873
6874 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006875 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006876 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006877
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006878 final long identity = Binder.clearCallingIdentity();
6879 try {
6880 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6881 if (slots == null) {
6882 Rlog.i(LOG_TAG, "slots is null.");
6883 return null;
6884 }
6885
6886 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6887 for (int i = 0; i < slots.length; i++) {
6888 UiccSlot slot = slots[i];
6889 if (slot == null) {
6890 continue;
6891 }
6892
Jordan Liu7be7e652019-05-06 18:55:02 +00006893 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006894 UiccCard card = slot.getUiccCard();
6895 if (card != null) {
6896 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006897 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006898 cardId = slot.getEid();
6899 if (TextUtils.isEmpty(cardId)) {
6900 cardId = slot.getIccId();
6901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006902 }
6903
Jordan Liu857451f2019-05-09 16:35:35 -07006904 if (cardId != null) {
6905 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6906 // if cardId is an EID, it's all digits so this is fine
6907 cardId = IccUtils.stripTrailingFs(cardId);
6908 }
6909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006910 int cardState = 0;
6911 switch (slot.getCardState()) {
6912 case CARDSTATE_ABSENT:
6913 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6914 break;
6915 case CARDSTATE_PRESENT:
6916 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6917 break;
6918 case CARDSTATE_ERROR:
6919 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6920 break;
6921 case CARDSTATE_RESTRICTED:
6922 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6923 break;
6924 default:
6925 break;
6926
6927 }
6928
6929 infos[i] = new UiccSlotInfo(
6930 slot.isActive(),
6931 slot.isEuicc(),
6932 cardId,
6933 cardState,
6934 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006935 slot.isExtendedApduSupported(),
6936 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006937 }
6938 return infos;
6939 } finally {
6940 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006941 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006942 }
6943
6944 @Override
6945 public boolean switchSlots(int[] physicalSlots) {
6946 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947
6948 final long identity = Binder.clearCallingIdentity();
6949 try {
6950 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6951 } finally {
6952 Binder.restoreCallingIdentity(identity);
6953 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006954 }
Jack Yu4c988042018-02-27 15:30:01 -08006955
6956 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006957 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006958 final long identity = Binder.clearCallingIdentity();
6959 try {
6960 return UiccController.getInstance().getCardIdForDefaultEuicc();
6961 } finally {
6962 Binder.restoreCallingIdentity(identity);
6963 }
6964 }
6965
6966 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006967 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6968 enforceModifyPermission();
6969 final Phone phone = getPhone(subId);
6970 if (phone == null) {
6971 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6972 return;
6973 }
6974
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006975 final long identity = Binder.clearCallingIdentity();
6976 try {
6977 phone.setRadioIndicationUpdateMode(filters, mode);
6978 } finally {
6979 Binder.restoreCallingIdentity(identity);
6980 }
Jack Yu4c988042018-02-27 15:30:01 -08006981 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006982
6983 /**
goneil47ffb6e2018-04-06 15:40:58 -07006984 * A test API to reload the UICC profile.
6985 *
6986 * <p>Requires that the calling app has permission
6987 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6988 * @hide
6989 */
6990 @Override
6991 public void refreshUiccProfile(int subId) {
6992 enforceModifyPermission();
6993
6994 final long identity = Binder.clearCallingIdentity();
6995 try {
6996 Phone phone = getPhone(subId);
6997 if (phone == null) {
6998 return;
6999 }
7000 UiccCard uiccCard = phone.getUiccCard();
7001 if (uiccCard == null) {
7002 return;
7003 }
7004 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7005 if (uiccProfile == null) {
7006 return;
7007 }
7008 uiccProfile.refresh();
7009 } finally {
7010 Binder.restoreCallingIdentity(identity);
7011 }
7012 }
7013
7014 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007015 * Returns false if the mobile data is disabled by default, otherwise return true.
7016 */
7017 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007018 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007019 }
7020
7021 /**
7022 * Returns true if the data roaming is enabled by default, i.e the system property
7023 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7024 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7025 */
7026 private boolean getDefaultDataRoamingEnabled(int subId) {
7027 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007028 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007029 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007030 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7031 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7032 return isDataRoamingEnabled;
7033 }
7034
7035 /**
7036 * Returns the default network type for the given {@code subId}, if the default network type is
7037 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7038 */
7039 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007040 List<Integer> list = TelephonyProperties.default_network();
7041 int phoneId = mSubscriptionController.getPhoneId(subId);
7042 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7043 return list.get(phoneId);
7044 }
7045 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007046 }
fionaxua13278b2018-03-21 00:08:13 -07007047
7048 @Override
7049 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007050 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007051 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052
7053 final long identity = Binder.clearCallingIdentity();
7054 try {
7055 final Phone phone = getPhone(subId);
7056 if (phone == null) {
7057 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7058 return;
7059 }
chen xueaba88a2019-03-15 13:15:10 -07007060 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7061 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 } finally {
7063 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007064 }
fionaxua13278b2018-03-21 00:08:13 -07007065 }
7066
7067 @Override
7068 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007069 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070
7071 final long identity = Binder.clearCallingIdentity();
7072 try {
7073 final Phone phone = getPhone(subId);
7074 if (phone == null) {
7075 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7076 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7077 }
7078 return phone.getCarrierIdListVersion();
7079 } finally {
7080 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007081 }
fionaxua13278b2018-03-21 00:08:13 -07007082 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007083
7084 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007085 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7086 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007087 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007088 mApp, subId, callingPackage, callingFeatureId,
7089 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007090 return -1;
7091 }
7092
7093 final long identity = Binder.clearCallingIdentity();
7094 try {
7095 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7096 } finally {
7097 Binder.restoreCallingIdentity(identity);
7098 }
7099 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007100
7101 @Override
7102 public int getCdmaRoamingMode(int subId) {
7103 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7104 mApp, subId, "getCdmaRoamingMode");
7105
7106 final long identity = Binder.clearCallingIdentity();
7107 try {
7108 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7109 } finally {
7110 Binder.restoreCallingIdentity(identity);
7111 }
7112 }
7113
7114 @Override
7115 public boolean setCdmaRoamingMode(int subId, int mode) {
7116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7117 mApp, subId, "setCdmaRoamingMode");
7118
7119 final long identity = Binder.clearCallingIdentity();
7120 try {
7121 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7122 } finally {
7123 Binder.restoreCallingIdentity(identity);
7124 }
7125 }
7126
7127 @Override
7128 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7130 mApp, subId, "setCdmaSubscriptionMode");
7131
7132 final long identity = Binder.clearCallingIdentity();
7133 try {
7134 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7135 } finally {
7136 Binder.restoreCallingIdentity(identity);
7137 }
7138 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007139
sqianc5eccab2018-10-19 18:46:41 -07007140 @Override
sqian8c685422019-02-22 15:55:18 -08007141 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007142 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007144 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7145 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007146 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7147 }
7148 final long identity = Binder.clearCallingIdentity();
7149 try {
sqian854d44b2018-12-12 16:48:18 -08007150 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7151 for (Phone phone: PhoneFactory.getPhones()) {
7152 if (phone.getEmergencyNumberTracker() != null
7153 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7154 emergencyNumberListInternal.put(
7155 phone.getSubId(),
7156 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7157 }
sqian11b7a0e2018-12-05 18:48:28 -08007158 }
sqian854d44b2018-12-12 16:48:18 -08007159 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007160 } finally {
7161 Binder.restoreCallingIdentity(identity);
7162 }
sqianc5eccab2018-10-19 18:46:41 -07007163 }
7164
7165 @Override
sqian8c685422019-02-22 15:55:18 -08007166 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007167 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007168 if (!exactMatch) {
7169 TelephonyPermissions
7170 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007171 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007172 }
7173 final long identity = Binder.clearCallingIdentity();
7174 try {
sqian854d44b2018-12-12 16:48:18 -08007175 for (Phone phone: PhoneFactory.getPhones()) {
7176 if (phone.getEmergencyNumberTracker() != null
7177 && phone.getEmergencyNumberTracker() != null) {
7178 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7179 number, exactMatch)) {
7180 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007181 }
7182 }
sqian11b7a0e2018-12-05 18:48:28 -08007183 }
7184 return false;
7185 } finally {
7186 Binder.restoreCallingIdentity(identity);
7187 }
7188 }
7189
sqianf4ca7ed2019-01-15 18:32:07 -08007190 /**
7191 * Update emergency number list for test mode.
7192 */
7193 @Override
7194 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7195 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7196 "updateEmergencyNumberListTestMode");
7197
7198 final long identity = Binder.clearCallingIdentity();
7199 try {
7200 for (Phone phone: PhoneFactory.getPhones()) {
7201 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7202 if (tracker != null) {
7203 tracker.executeEmergencyNumberTestModeCommand(action, num);
7204 }
7205 }
7206 } finally {
7207 Binder.restoreCallingIdentity(identity);
7208 }
7209 }
7210
7211 /**
7212 * Get the full emergency number list for test mode.
7213 */
7214 @Override
7215 public List<String> getEmergencyNumberListTestMode() {
7216 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7217 "getEmergencyNumberListTestMode");
7218
7219 final long identity = Binder.clearCallingIdentity();
7220 try {
7221 Set<String> emergencyNumbers = new HashSet<>();
7222 for (Phone phone: PhoneFactory.getPhones()) {
7223 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7224 if (tracker != null) {
7225 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7226 emergencyNumbers.add(num.getNumber());
7227 }
7228 }
7229 }
7230 return new ArrayList<>(emergencyNumbers);
7231 } finally {
7232 Binder.restoreCallingIdentity(identity);
7233 }
7234 }
7235
chen xud6b45bd2018-10-30 22:27:10 -07007236 @Override
7237 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7238 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7239 Phone phone = getPhone(subId);
7240 if (phone == null) {
7241 return null;
7242 }
7243 final long identity = Binder.clearCallingIdentity();
7244 try {
7245 UiccProfile profile = UiccController.getInstance()
7246 .getUiccProfileForPhone(phone.getPhoneId());
7247 if (profile != null) {
7248 return profile.getCertsFromCarrierPrivilegeAccessRules();
7249 }
7250 } finally {
7251 Binder.restoreCallingIdentity(identity);
7252 }
7253 return null;
7254 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007255
7256 /**
7257 * Enable or disable a modem stack.
7258 */
7259 @Override
7260 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7261 enforceModifyPermission();
7262
7263 final long identity = Binder.clearCallingIdentity();
7264 try {
7265 Phone phone = PhoneFactory.getPhone(slotIndex);
7266 if (phone == null) {
7267 return false;
7268 } else {
7269 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7270 }
7271 } finally {
7272 Binder.restoreCallingIdentity(identity);
7273 }
7274 }
Michelecea4cf22018-12-21 15:00:11 -08007275
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007276 /**
7277 * Whether a modem stack is enabled or not.
7278 */
7279 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007280 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7281 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007282 Phone phone = PhoneFactory.getPhone(slotIndex);
7283 if (phone == null) return false;
7284
7285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007286 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7287 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007288 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7289 }
7290
7291 final long identity = Binder.clearCallingIdentity();
7292 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007293 try {
7294 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7295 } catch (NoSuchElementException ex) {
7296 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7297 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007298 } finally {
7299 Binder.restoreCallingIdentity(identity);
7300 }
7301 }
7302
Michelecea4cf22018-12-21 15:00:11 -08007303 @Override
Michele0ea7d782019-03-19 14:58:42 -07007304 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007305 enforceModifyPermission();
7306
7307 final long identity = Binder.clearCallingIdentity();
7308 try {
7309 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007310 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007311 .commit();
7312 } finally {
7313 Binder.restoreCallingIdentity(identity);
7314 }
7315 }
7316
7317 @Override
Michele0ea7d782019-03-19 14:58:42 -07007318 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007319 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007321 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7322 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007323 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007324 }
Michelecea4cf22018-12-21 15:00:11 -08007325
7326 final long identity = Binder.clearCallingIdentity();
7327 try {
Michele0ea7d782019-03-19 14:58:42 -07007328 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007329 } finally {
7330 Binder.restoreCallingIdentity(identity);
7331 }
7332 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007333
Michele0ea7d782019-03-19 14:58:42 -07007334 @TelephonyManager.IsMultiSimSupportedResult
7335 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007336 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7337 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7338 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007339 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7340 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007341 }
7342 // Check if the hardware supports multisim functionality. If usage of multisim is not
7343 // supported by the modem, indicate that it is restricted.
7344 PhoneCapability staticCapability =
7345 mPhoneConfigurationManager.getStaticPhoneCapability();
7346 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007347 loge("isMultiSimSupportedInternal: no static configuration available");
7348 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007349 }
7350 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007351 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7352 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007353 }
7354 // Check if support of multiple SIMs is restricted by carrier
7355 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007356 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007357 }
7358
Michele0ea7d782019-03-19 14:58:42 -07007359 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007360 }
7361
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007362 /**
7363 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007364 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7365 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7366 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007367 * @param numOfSims number of active sims we want to switch to
7368 */
7369 @Override
7370 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007371 if (numOfSims == 1) {
7372 enforceModifyPermission();
7373 } else {
7374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7375 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7376 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007377 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007378
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007379 try {
Michele30b57b22019-03-01 12:01:14 -08007380 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007381 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007382 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7383 return;
7384 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007385 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7386 } finally {
7387 Binder.restoreCallingIdentity(identity);
7388 }
7389 }
7390
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007391 @Override
7392 public boolean isApplicationOnUicc(int subId, int appType) {
7393 enforceReadPrivilegedPermission("isApplicationOnUicc");
7394 Phone phone = getPhone(subId);
7395 if (phone == null) {
7396 return false;
7397 }
7398 final long identity = Binder.clearCallingIdentity();
7399 try {
7400 UiccCard uiccCard = phone.getUiccCard();
7401 if (uiccCard == null) {
7402 return false;
7403 }
7404 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7405 if (uiccProfile == null) {
7406 return false;
7407 }
7408 if (TelephonyManager.APPTYPE_SIM <= appType
7409 && appType <= TelephonyManager.APPTYPE_ISIM) {
7410 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7411 }
7412 return false;
7413 } finally {
7414 Binder.restoreCallingIdentity(identity);
7415 }
7416 }
7417
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007418 /**
chen xub4baa772019-04-03 10:23:41 -07007419 * Get whether making changes to modem configurations will trigger reboot.
7420 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007421 */
7422 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007423 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7424 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007425 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007426 mApp, subId, callingPackage, callingFeatureId,
7427 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007428 return false;
7429 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007430 final long identity = Binder.clearCallingIdentity();
7431 try {
7432 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7433 } finally {
7434 Binder.restoreCallingIdentity(identity);
7435 }
7436 }
7437
Nathan Harold29f5f052019-02-15 13:41:57 -08007438 private void updateModemStateMetrics() {
7439 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7440 // TODO: check the state for each modem if the api is ready.
7441 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7442 }
7443
Pengquan Meng3889a572019-01-23 11:16:29 -08007444 @Override
7445 public int[] getSlotsMapping() {
7446 enforceReadPrivilegedPermission("getSlotsMapping");
7447
7448 final long identity = Binder.clearCallingIdentity();
7449 try {
7450 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7451 // All logical slots should have a mapping to a physical slot.
7452 int[] logicalSlotsMapping = new int[phoneCount];
7453 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7454 for (int i = 0; i < slotInfos.length; i++) {
7455 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7456 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7457 }
7458 }
7459 return logicalSlotsMapping;
7460 } finally {
7461 Binder.restoreCallingIdentity(identity);
7462 }
7463 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007464
7465 /**
7466 * Get the IRadio HAL Version
7467 */
7468 @Override
7469 public int getRadioHalVersion() {
7470 Phone phone = getDefaultPhone();
7471 if (phone == null) return -1;
7472 HalVersion hv = phone.getHalVersion();
7473 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7474 return hv.major * 100 + hv.minor;
7475 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007476
7477 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007478 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7479 * corresponding network requests on a subId.
7480 *
7481 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007482 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007483 * 2) APN is un-metered for this subscription, or
7484 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7485 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7486 *
7487 * @return whether data is allowed for a apn type.
7488 *
7489 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007490 */
7491 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007492 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007493 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7494 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007495
7496 // Now that all security checks passes, perform the operation as ourselves.
7497 final long identity = Binder.clearCallingIdentity();
7498 try {
7499 Phone phone = getPhone(subId);
7500 if (phone == null) return false;
7501
Jack Yu41407ee2019-05-13 16:54:09 -07007502 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007503 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7504 } finally {
7505 Binder.restoreCallingIdentity(identity);
7506 }
7507 }
7508
7509 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007510 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007511 enforceReadPrivilegedPermission("isApnMetered");
7512
7513 // Now that all security checks passes, perform the operation as ourselves.
7514 final long identity = Binder.clearCallingIdentity();
7515 try {
7516 Phone phone = getPhone(subId);
7517 if (phone == null) return true; // By default return true.
7518
Jack Yu41407ee2019-05-13 16:54:09 -07007519 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007520 } finally {
7521 Binder.restoreCallingIdentity(identity);
7522 }
7523 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007524
7525 @Override
7526 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7527 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7528 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7529 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7530 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7531 }
7532 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7533 Intent intent = new Intent();
7534 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7535 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7536 // Bring up choose default SMS subscription dialog right now
7537 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7538 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7539 mApp.startActivity(intent);
7540 }
chen xud5ca2d52019-05-28 15:20:57 -07007541
7542 @Override
7543 public String getMmsUAProfUrl(int subId) {
7544 //TODO investigate if this API should require proper permission check in R b/133791609
7545 final long identity = Binder.clearCallingIdentity();
7546 try {
7547 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7548 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7549 } finally {
7550 Binder.restoreCallingIdentity(identity);
7551 }
7552 }
7553
7554 @Override
7555 public String getMmsUserAgent(int subId) {
7556 //TODO investigate if this API should require proper permission check in R b/133791609
7557 final long identity = Binder.clearCallingIdentity();
7558 try {
7559 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7560 .getString(com.android.internal.R.string.config_mms_user_agent);
7561 } finally {
7562 Binder.restoreCallingIdentity(identity);
7563 }
7564 }
Jack Yub07d4972019-05-28 16:12:25 -07007565
7566 @Override
7567 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7568 enforceModifyPermission();
7569
7570 // Now that all security checks passes, perform the operation as ourselves.
7571 final long identity = Binder.clearCallingIdentity();
7572 try {
7573 Phone phone = getPhone(subId);
7574 if (phone == null) return false;
7575
7576 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7577 } finally {
7578 Binder.restoreCallingIdentity(identity);
7579 }
7580 }
7581
7582 @Override
7583 public boolean isDataAllowedInVoiceCall(int subId) {
7584 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7585
7586 // Now that all security checks passes, perform the operation as ourselves.
7587 final long identity = Binder.clearCallingIdentity();
7588 try {
7589 Phone phone = getPhone(subId);
7590 if (phone == null) return false;
7591
7592 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7593 } finally {
7594 Binder.restoreCallingIdentity(identity);
7595 }
7596 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007597
7598 /**
7599 * Updates whether conference event pacakge handling is enabled.
7600 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7601 * otherwise.
7602 */
7603 @Override
7604 public void setCepEnabled(boolean isCepEnabled) {
7605 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7606
7607 final long identity = Binder.clearCallingIdentity();
7608 try {
7609 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7610 for (Phone phone : PhoneFactory.getPhones()) {
7611 Phone defaultPhone = phone.getImsPhone();
7612 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7613 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7614 ImsPhoneCallTracker imsPhoneCallTracker =
7615 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7616 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7617 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7618 + imsPhone.getMsisdn());
7619 }
7620 }
7621 } finally {
7622 Binder.restoreCallingIdentity(identity);
7623 }
7624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007625}