blob: cfbcafbb8bc5cd45e2f72c0cf0a2be00f64d441c [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;
Pengquan Meng85728fb2018-03-12 16:31:21 -070055import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
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 Xuc7b18ec2019-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 zhaod698b842019-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 Ebinger774ba362019-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 Ebinger77b832e2019-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;
Taesu Leef8fbed92019-10-07 18:47:02 +0900158import 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 zhaod698b842019-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
Pengquan Meng85728fb2018-03-12 16:31:21 -0700272 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
273 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
274 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
275
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276 /** The singleton instance. */
277 private static PhoneInterfaceManager sInstance;
278
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700281 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private AppOpsManager mAppOps;
283 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800284 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700286 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287
Derek Tan97ebb422014-09-05 16:55:38 -0700288 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
289 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800290 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800291 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700292
Michelecea4cf22018-12-21 15:00:11 -0800293 // String to store multi SIM allowed
294 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
295
Derek Tan740e1672017-06-27 14:56:27 -0700296 // The AID of ISD-R.
297 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
298
yinxub1bed742017-04-17 11:45:04 -0700299 private NetworkScanRequestTracker mNetworkScanRequestTracker;
300
David Kelly5e06a7f2018-03-12 14:10:59 +0000301 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
302 private static final int MANUFACTURER_CODE_LENGTH = 8;
303
Derek Tan89e89d42014-07-08 17:00:10 -0700304 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700305 * A request object to use for transmitting data to an ICC.
306 */
307 private static final class IccAPDUArgument {
308 public int channel, cla, command, p1, p2, p3;
309 public String data;
310
311 public IccAPDUArgument(int channel, int cla, int command,
312 int p1, int p2, int p3, String data) {
313 this.channel = channel;
314 this.cla = cla;
315 this.command = command;
316 this.p1 = p1;
317 this.p2 = p2;
318 this.p3 = p3;
319 this.data = data;
320 }
321 }
322
323 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700324 * A request object to use for transmitting data to an ICC.
325 */
326 private static final class ManualNetworkSelectionArgument {
327 public OperatorInfo operatorInfo;
328 public boolean persistSelection;
329
330 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
331 this.operatorInfo = operatorInfo;
332 this.persistSelection = persistSelection;
333 }
334 }
335
336 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
338 * request after sending. The main thread will notify the request when it is complete.
339 */
340 private static final class MainThreadRequest {
341 /** The argument to use for the request */
342 public Object argument;
343 /** The result of the request that is run on the main thread */
344 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800345 // The subscriber id that this request applies to. Defaults to
346 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
347 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348
Nathan Harold92bed182018-10-12 18:16:49 -0700349 // In cases where subId is unavailable, the caller needs to specify the phone.
350 public Phone phone;
351
vagdeviaf9a5b92018-08-15 16:01:53 -0700352 public WorkSource workSource;
353
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 public MainThreadRequest(Object argument) {
355 this.argument = argument;
356 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800357
Nathan Harold92bed182018-10-12 18:16:49 -0700358 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
359 this.argument = argument;
360 if (phone != null) {
361 this.phone = phone;
362 }
363 this.workSource = workSource;
364 }
365
vagdeviaf9a5b92018-08-15 16:01:53 -0700366 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800367 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800368 if (subId != null) {
369 this.subId = subId;
370 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700371 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800372 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 }
374
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800375 private static final class IncomingThirdPartyCallArgs {
376 public final ComponentName component;
377 public final String callId;
378 public final String callerDisplayName;
379
380 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
381 String callerDisplayName) {
382 this.component = component;
383 this.callId = callId;
384 this.callerDisplayName = callerDisplayName;
385 }
386 }
387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 /**
389 * A handler that processes messages on the main thread in the phone process. Since many
390 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
391 * inbound binder threads to the main thread in the phone process. The Binder thread
392 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
393 * on, which will be notified when the operation completes and will contain the result of the
394 * request.
395 *
396 * <p>If a MainThreadRequest object is provided in the msg.obj field,
397 * note that request.result must be set to something non-null for the calling thread to
398 * unblock.
399 */
400 private final class MainThreadHandler extends Handler {
401 @Override
402 public void handleMessage(Message msg) {
403 MainThreadRequest request;
404 Message onCompleted;
405 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800406 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700407 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800408 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409
410 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700411 case CMD_HANDLE_USSD_REQUEST: {
412 request = (MainThreadRequest) msg.obj;
413 final Phone phone = getPhoneFromRequest(request);
414 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
415 String ussdRequest = ussdObject.first;
416 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700417
Pengquan Menga1bb6272018-09-06 09:59:22 -0700418 if (!isUssdApiAllowed(request.subId)) {
419 // Carrier does not support use of this API, return failure.
420 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
421 UssdResponse response = new UssdResponse(ussdRequest, null);
422 Bundle returnData = new Bundle();
423 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
424 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700425
Pengquan Menga1bb6272018-09-06 09:59:22 -0700426 request.result = true;
427 notifyRequester(request);
428 return;
429 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700430
Pengquan Menga1bb6272018-09-06 09:59:22 -0700431 try {
432 request.result = phone != null
433 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
434 } catch (CallStateException cse) {
435 request.result = false;
436 }
437 // Wake up the requesting thread
438 notifyRequester(request);
439 break;
pkanwar32d516d2016-10-14 19:37:38 -0700440 }
441
Yorke Lee716f67e2015-06-17 15:39:16 -0700442 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700444 final Phone phone = getPhoneFromRequest(request);
445 request.result = phone != null ?
446 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
447 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700449 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800456 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 if (uiccCard == null) {
458 loge("iccTransmitApduLogicalChannel: No UICC");
459 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700461 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
463 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700464 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 iccArgument.channel, iccArgument.cla, iccArgument.command,
466 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700467 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700468 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700469 break;
470
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 ar = (AsyncResult) msg.obj;
473 request = (MainThreadRequest) ar.userObj;
474 if (ar.exception == null && ar.result != null) {
475 request.result = ar.result;
476 } else {
477 request.result = new IccIoResult(0x6F, 0, (byte[])null);
478 if (ar.result == null) {
479 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800480 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800482 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700483 } else {
484 loge("iccTransmitApduLogicalChannel: Unknown exception");
485 }
486 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 break;
489
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
491 request = (MainThreadRequest) msg.obj;
492 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800493 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 if (uiccCard == null) {
495 loge("iccTransmitApduBasicChannel: No UICC");
496 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700497 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 } else {
499 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
500 request);
501 uiccCard.iccTransmitApduBasicChannel(
502 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
503 iccArgument.p3, iccArgument.data, onCompleted);
504 }
505 break;
506
507 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
508 ar = (AsyncResult) msg.obj;
509 request = (MainThreadRequest) ar.userObj;
510 if (ar.exception == null && ar.result != null) {
511 request.result = ar.result;
512 } else {
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
514 if (ar.result == null) {
515 loge("iccTransmitApduBasicChannel: Empty response");
516 } else if (ar.exception instanceof CommandException) {
517 loge("iccTransmitApduBasicChannel: CommandException: " +
518 ar.exception);
519 } else {
520 loge("iccTransmitApduBasicChannel: Unknown exception");
521 }
522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 break;
525
526 case CMD_EXCHANGE_SIM_IO:
527 request = (MainThreadRequest) msg.obj;
528 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 if (uiccCard == null) {
531 loge("iccExchangeSimIO: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 } else {
535 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
536 request);
537 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
538 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
539 iccArgument.data, onCompleted);
540 }
541 break;
542
543 case EVENT_EXCHANGE_SIM_IO_DONE:
544 ar = (AsyncResult) msg.obj;
545 request = (MainThreadRequest) ar.userObj;
546 if (ar.exception == null && ar.result != null) {
547 request.result = ar.result;
548 } else {
549 request.result = new IccIoResult(0x6f, 0, (byte[])null);
550 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 break;
553
Derek Tan4d5e5c12014-02-04 11:54:58 -0800554 case CMD_SEND_ENVELOPE:
555 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800556 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 if (uiccCard == null) {
558 loge("sendEnvelopeWithStatus: No UICC");
559 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 } else {
562 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
563 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
564 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 break;
566
567 case EVENT_SEND_ENVELOPE_DONE:
568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700570 if (ar.exception == null && ar.result != null) {
571 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800572 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700573 request.result = new IccIoResult(0x6F, 0, (byte[])null);
574 if (ar.result == null) {
575 loge("sendEnvelopeWithStatus: Empty response");
576 } else if (ar.exception instanceof CommandException) {
577 loge("sendEnvelopeWithStatus: CommandException: " +
578 ar.exception);
579 } else {
580 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
581 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800582 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800584 break;
585
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 case CMD_OPEN_CHANNEL:
587 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800588 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800589 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 if (uiccCard == null) {
591 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800592 request.result = new IccOpenLogicalChannelResponse(-1,
593 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 } else {
596 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800597 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
598 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 break;
601
602 case EVENT_OPEN_CHANNEL_DONE:
603 ar = (AsyncResult) msg.obj;
604 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 int[] result = (int[]) ar.result;
608 int channelId = result[0];
609 byte[] selectResponse = null;
610 if (result.length > 1) {
611 selectResponse = new byte[result.length - 1];
612 for (int i = 1; i < result.length; ++i) {
613 selectResponse[i - 1] = (byte) result[i];
614 }
615 }
616 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700617 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 if (ar.result == null) {
620 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 if (ar.exception != null) {
623 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
624 }
625
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700627 if (ar.exception instanceof CommandException) {
628 CommandException.Error error =
629 ((CommandException) (ar.exception)).getCommandError();
630 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700631 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700632 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700633 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 }
635 }
636 openChannelResp = new IccOpenLogicalChannelResponse(
637 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700639 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 break;
642
643 case CMD_CLOSE_CHANNEL:
644 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800645 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700646 if (uiccCard == null) {
647 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900648 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700649 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700650 } else {
651 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
652 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
653 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 break;
655
656 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800657 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
658 break;
659
660 case CMD_NV_READ_ITEM:
661 request = (MainThreadRequest) msg.obj;
662 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800663 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
664 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800665 break;
666
667 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 ar = (AsyncResult) msg.obj;
669 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800670 if (ar.exception == null && ar.result != null) {
671 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800673 request.result = "";
674 if (ar.result == null) {
675 loge("nvReadItem: Empty response");
676 } else if (ar.exception instanceof CommandException) {
677 loge("nvReadItem: CommandException: " +
678 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800680 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 }
682 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 break;
685
Jake Hambye994d462014-02-03 13:10:13 -0800686 case CMD_NV_WRITE_ITEM:
687 request = (MainThreadRequest) msg.obj;
688 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
689 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800690 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700691 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800692 break;
693
694 case EVENT_NV_WRITE_ITEM_DONE:
695 handleNullReturnEvent(msg, "nvWriteItem");
696 break;
697
698 case CMD_NV_WRITE_CDMA_PRL:
699 request = (MainThreadRequest) msg.obj;
700 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800701 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800702 break;
703
704 case EVENT_NV_WRITE_CDMA_PRL_DONE:
705 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
706 break;
707
chen xu6dac5ab2018-10-26 17:39:23 -0700708 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800709 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700710 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800711 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800712 break;
713
chen xu6dac5ab2018-10-26 17:39:23 -0700714 case EVENT_RESET_MODEM_CONFIG_DONE:
715 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800716 break;
717
Jake Hamby7c27be32014-03-03 13:25:59 -0800718 case CMD_GET_PREFERRED_NETWORK_TYPE:
719 request = (MainThreadRequest) msg.obj;
720 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700721 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800722 break;
723
724 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
725 ar = (AsyncResult) msg.obj;
726 request = (MainThreadRequest) ar.userObj;
727 if (ar.exception == null && ar.result != null) {
728 request.result = ar.result; // Integer
729 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800730 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 if (ar.result == null) {
732 loge("getPreferredNetworkType: Empty response");
733 } else if (ar.exception instanceof CommandException) {
734 loge("getPreferredNetworkType: CommandException: " +
735 ar.exception);
736 } else {
737 loge("getPreferredNetworkType: Unknown exception");
738 }
739 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800741 break;
742
743 case CMD_SET_PREFERRED_NETWORK_TYPE:
744 request = (MainThreadRequest) msg.obj;
745 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
746 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700747 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800748 break;
749
750 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
751 handleNullReturnEvent(msg, "setPreferredNetworkType");
752 break;
753
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000754 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
755 request = (MainThreadRequest)msg.obj;
756 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800757 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000758 break;
759
760 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
761 ar = (AsyncResult)msg.obj;
762 request = (MainThreadRequest)ar.userObj;
763 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700764 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000765 break;
766
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800767 case CMD_SET_VOICEMAIL_NUMBER:
768 request = (MainThreadRequest) msg.obj;
769 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
770 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800771 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
772 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800773 break;
774
775 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
776 handleNullReturnEvent(msg, "setVoicemailNumber");
777 break;
778
Stuart Scott54788802015-03-30 13:18:01 -0700779 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
782 request);
783 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
784 break;
785
786 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
787 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
788 break;
789
Shishir Agrawal302c8692015-06-19 13:49:39 -0700790 case CMD_PERFORM_NETWORK_SCAN:
791 request = (MainThreadRequest) msg.obj;
792 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
793 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
794 break;
795
796 case EVENT_PERFORM_NETWORK_SCAN_DONE:
797 ar = (AsyncResult) msg.obj;
798 request = (MainThreadRequest) ar.userObj;
799 CellNetworkScanResult cellScanResult;
800 if (ar.exception == null && ar.result != null) {
801 cellScanResult = new CellNetworkScanResult(
802 CellNetworkScanResult.STATUS_SUCCESS,
803 (List<OperatorInfo>) ar.result);
804 } else {
805 if (ar.result == null) {
806 loge("getCellNetworkScanResults: Empty response");
807 }
808 if (ar.exception != null) {
809 loge("getCellNetworkScanResults: Exception: " + ar.exception);
810 }
811 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
812 if (ar.exception instanceof CommandException) {
813 CommandException.Error error =
814 ((CommandException) (ar.exception)).getCommandError();
815 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
816 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
817 } else if (error == CommandException.Error.GENERIC_FAILURE) {
818 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
819 }
820 }
821 cellScanResult = new CellNetworkScanResult(errorCode, null);
822 }
823 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700824 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700825 break;
826
827 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
828 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700829 ManualNetworkSelectionArgument selArg =
830 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700831 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
832 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700833 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
834 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700835 break;
836
837 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null) {
841 request.result = true;
842 } else {
843 request.result = false;
844 loge("setNetworkSelectionModeManual " + ar.exception);
845 }
846 notifyRequester(request);
847 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700848 break;
849
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700850 case CMD_GET_MODEM_ACTIVITY_INFO:
851 request = (MainThreadRequest) msg.obj;
852 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700853 if (defaultPhone != null) {
854 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
855 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700856 break;
857
858 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
859 ar = (AsyncResult) msg.obj;
860 request = (MainThreadRequest) ar.userObj;
861 if (ar.exception == null && ar.result != null) {
862 request.result = ar.result;
863 } else {
864 if (ar.result == null) {
865 loge("queryModemActivityInfo: Empty response");
866 } else if (ar.exception instanceof CommandException) {
867 loge("queryModemActivityInfo: CommandException: " +
868 ar.exception);
869 } else {
870 loge("queryModemActivityInfo: Unknown exception");
871 }
872 }
Amit Mahajand4766222016-01-28 15:28:28 -0800873 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
874 if (request.result == null) {
875 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
876 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700877 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700878 break;
879
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 case CMD_SET_ALLOWED_CARRIERS:
881 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800882 CarrierRestrictionRules argument =
883 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700884 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800885 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700886 break;
887
888 case EVENT_SET_ALLOWED_CARRIERS_DONE:
889 ar = (AsyncResult) msg.obj;
890 request = (MainThreadRequest) ar.userObj;
891 if (ar.exception == null && ar.result != null) {
892 request.result = ar.result;
893 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800894 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
895 if (ar.exception instanceof CommandException) {
896 loge("setAllowedCarriers: CommandException: " + ar.exception);
897 CommandException.Error error =
898 ((CommandException) (ar.exception)).getCommandError();
899 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
900 request.result =
901 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
902 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700903 } else {
904 loge("setAllowedCarriers: Unknown exception");
905 }
906 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700907 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700908 break;
909
910 case CMD_GET_ALLOWED_CARRIERS:
911 request = (MainThreadRequest) msg.obj;
912 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800913 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700914 break;
915
916 case EVENT_GET_ALLOWED_CARRIERS_DONE:
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 if (ar.exception == null && ar.result != null) {
920 request.result = ar.result;
921 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800922 request.result = new IllegalStateException(
923 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700924 if (ar.result == null) {
925 loge("getAllowedCarriers: Empty response");
926 } else if (ar.exception instanceof CommandException) {
927 loge("getAllowedCarriers: CommandException: " +
928 ar.exception);
929 } else {
930 loge("getAllowedCarriers: Unknown exception");
931 }
932 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700933 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700934 break;
935
Nathan Haroldb3014052017-01-25 15:57:32 -0800936 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
937 ar = (AsyncResult) msg.obj;
938 request = (MainThreadRequest) ar.userObj;
939 if (ar.exception == null && ar.result != null) {
940 request.result = ar.result;
941 } else {
942 request.result = new IllegalArgumentException(
943 "Failed to retrieve Forbidden Plmns");
944 if (ar.result == null) {
945 loge("getForbiddenPlmns: Empty response");
946 } else {
947 loge("getForbiddenPlmns: Unknown exception");
948 }
949 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700950 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800951 break;
952
953 case CMD_GET_FORBIDDEN_PLMNS:
954 request = (MainThreadRequest) msg.obj;
955 uiccCard = getUiccCardFromRequest(request);
956 if (uiccCard == null) {
957 loge("getForbiddenPlmns() UiccCard is null");
958 request.result = new IllegalArgumentException(
959 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700960 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800961 break;
962 }
963 Integer appType = (Integer) request.argument;
964 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
965 if (uiccApp == null) {
966 loge("getForbiddenPlmns() no app with specified type -- "
967 + appType);
968 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700969 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800970 break;
971 } else {
972 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
973 + " specified type -- " + appType);
974 }
975 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
976 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
977 onCompleted);
978 break;
979
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000980 case CMD_SWITCH_SLOTS:
981 request = (MainThreadRequest) msg.obj;
982 int[] physicalSlots = (int[]) request.argument;
983 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
984 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
985 break;
986
987 case EVENT_SWITCH_SLOTS_DONE:
988 ar = (AsyncResult) msg.obj;
989 request = (MainThreadRequest) ar.userObj;
990 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700991 notifyRequester(request);
992 break;
993 case CMD_GET_NETWORK_SELECTION_MODE:
994 request = (MainThreadRequest) msg.obj;
995 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
996 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
997 break;
998
999 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1000 ar = (AsyncResult) msg.obj;
1001 request = (MainThreadRequest) ar.userObj;
1002 if (ar.exception != null) {
1003 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1004 } else {
1005 int mode = ((int[]) ar.result)[0];
1006 if (mode == 0) {
1007 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1008 } else {
1009 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1010 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001011 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001012 notifyRequester(request);
1013 break;
1014 case CMD_GET_CDMA_ROAMING_MODE:
1015 request = (MainThreadRequest) msg.obj;
1016 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1017 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1018 break;
1019 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1020 ar = (AsyncResult) msg.obj;
1021 request = (MainThreadRequest) ar.userObj;
1022 if (ar.exception != null) {
1023 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1024 } else {
1025 request.result = ((int[]) ar.result)[0];
1026 }
1027 notifyRequester(request);
1028 break;
1029 case CMD_SET_CDMA_ROAMING_MODE:
1030 request = (MainThreadRequest) msg.obj;
1031 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1032 int mode = (int) request.argument;
1033 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1034 break;
1035 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1036 ar = (AsyncResult) msg.obj;
1037 request = (MainThreadRequest) ar.userObj;
1038 request.result = ar.exception == null;
1039 notifyRequester(request);
1040 break;
1041 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1042 request = (MainThreadRequest) msg.obj;
1043 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1044 int subscriptionMode = (int) request.argument;
1045 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1046 break;
1047 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1048 ar = (AsyncResult) msg.obj;
1049 request = (MainThreadRequest) ar.userObj;
1050 request.result = ar.exception == null;
1051 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001052 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001053 case CMD_GET_ALL_CELL_INFO:
1054 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001055 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001056 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001058 case EVENT_GET_ALL_CELL_INFO_DONE:
1059 ar = (AsyncResult) msg.obj;
1060 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001061 // If a timeout occurs, the response will be null
1062 request.result = (ar.exception == null && ar.result != null)
1063 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 synchronized (request) {
1065 request.notifyAll();
1066 }
1067 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001068 case CMD_REQUEST_CELL_INFO_UPDATE:
1069 request = (MainThreadRequest) msg.obj;
1070 request.phone.requestCellInfoUpdate(request.workSource,
1071 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1072 break;
1073 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1074 ar = (AsyncResult) msg.obj;
1075 request = (MainThreadRequest) ar.userObj;
1076 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1077 try {
1078 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001079 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001080 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1081 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001082 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001083 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001084 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 } else {
1086 // use the result as returned
1087 cb.onCellInfo((List<CellInfo>) ar.result);
1088 }
1089 } catch (RemoteException re) {
1090 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1091 }
1092 break;
1093 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001094 request = (MainThreadRequest) msg.obj;
1095 WorkSource ws = (WorkSource) request.argument;
1096 Phone phone = getPhoneFromRequest(request);
1097 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1098 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001099 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001100 ar = (AsyncResult) msg.obj;
1101 request = (MainThreadRequest) ar.userObj;
1102 if (ar.exception == null) {
1103 request.result = ar.result;
1104 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001105 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001106 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1107 ? new CdmaCellLocation() : new GsmCellLocation();
1108 }
1109
1110 synchronized (request) {
1111 request.notifyAll();
1112 }
1113 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001114 case CMD_MODEM_REBOOT:
1115 request = (MainThreadRequest) msg.obj;
1116 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001117 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001118 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001119 case EVENT_CMD_MODEM_REBOOT_DONE:
1120 handleNullReturnEvent(msg, "rebootModem");
1121 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001122 case CMD_REQUEST_ENABLE_MODEM:
1123 request = (MainThreadRequest) msg.obj;
1124 boolean enable = (boolean) request.argument;
1125 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001126 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001127 PhoneConfigurationManager.getInstance()
1128 .enablePhone(request.phone, enable, onCompleted);
1129 break;
1130 case EVENT_ENABLE_MODEM_DONE:
1131 ar = (AsyncResult) msg.obj;
1132 request = (MainThreadRequest) ar.userObj;
1133 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001134 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001135 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001136 if ((boolean) request.result) {
1137 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1138 updateModemStateMetrics();
1139 } else {
1140 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1141 + ar.exception);
1142 }
1143 notifyRequester(request);
1144 break;
1145 case CMD_GET_MODEM_STATUS:
1146 request = (MainThreadRequest) msg.obj;
1147 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1148 PhoneConfigurationManager.getInstance()
1149 .getPhoneStatusFromModem(request.phone, onCompleted);
1150 break;
1151 case EVENT_GET_MODEM_STATUS_DONE:
1152 ar = (AsyncResult) msg.obj;
1153 request = (MainThreadRequest) ar.userObj;
1154 int id = request.phone.getPhoneId();
1155 if (ar.exception == null && ar.result != null) {
1156 request.result = ar.result;
1157 //update the cache as modem status has changed
1158 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1159 (boolean) request.result);
1160 } else {
1161 // Return true if modem status cannot be retrieved. For most cases,
1162 // modem status is on. And for older version modems, GET_MODEM_STATUS
1163 // and disable modem are not supported. Modem is always on.
1164 // TODO: this should be fixed in R to support a third
1165 // status UNKNOWN b/131631629
1166 request.result = true;
1167 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1168 + ar.exception);
1169 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001170 notifyRequester(request);
1171 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001172 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1173 ar = (AsyncResult) msg.obj;
1174 request = (MainThreadRequest) ar.userObj;
1175 if (ar.exception == null && ar.result != null) {
1176 request.result = ar.result;
1177 } else {
1178 request.result = -1;
1179 loge("Failed to set Forbidden Plmns");
1180 if (ar.result == null) {
1181 loge("setForbidenPlmns: Empty response");
1182 } else if (ar.exception != null) {
1183 loge("setForbiddenPlmns: Exception: " + ar.exception);
1184 request.result = -1;
1185 } else {
1186 loge("setForbiddenPlmns: Unknown exception");
1187 }
1188 }
1189 notifyRequester(request);
1190 break;
1191 case CMD_SET_FORBIDDEN_PLMNS:
1192 request = (MainThreadRequest) msg.obj;
1193 uiccCard = getUiccCardFromRequest(request);
1194 if (uiccCard == null) {
1195 loge("setForbiddenPlmns: UiccCard is null");
1196 request.result = -1;
1197 notifyRequester(request);
1198 break;
1199 }
1200 Pair<Integer, List<String>> setFplmnsArgs =
1201 (Pair<Integer, List<String>>) request.argument;
1202 appType = setFplmnsArgs.first;
1203 List<String> fplmns = setFplmnsArgs.second;
1204 uiccApp = uiccCard.getApplicationByType(appType);
1205 if (uiccApp == null) {
1206 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1207 request.result = -1;
1208 loge("Failed to get UICC App");
1209 notifyRequester(request);
1210 } else {
1211 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1212 ((SIMRecords) uiccApp.getIccRecords())
1213 .setForbiddenPlmns(onCompleted, fplmns);
1214 }
1215 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001216 default:
1217 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1218 break;
1219 }
1220 }
Jake Hambye994d462014-02-03 13:10:13 -08001221
Pengquan Menga1bb6272018-09-06 09:59:22 -07001222 private void notifyRequester(MainThreadRequest request) {
1223 synchronized (request) {
1224 request.notifyAll();
1225 }
1226 }
1227
Jake Hambye994d462014-02-03 13:10:13 -08001228 private void handleNullReturnEvent(Message msg, String command) {
1229 AsyncResult ar = (AsyncResult) msg.obj;
1230 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1231 if (ar.exception == null) {
1232 request.result = true;
1233 } else {
1234 request.result = false;
1235 if (ar.exception instanceof CommandException) {
1236 loge(command + ": CommandException: " + ar.exception);
1237 } else {
1238 loge(command + ": Unknown exception");
1239 }
1240 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001241 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001243 }
1244
1245 /**
1246 * Posts the specified command to be executed on the main thread,
1247 * waits for the request to complete, and returns the result.
1248 * @see #sendRequestAsync
1249 */
1250 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001251 return sendRequest(
1252 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001253 }
1254
1255 /**
1256 * Posts the specified command to be executed on the main thread,
1257 * waits for the request to complete, and returns the result.
1258 * @see #sendRequestAsync
1259 */
1260 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1261 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001262 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001263 }
1264
1265 /**
1266 * Posts the specified command to be executed on the main thread,
1267 * waits for the request to complete, and returns the result.
1268 * @see #sendRequestAsync
1269 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001270 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001271 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001272 }
1273
1274 /**
1275 * Posts the specified command to be executed on the main thread,
1276 * waits for the request to complete, and returns the result.
1277 * @see #sendRequestAsync
1278 */
Nathan Harold92bed182018-10-12 18:16:49 -07001279 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1280 return sendRequest(command, argument, subId, null, workSource);
1281 }
1282
1283 /**
1284 * Posts the specified command to be executed on the main thread,
1285 * waits for the request to complete, and returns the result.
1286 * @see #sendRequestAsync
1287 */
1288 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1289 return sendRequest(
1290 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1291 }
1292
1293 /**
1294 * Posts the specified command to be executed on the main thread,
1295 * waits for the request to complete, and returns the result.
1296 * @see #sendRequestAsync
1297 */
1298 private Object sendRequest(
1299 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1301 throw new RuntimeException("This method will deadlock if called from the main thread.");
1302 }
1303
Nathan Harold92bed182018-10-12 18:16:49 -07001304 MainThreadRequest request = null;
1305 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1306 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1307 } else if (phone != null) {
1308 request = new MainThreadRequest(argument, phone, workSource);
1309 } else {
1310 request = new MainThreadRequest(argument, subId, workSource);
1311 }
1312
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 Message msg = mMainThreadHandler.obtainMessage(command, request);
1314 msg.sendToTarget();
1315
1316 // Wait for the request to complete
1317 synchronized (request) {
1318 while (request.result == null) {
1319 try {
1320 request.wait();
1321 } catch (InterruptedException e) {
1322 // Do nothing, go back and wait until the request is complete
1323 }
1324 }
1325 }
1326 return request.result;
1327 }
1328
1329 /**
1330 * Asynchronous ("fire and forget") version of sendRequest():
1331 * Posts the specified command to be executed on the main thread, and
1332 * returns immediately.
1333 * @see #sendRequest
1334 */
1335 private void sendRequestAsync(int command) {
1336 mMainThreadHandler.sendEmptyMessage(command);
1337 }
1338
1339 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001340 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001341 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001342 */
1343 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001344 sendRequestAsync(command, argument, null, null);
1345 }
1346
1347 /**
1348 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1349 * @see {@link #sendRequest(int,Object)}
1350 */
1351 private void sendRequestAsync(
1352 int command, Object argument, Phone phone, WorkSource workSource) {
1353 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001354 Message msg = mMainThreadHandler.obtainMessage(command, request);
1355 msg.sendToTarget();
1356 }
1357
1358 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359 * Initialize the singleton PhoneInterfaceManager instance.
1360 * This is only done once, at startup, from PhoneApp.onCreate().
1361 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001362 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363 synchronized (PhoneInterfaceManager.class) {
1364 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001365 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001366 } else {
1367 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1368 }
1369 return sInstance;
1370 }
1371 }
1372
1373 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001374 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001377 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1379 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001380 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001381 mTelephonySharedPreferences =
1382 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001383 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001384 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001385
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 publish();
1387 }
1388
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001389 private Phone getDefaultPhone() {
1390 Phone thePhone = getPhone(getDefaultSubscription());
1391 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1392 }
1393
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 private void publish() {
1395 if (DBG) log("publish: " + this);
1396
1397 ServiceManager.addService("phone", this);
1398 }
1399
Stuart Scott584921c2015-01-15 17:10:34 -08001400 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001401 if (request.phone != null) {
1402 return request.phone;
1403 } else {
1404 return getPhoneFromSubId(request.subId);
1405 }
1406 }
1407
1408 private Phone getPhoneFromSubId(int subId) {
1409 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1410 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001411 }
1412
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001413 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1414 Phone phone = getPhoneFromRequest(request);
1415 return phone == null ? null :
1416 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1417 }
1418
Wink Saville36469e72014-06-11 15:17:00 -07001419 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001420 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001421 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001423
1424 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001425 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001426 }
1427
Wink Savilleb564aae2014-10-23 10:18:09 -07001428 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001429 if (DBG) log("dial: " + number);
1430 // No permission check needed here: This is just a wrapper around the
1431 // ACTION_DIAL intent, which is available to any app since it puts up
1432 // the UI before it does anything.
1433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001434 final long identity = Binder.clearCallingIdentity();
1435 try {
1436 String url = createTelUrl(number);
1437 if (url == null) {
1438 return;
1439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001441 // PENDING: should we just silently fail if phone is offhook or ringing?
1442 PhoneConstants.State state = mCM.getState(subId);
1443 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1444 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1445 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1446 mApp.startActivity(intent);
1447 }
1448 } finally {
1449 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 }
1451 }
1452
1453 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001455 }
1456
Wink Savilleb564aae2014-10-23 10:18:09 -07001457 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458 if (DBG) log("call: " + number);
1459
1460 // This is just a wrapper around the ACTION_CALL intent, but we still
1461 // need to do a permission check since we're calling startActivity()
1462 // from the context of the phone app.
1463 enforceCallPermission();
1464
Jordan Liu1617b712019-07-10 15:06:26 -07001465 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001466 != AppOpsManager.MODE_ALLOWED) {
1467 return;
1468 }
1469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001470 final long identity = Binder.clearCallingIdentity();
1471 try {
1472 String url = createTelUrl(number);
1473 if (url == null) {
1474 return;
1475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001477 boolean isValid = false;
1478 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1479 if (slist != null) {
1480 for (SubscriptionInfo subInfoRecord : slist) {
1481 if (subInfoRecord.getSubscriptionId() == subId) {
1482 isValid = true;
1483 break;
1484 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001485 }
Wink Saville08874612014-08-31 19:19:58 -07001486 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001487 if (!isValid) {
1488 return;
1489 }
Wink Saville08874612014-08-31 19:19:58 -07001490
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001491 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1492 intent.putExtra(SUBSCRIPTION_KEY, subId);
1493 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1494 mApp.startActivity(intent);
1495 } finally {
1496 Binder.restoreCallingIdentity(identity);
1497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 }
1499
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001500 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001501 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001502 }
1503
Wink Savilleb564aae2014-10-23 10:18:09 -07001504 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001505 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001506 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1507 }
1508
1509 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001510 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001511 }
1512
Wink Savilleb564aae2014-10-23 10:18:09 -07001513 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001514 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001515 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1516 }
1517
1518 /** {@hide} */
1519 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001520 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001521 }
1522
Wink Savilleb564aae2014-10-23 10:18:09 -07001523 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001525
1526 final long identity = Binder.clearCallingIdentity();
1527 try {
1528 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1529 checkSimPin.start();
1530 return checkSimPin.unlockSim(null, pin);
1531 } finally {
1532 Binder.restoreCallingIdentity(identity);
1533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534 }
1535
Wink Saville9de0f752013-10-22 19:04:03 -07001536 /** {@hide} */
1537 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001538 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001539 }
1540
Wink Savilleb564aae2014-10-23 10:18:09 -07001541 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001542 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001543
1544 final long identity = Binder.clearCallingIdentity();
1545 try {
1546 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1547 checkSimPuk.start();
1548 return checkSimPuk.unlockSim(puk, pin);
1549 } finally {
1550 Binder.restoreCallingIdentity(identity);
1551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001552 }
1553
1554 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001555 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 * a synchronous one.
1557 */
1558 private static class UnlockSim extends Thread {
1559
1560 private final IccCard mSimCard;
1561
1562 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001563 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1564 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565
1566 // For replies from SimCard interface
1567 private Handler mHandler;
1568
1569 // For async handler to identify request type
1570 private static final int SUPPLY_PIN_COMPLETE = 100;
1571
1572 public UnlockSim(IccCard simCard) {
1573 mSimCard = simCard;
1574 }
1575
1576 @Override
1577 public void run() {
1578 Looper.prepare();
1579 synchronized (UnlockSim.this) {
1580 mHandler = new Handler() {
1581 @Override
1582 public void handleMessage(Message msg) {
1583 AsyncResult ar = (AsyncResult) msg.obj;
1584 switch (msg.what) {
1585 case SUPPLY_PIN_COMPLETE:
1586 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1587 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001588 mRetryCount = msg.arg1;
1589 if (ar.exception != null) {
1590 if (ar.exception instanceof CommandException &&
1591 ((CommandException)(ar.exception)).getCommandError()
1592 == CommandException.Error.PASSWORD_INCORRECT) {
1593 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1594 } else {
1595 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1596 }
1597 } else {
1598 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 mDone = true;
1601 UnlockSim.this.notifyAll();
1602 }
1603 break;
1604 }
1605 }
1606 };
1607 UnlockSim.this.notifyAll();
1608 }
1609 Looper.loop();
1610 }
1611
1612 /*
1613 * Use PIN or PUK to unlock SIM card
1614 *
1615 * If PUK is null, unlock SIM card with PIN
1616 *
1617 * If PUK is not null, unlock SIM card with PUK and set PIN code
1618 */
Wink Saville9de0f752013-10-22 19:04:03 -07001619 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620
1621 while (mHandler == null) {
1622 try {
1623 wait();
1624 } catch (InterruptedException e) {
1625 Thread.currentThread().interrupt();
1626 }
1627 }
1628 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1629
1630 if (puk == null) {
1631 mSimCard.supplyPin(pin, callback);
1632 } else {
1633 mSimCard.supplyPuk(puk, pin, callback);
1634 }
1635
1636 while (!mDone) {
1637 try {
1638 Log.d(LOG_TAG, "wait for done");
1639 wait();
1640 } catch (InterruptedException e) {
1641 // Restore the interrupted status
1642 Thread.currentThread().interrupt();
1643 }
1644 }
1645 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001646 int[] resultArray = new int[2];
1647 resultArray[0] = mResult;
1648 resultArray[1] = mRetryCount;
1649 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 }
1651 }
1652
1653 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001654 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001655
1656 }
1657
Wink Savilleb564aae2014-10-23 10:18:09 -07001658 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 // No permission check needed here: this call is harmless, and it's
1660 // needed for the ServiceState.requestStateUpdate() call (which is
1661 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001662 final long identity = Binder.clearCallingIdentity();
1663 try {
1664 final Phone phone = getPhone(subId);
1665 if (phone != null) {
1666 phone.updateServiceLocation();
1667 }
1668 } finally {
1669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 }
1672
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001673 @Override
1674 public boolean isRadioOn(String callingPackage) {
1675 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001676 }
1677
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001678 @Override
1679 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001680 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001681 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001682 return false;
1683 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001684
1685 final long identity = Binder.clearCallingIdentity();
1686 try {
1687 return isRadioOnForSubscriber(subId);
1688 } finally {
1689 Binder.restoreCallingIdentity(identity);
1690 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001691 }
1692
1693 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001694 final long identity = Binder.clearCallingIdentity();
1695 try {
1696 final Phone phone = getPhone(subId);
1697 if (phone != null) {
1698 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1699 } else {
1700 return false;
1701 }
1702 } finally {
1703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 }
1706
1707 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001708 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709 }
Wink Saville36469e72014-06-11 15:17:00 -07001710
Wink Savilleb564aae2014-10-23 10:18:09 -07001711 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
1718 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1719 }
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001722 }
Wink Saville36469e72014-06-11 15:17:00 -07001723 }
1724
1725 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001726 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001727 }
1728
Wink Savilleb564aae2014-10-23 10:18:09 -07001729 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001730 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001731
1732 final long identity = Binder.clearCallingIdentity();
1733 try {
1734 final Phone phone = getPhone(subId);
1735 if (phone == null) {
1736 return false;
1737 }
1738 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1739 toggleRadioOnOffForSubscriber(subId);
1740 }
1741 return true;
1742 } finally {
1743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
Wink Saville36469e72014-06-11 15:17:00 -07001746
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001747 public boolean needMobileRadioShutdown() {
1748 /*
1749 * If any of the Radios are available, it will need to be
1750 * shutdown. So return true if any Radio is available.
1751 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001752 final long identity = Binder.clearCallingIdentity();
1753 try {
1754 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1755 Phone phone = PhoneFactory.getPhone(i);
1756 if (phone != null && phone.isRadioAvailable()) return true;
1757 }
1758 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1759 return false;
1760 } finally {
1761 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001762 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001763 }
1764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001765 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001766 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001767 enforceModifyPermission();
1768
1769 final long identity = Binder.clearCallingIdentity();
1770 try {
1771 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1772 logv("Shutting down Phone " + i);
1773 shutdownRadioUsingPhoneId(i);
1774 }
1775 } finally {
1776 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001777 }
1778 }
1779
1780 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001781 Phone phone = PhoneFactory.getPhone(phoneId);
1782 if (phone != null && phone.isRadioAvailable()) {
1783 phone.shutdownRadio();
1784 }
1785 }
1786
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001788 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001789
1790 final long identity = Binder.clearCallingIdentity();
1791 try {
1792 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1793 if (defaultPhone != null) {
1794 defaultPhone.setRadioPower(turnOn);
1795 return true;
1796 } else {
1797 loge("There's no default phone.");
1798 return false;
1799 }
1800 } finally {
1801 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001802 }
Wink Saville36469e72014-06-11 15:17:00 -07001803 }
1804
Wink Savilleb564aae2014-10-23 10:18:09 -07001805 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001807
1808 final long identity = Binder.clearCallingIdentity();
1809 try {
1810 final Phone phone = getPhone(subId);
1811 if (phone != null) {
1812 phone.setRadioPower(turnOn);
1813 return true;
1814 } else {
1815 return false;
1816 }
1817 } finally {
1818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 }
1821
Wink Saville36469e72014-06-11 15:17:00 -07001822 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001823 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 public boolean enableDataConnectivity() {
1825 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001826
1827 final long identity = Binder.clearCallingIdentity();
1828 try {
1829 int subId = mSubscriptionController.getDefaultDataSubId();
1830 final Phone phone = getPhone(subId);
1831 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001832 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001833 return true;
1834 } else {
1835 return false;
1836 }
1837 } finally {
1838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 }
1841
Wink Saville36469e72014-06-11 15:17:00 -07001842 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001843 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001844 public boolean disableDataConnectivity() {
1845 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001846
1847 final long identity = Binder.clearCallingIdentity();
1848 try {
1849 int subId = mSubscriptionController.getDefaultDataSubId();
1850 final Phone phone = getPhone(subId);
1851 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001852 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001853 return true;
1854 } else {
1855 return false;
1856 }
1857 } finally {
1858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 }
1861
Sanket Padawe356d7632015-06-22 14:03:32 -07001862 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001863 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001864 final long identity = Binder.clearCallingIdentity();
1865 try {
1866 final Phone phone = getPhone(subId);
1867 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001868 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001869 } else {
1870 return false;
1871 }
1872 } finally {
1873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 }
1876
1877 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001878 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001879 }
1880
pkanwarae03a6b2016-11-06 20:37:09 -08001881 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001882 enforceCallPermission();
1883
1884 final long identity = Binder.clearCallingIdentity();
1885 try {
1886 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1887 return;
1888 }
1889 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1890 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1891 } finally {
1892 Binder.restoreCallingIdentity(identity);
1893 }
pkanwar32d516d2016-10-14 19:37:38 -07001894 };
1895
Wink Savilleb564aae2014-10-23 10:18:09 -07001896 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898
1899 final long identity = Binder.clearCallingIdentity();
1900 try {
1901 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1902 return false;
1903 }
1904 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1905 } finally {
1906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 }
1909
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001911 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001912 }
1913
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001914 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001915 final long identity = Binder.clearCallingIdentity();
1916 try {
1917 Phone phone = PhoneFactory.getPhone(slotIndex);
1918 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1919 PhoneConstantConversions.convertCallState(phone.getState());
1920 } finally {
1921 Binder.restoreCallingIdentity(identity);
1922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923 }
1924
Sanket Padawe356d7632015-06-22 14:03:32 -07001925 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001926 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001927 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1928 }
1929
1930 @Override
1931 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001932 final long identity = Binder.clearCallingIdentity();
1933 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001934 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001935 if (phone != null) {
1936 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1937 } else {
1938 return PhoneConstantConversions.convertDataState(
1939 PhoneConstants.DataState.DISCONNECTED);
1940 }
1941 } finally {
1942 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001943 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 }
1945
Sanket Padawe356d7632015-06-22 14:03:32 -07001946 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001947 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001948 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1949 }
1950
1951 @Override
1952 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001953 final long identity = Binder.clearCallingIdentity();
1954 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001955 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001956 if (phone != null) {
1957 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1958 } else {
1959 return TelephonyManager.DATA_ACTIVITY_NONE;
1960 }
1961 } finally {
1962 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001963 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001964 }
1965
1966 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001967 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001968 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001969 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001970
1971 LocationAccessPolicy.LocationPermissionResult locationResult =
1972 LocationAccessPolicy.checkLocationPermission(mApp,
1973 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1974 .setCallingPackage(callingPackage)
1975 .setCallingPid(Binder.getCallingPid())
1976 .setCallingUid(Binder.getCallingUid())
1977 .setMethod("getCellLocation")
1978 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1979 .build());
1980 switch (locationResult) {
1981 case DENIED_HARD:
1982 throw new SecurityException("Not allowed to access cell location");
1983 case DENIED_SOFT:
1984 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001985 }
1986
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001987 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001988 final long identity = Binder.clearCallingIdentity();
1989 try {
1990 if (DBG_LOC) log("getCellLocation: is active user");
1991 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001992 int subId = mSubscriptionController.getDefaultDataSubId();
1993 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1994 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001995 return data;
1996 } finally {
1997 Binder.restoreCallingIdentity(identity);
1998 }
Svetoslav64fad262015-04-14 14:35:21 -07001999 }
2000
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002002 public String getNetworkCountryIsoForPhone(int phoneId) {
2003 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2004 // registered cell info, so return a NULL country instead.
2005 final long identity = Binder.clearCallingIdentity();
2006 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002007 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2008 // Get default phone in this case.
2009 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2010 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002011 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002012 // Todo: fix this when we can get the actual cellular network info when the device
2013 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002014 if (TelephonyManager.NETWORK_TYPE_IWLAN
2015 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2016 return "";
2017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002018 Phone phone = PhoneFactory.getPhone(phoneId);
2019 if (phone != null) {
2020 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002021 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002022 if (sst != null) {
2023 LocaleTracker lt = sst.getLocaleTracker();
2024 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002025 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2026 return lt.getCurrentCountry();
2027 } else if (emergencyNumberTracker != null) {
2028 return emergencyNumberTracker.getEmergencyCountryIso();
2029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002030 }
2031 }
2032 }
2033 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002034 } finally {
2035 Binder.restoreCallingIdentity(identity);
2036 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002037 }
2038
2039 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002041 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002042 }
2043
Sanket Padawe356d7632015-06-22 14:03:32 -07002044 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002045 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 mApp.enforceCallingOrSelfPermission(
2047 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002048
2049 final long identity = Binder.clearCallingIdentity();
2050 try {
2051 final Phone phone = getPhone(subId);
2052 if (phone != null) {
2053 phone.enableLocationUpdates();
2054 }
2055 } finally {
2056 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002057 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 }
2059
2060 @Override
2061 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002062 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002063 }
2064
Sanket Padawe356d7632015-06-22 14:03:32 -07002065 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002066 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067 mApp.enforceCallingOrSelfPermission(
2068 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002069
2070 final long identity = Binder.clearCallingIdentity();
2071 try {
2072 final Phone phone = getPhone(subId);
2073 if (phone != null) {
2074 phone.disableLocationUpdates();
2075 }
2076 } finally {
2077 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002078 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 }
2080
Nathan Harold31d7ff32018-10-15 20:20:30 -07002081 /**
2082 * Returns the target SDK version number for a given package name.
2083 *
Nathan Haroldec184742019-07-10 17:04:16 -07002084 * This call MUST be invoked before clearing the calling UID.
2085 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002086 * @return target SDK if the package is found or INT_MAX.
2087 */
2088 private int getTargetSdk(String packageName) {
2089 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002090 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002091 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002092 if (ai != null) return ai.targetSdkVersion;
2093 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002094 loge("Failed to get package info for pkg="
2095 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002096 }
2097 return Integer.MAX_VALUE;
2098 }
2099
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 @Override
2101 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002102 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2103 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002104 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2105 throw new SecurityException(
2106 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2107 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002108
Jordan Liu1617b712019-07-10 15:06:26 -07002109 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2111 return null;
2112 }
Svetoslav64fad262015-04-14 14:35:21 -07002113
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002114 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115
Nathan Haroldf180aac2018-06-01 18:43:55 -07002116 List<CellInfo> info = getAllCellInfo(callingPackage);
2117 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118
Nathan Haroldf180aac2018-06-01 18:43:55 -07002119 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2120 for (CellInfo ci : info) {
2121 if (ci instanceof CellInfoGsm) {
2122 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2123 } else if (ci instanceof CellInfoWcdma) {
2124 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002127 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 }
2129
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002130 private List<CellInfo> getCachedCellInfo() {
2131 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2132 for (Phone phone : PhoneFactory.getPhones()) {
2133 List<CellInfo> info = phone.getAllCellInfo();
2134 if (info != null) cellInfos.addAll(info);
2135 }
2136 return cellInfos;
2137 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138
2139 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002140 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002141 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002142 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002143
2144 LocationAccessPolicy.LocationPermissionResult locationResult =
2145 LocationAccessPolicy.checkLocationPermission(mApp,
2146 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2147 .setCallingPackage(callingPackage)
2148 .setCallingPid(Binder.getCallingPid())
2149 .setCallingUid(Binder.getCallingUid())
2150 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002151 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002152 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2153 .build());
2154 switch (locationResult) {
2155 case DENIED_HARD:
2156 throw new SecurityException("Not allowed to access cell info");
2157 case DENIED_SOFT:
2158 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 }
2160
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002161 final int targetSdk = getTargetSdk(callingPackage);
2162 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2163 return getCachedCellInfo();
2164 }
2165
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002166 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002167 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002168 final long identity = Binder.clearCallingIdentity();
2169 try {
2170 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2171 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002172 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002173 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002174 if (info != null) cellInfos.addAll(info);
2175 }
2176 return cellInfos;
2177 } finally {
2178 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 }
2180 }
2181
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002182 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002183 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2184 requestCellInfoUpdateInternal(
2185 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2186 }
2187
2188 @Override
2189 public void requestCellInfoUpdateWithWorkSource(
2190 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2191 enforceModifyPermission();
2192 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2193 }
2194
2195 private void requestCellInfoUpdateInternal(
2196 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002197 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002198 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002199
2200 LocationAccessPolicy.LocationPermissionResult locationResult =
2201 LocationAccessPolicy.checkLocationPermission(mApp,
2202 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2203 .setCallingPackage(callingPackage)
2204 .setCallingPid(Binder.getCallingPid())
2205 .setCallingUid(Binder.getCallingUid())
2206 .setMethod("requestCellInfoUpdate")
2207 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2208 .build());
2209 switch (locationResult) {
2210 case DENIED_HARD:
2211 throw new SecurityException("Not allowed to access cell info");
2212 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002213 try {
2214 cb.onCellInfo(new ArrayList<CellInfo>());
2215 } catch (RemoteException re) {
2216 // Drop without consequences
2217 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002218 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002219 }
2220
Nathan Harolda939a962019-05-09 10:13:47 -07002221
2222 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002223 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2224
2225 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2226 }
2227
2228 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002230 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002231 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002232
2233 final long identity = Binder.clearCallingIdentity();
2234 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002235 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002236 } finally {
2237 Binder.restoreCallingIdentity(identity);
2238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 }
2240
Shishir Agrawala9f32182016-04-12 12:00:16 -07002241 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002242 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002243 Phone phone = PhoneFactory.getPhone(slotIndex);
2244 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002245 return null;
2246 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002247 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002248 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2249 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002250 return null;
2251 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002252
2253 final long identity = Binder.clearCallingIdentity();
2254 try {
2255 return phone.getImei();
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
2258 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002259 }
2260
2261 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002262 public String getTypeAllocationCodeForSlot(int slotIndex) {
2263 Phone phone = PhoneFactory.getPhone(slotIndex);
2264 String tac = null;
2265 if (phone != null) {
2266 String imei = phone.getImei();
2267 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2268 }
2269 return tac;
2270 }
2271
2272 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002273 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002274 Phone phone = PhoneFactory.getPhone(slotIndex);
2275 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002276 return null;
2277 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002278
Jeff Davidson913390f2018-02-23 17:11:49 -08002279 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002280 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2281 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002282 return null;
2283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002284
2285 final long identity = Binder.clearCallingIdentity();
2286 try {
2287 return phone.getMeid();
2288 } finally {
2289 Binder.restoreCallingIdentity(identity);
2290 }
Jack Yu2af8d712017-03-15 17:14:14 -07002291 }
2292
2293 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002294 public String getManufacturerCodeForSlot(int slotIndex) {
2295 Phone phone = PhoneFactory.getPhone(slotIndex);
2296 String manufacturerCode = null;
2297 if (phone != null) {
2298 String meid = phone.getMeid();
2299 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2300 }
2301 return manufacturerCode;
2302 }
2303
2304 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002305 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002306 Phone phone = PhoneFactory.getPhone(slotIndex);
2307 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002308 return null;
2309 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002310 int subId = phone.getSubId();
2311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2312 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2313 return null;
2314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002315
2316 final long identity = Binder.clearCallingIdentity();
2317 try {
2318 return phone.getDeviceSvn();
2319 } finally {
2320 Binder.restoreCallingIdentity(identity);
2321 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002322 }
2323
fionaxu43304da2017-11-27 22:51:16 -08002324 @Override
2325 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326 final long identity = Binder.clearCallingIdentity();
2327 try {
2328 final Phone phone = getPhone(subId);
2329 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
2332 }
fionaxu43304da2017-11-27 22:51:16 -08002333 }
2334
2335 @Override
2336 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002337 final long identity = Binder.clearCallingIdentity();
2338 try {
2339 final Phone phone = getPhone(subId);
2340 return phone == null ? null : phone.getCarrierName();
2341 } finally {
2342 Binder.restoreCallingIdentity(identity);
2343 }
fionaxu43304da2017-11-27 22:51:16 -08002344 }
2345
calvinpanffe225e2018-11-01 19:43:06 +08002346 @Override
chen xu0026ca62019-03-06 15:28:50 -08002347 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 final Phone phone = getPhone(subId);
2351 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002352 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002353 } finally {
2354 Binder.restoreCallingIdentity(identity);
2355 }
2356 }
2357
2358 @Override
chen xu0026ca62019-03-06 15:28:50 -08002359 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002360 final long identity = Binder.clearCallingIdentity();
2361 try {
2362 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002363 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002364 } finally {
2365 Binder.restoreCallingIdentity(identity);
2366 }
2367 }
2368
chen xu651eec72018-11-11 19:03:44 -08002369 @Override
chen xu864e11c2018-12-06 22:10:03 -08002370 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2371 if (!isSubscriptionMccMnc) {
2372 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2373 }
chen xu651eec72018-11-11 19:03:44 -08002374 final Phone phone = PhoneFactory.getPhone(slotIndex);
2375 if (phone == null) {
2376 return TelephonyManager.UNKNOWN_CARRIER_ID;
2377 }
2378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2381 } finally {
2382 Binder.restoreCallingIdentity(identity);
2383 }
2384 }
2385
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 //
2387 // Internal helper methods.
2388 //
2389
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002390 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2392 *
2393 * @throws SecurityException if the caller does not have the required permission
2394 */
2395 private void enforceModifyPermission() {
2396 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2397 }
2398
2399 /**
2400 * Make sure the caller has the CALL_PHONE permission.
2401 *
2402 * @throws SecurityException if the caller does not have the required permission
2403 */
2404 private void enforceCallPermission() {
2405 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2406 }
2407
Stuart Scott8eef64f2015-04-08 15:13:54 -07002408 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002409 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002410 "ConnectivityService");
2411 }
2412
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413 private String createTelUrl(String number) {
2414 if (TextUtils.isEmpty(number)) {
2415 return null;
2416 }
2417
Jake Hambye994d462014-02-03 13:10:13 -08002418 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 }
2420
Ihab Awadf9e92732013-12-05 18:02:52 -08002421 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2423 }
2424
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002425 private static void logv(String msg) {
2426 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2427 }
2428
Ihab Awadf9e92732013-12-05 18:02:52 -08002429 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2431 }
2432
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002433 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002434 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002435 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002436 }
2437
Sanket Padawe356d7632015-06-22 14:03:32 -07002438 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002439 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440 final long identity = Binder.clearCallingIdentity();
2441 try {
2442 final Phone phone = PhoneFactory.getPhone(slotIndex);
2443 if (phone == null) {
2444 return PhoneConstants.PHONE_TYPE_NONE;
2445 } else {
2446 return phone.getPhoneType();
2447 }
2448 } finally {
2449 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 }
2452
2453 /**
2454 * Returns the CDMA ERI icon index to display
2455 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002456 @Override
2457 public int getCdmaEriIconIndex(String callingPackage) {
2458 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002459 }
2460
Sanket Padawe356d7632015-06-22 14:03:32 -07002461 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002462 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002464 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002465 return -1;
2466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002467
2468 final long identity = Binder.clearCallingIdentity();
2469 try {
2470 final Phone phone = getPhone(subId);
2471 if (phone != null) {
2472 return phone.getCdmaEriIconIndex();
2473 } else {
2474 return -1;
2475 }
2476 } finally {
2477 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 }
2480
2481 /**
2482 * Returns the CDMA ERI icon mode,
2483 * 0 - ON
2484 * 1 - FLASHING
2485 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002486 @Override
2487 public int getCdmaEriIconMode(String callingPackage) {
2488 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002489 }
2490
Sanket Padawe356d7632015-06-22 14:03:32 -07002491 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002492 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002493 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002494 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002495 return -1;
2496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002497
2498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 final Phone phone = getPhone(subId);
2501 if (phone != null) {
2502 return phone.getCdmaEriIconMode();
2503 } else {
2504 return -1;
2505 }
2506 } finally {
2507 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002509 }
2510
2511 /**
2512 * Returns the CDMA ERI text,
2513 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002514 @Override
2515 public String getCdmaEriText(String callingPackage) {
2516 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002517 }
2518
Sanket Padawe356d7632015-06-22 14:03:32 -07002519 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002520 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002521 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002522 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002523 return null;
2524 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002525
2526 final long identity = Binder.clearCallingIdentity();
2527 try {
2528 final Phone phone = getPhone(subId);
2529 if (phone != null) {
2530 return phone.getCdmaEriText();
2531 } else {
2532 return null;
2533 }
2534 } finally {
2535 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002536 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537 }
2538
2539 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002540 * Returns the CDMA MDN.
2541 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002542 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002543 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2545 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002546
2547 final long identity = Binder.clearCallingIdentity();
2548 try {
2549 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002550 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002551 return phone.getLine1Number();
2552 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002553 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554 return null;
2555 }
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002558 }
2559 }
2560
2561 /**
2562 * Returns the CDMA MIN.
2563 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002564 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002565 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2567 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 final Phone phone = getPhone(subId);
2572 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2573 return phone.getCdmaMin();
2574 } else {
2575 return null;
2576 }
2577 } finally {
2578 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002579 }
2580 }
2581
Hall Liud892bec2018-11-30 14:51:45 -08002582 @Override
2583 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2584 INumberVerificationCallback callback, String callingPackage) {
2585 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2586 != PERMISSION_GRANTED) {
2587 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2588 }
2589 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2590
2591 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2592 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2593 throw new SecurityException("Calling package must be configured in the device config");
2594 }
2595
2596 if (range == null) {
2597 throw new NullPointerException("Range must be non-null");
2598 }
2599
2600 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002601 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002602
2603 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2604 }
2605
Junda Liuca05d5d2014-08-14 22:36:34 -07002606 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002607 * Returns true if CDMA provisioning needs to run.
2608 */
2609 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002610 final long identity = Binder.clearCallingIdentity();
2611 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002612 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 } finally {
2614 Binder.restoreCallingIdentity(identity);
2615 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616 }
2617
2618 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002619 * Sets the voice mail number of a given subId.
2620 */
2621 @Override
2622 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002623 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624
2625 final long identity = Binder.clearCallingIdentity();
2626 try {
2627 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2628 new Pair<String, String>(alphaTag, number), new Integer(subId));
2629 return success;
2630 } finally {
2631 Binder.restoreCallingIdentity(identity);
2632 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002633 }
2634
Ta-wei Yen87c49842016-05-13 21:19:52 -07002635 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002636 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2637 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002638 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002639 if (!TextUtils.equals(callingPackage, systemDialer)) {
2640 throw new SecurityException("caller must be system dialer");
2641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642
2643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2646 if (phoneAccountHandle == null) {
2647 return null;
2648 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002649 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650 } finally {
2651 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002652 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002653 }
2654
2655 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002656 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002657 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002658 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002659 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002660 return null;
2661 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002663 final long identity = Binder.clearCallingIdentity();
2664 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002665 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002666 } finally {
2667 Binder.restoreCallingIdentity(identity);
2668 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002669 }
2670
2671 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002672 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2673 VisualVoicemailSmsFilterSettings settings) {
2674 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002675
2676 final long identity = Binder.clearCallingIdentity();
2677 try {
2678 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002679 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680 } finally {
2681 Binder.restoreCallingIdentity(identity);
2682 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002683 }
2684
2685 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002686 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2687 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688
2689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002692 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693 } finally {
2694 Binder.restoreCallingIdentity(identity);
2695 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002696 }
2697
2698 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002699 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2700 String callingPackage, int subId) {
2701 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002706 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707 } finally {
2708 Binder.restoreCallingIdentity(identity);
2709 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002710 }
2711
2712 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002713 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002714 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715
2716 final long identity = Binder.clearCallingIdentity();
2717 try {
2718 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002719 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 } finally {
2721 Binder.restoreCallingIdentity(identity);
2722 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002723 }
2724
2725 @Override
2726 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2727 String number, int port, String text, PendingIntent sentIntent) {
2728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002729 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002730 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002731 SmsController smsController = PhoneFactory.getSmsController();
2732 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2733 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002734 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002735
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002736 /**
fionaxu0152e512016-11-14 13:36:14 -08002737 * Sets the voice activation state of a given subId.
2738 */
2739 @Override
2740 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2742 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002743
2744 final long identity = Binder.clearCallingIdentity();
2745 try {
2746 final Phone phone = getPhone(subId);
2747 if (phone != null) {
2748 phone.setVoiceActivationState(activationState);
2749 } else {
2750 loge("setVoiceActivationState fails with invalid subId: " + subId);
2751 }
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002754 }
2755 }
2756
2757 /**
2758 * Sets the data activation state of a given subId.
2759 */
2760 @Override
2761 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2763 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 final Phone phone = getPhone(subId);
2768 if (phone != null) {
2769 phone.setDataActivationState(activationState);
2770 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002771 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 }
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002775 }
2776 }
2777
2778 /**
2779 * Returns the voice activation state of a given subId.
2780 */
2781 @Override
2782 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002783 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002784
fionaxu0152e512016-11-14 13:36:14 -08002785 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 if (phone != null) {
2789 return phone.getVoiceActivationState();
2790 } else {
2791 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2792 }
2793 } finally {
2794 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002795 }
2796 }
2797
2798 /**
2799 * Returns the data activation state of a given subId.
2800 */
2801 @Override
2802 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002803 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804
fionaxu0152e512016-11-14 13:36:14 -08002805 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 if (phone != null) {
2809 return phone.getDataActivationState();
2810 } else {
2811 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2812 }
2813 } finally {
2814 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002815 }
2816 }
2817
2818 /**
Wink Saville36469e72014-06-11 15:17:00 -07002819 * Returns the unread count of voicemails for a subId
2820 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002821 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002822 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2823 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2824 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2825 return 0;
2826 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 final Phone phone = getPhone(subId);
2830 if (phone != null) {
2831 return phone.getVoiceMessageCount();
2832 } else {
2833 return 0;
2834 }
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002838 }
2839
2840 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002841 * returns true, if the device is in a state where both voice and data
2842 * are supported simultaneously. This can change based on location or network condition.
2843 */
2844 @Override
2845 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846 final long identity = Binder.clearCallingIdentity();
2847 try {
2848 final Phone phone = getPhone(subId);
2849 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2850 } finally {
2851 Binder.restoreCallingIdentity(identity);
2852 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002853 }
2854
2855 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002856 * Send the dialer code if called from the current default dialer or the caller has
2857 * carrier privilege.
2858 * @param inputCode The dialer code to send
2859 */
2860 @Override
2861 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002862 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002863 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002864 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2865 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002866 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002867 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2868 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002869 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002870
2871 final long identity = Binder.clearCallingIdentity();
2872 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002873 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002874 } finally {
2875 Binder.restoreCallingIdentity(identity);
2876 }
fionaxu235cc5e2017-03-06 22:25:57 -08002877 }
2878
Pengquan Menga1bb6272018-09-06 09:59:22 -07002879 @Override
2880 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002881 if (!isActiveSubscription(subId)) {
2882 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2883 }
2884
Pengquan Menga1bb6272018-09-06 09:59:22 -07002885 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2886 }
2887
Brad Ebinger35c841c2018-10-01 10:40:55 -07002888 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002889 public boolean isInEmergencySmsMode() {
2890 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 for (Phone phone : PhoneFactory.getPhones()) {
2894 if (phone.isInEmergencySmsMode()) {
2895 return true;
2896 }
2897 }
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
2900 }
2901 return false;
2902 }
2903
2904 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002905 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2906 throws RemoteException {
2907 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002908 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2909 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2910 "IMS not available on device.");
2911 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002912 final long token = Binder.clearCallingIdentity();
2913 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002914 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002915 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002916 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002917 } catch (ImsException e) {
2918 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002919 } finally {
2920 Binder.restoreCallingIdentity(token);
2921 }
2922 }
2923
2924 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002925 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2926 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2928 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2929 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002930 final long token = Binder.clearCallingIdentity();
2931 try {
2932 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2933 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2934 .removeRegistrationCallbackForSubscription(c, subId);
2935 } catch (ImsException e) {
2936 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2937 + "is inactive, ignoring unregister.");
2938 // If the subscription is no longer active, just return, since the callback
2939 // will already have been removed internally.
2940 } finally {
2941 Binder.restoreCallingIdentity(token);
2942 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002943 }
2944
Brad Ebinger774ba362019-10-22 17:36:18 -07002945 /**
2946 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2947 */
2948 @Override
2949 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2950 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2951 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2952 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2953 "IMS not available on device.");
2954 }
2955 final long token = Binder.clearCallingIdentity();
2956 try {
2957 Phone phone = getPhone(subId);
2958 if (phone == null) {
2959 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2960 + subId + "'");
2961 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
2962 }
2963 phone.getImsRegistrationState(regState -> {
2964 try {
2965 consumer.accept((regState == null)
2966 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
2967 } catch (RemoteException e) {
2968 // Ignore if the remote process is no longer available to call back.
2969 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
2970 }
2971 });
2972 } finally {
2973 Binder.restoreCallingIdentity(token);
2974 }
2975 }
2976
2977 /**
2978 * Get the transport type for the IMS service registration state.
2979 */
2980 @Override
2981 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
2982 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
2983 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2984 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2985 "IMS not available on device.");
2986 }
2987 final long token = Binder.clearCallingIdentity();
2988 try {
2989 Phone phone = getPhone(subId);
2990 if (phone == null) {
2991 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2992 + subId + "'");
2993 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
2994 }
2995 phone.getImsRegistrationTech(regTech -> {
2996 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
2997 int regTechConverted = (regTech == null)
2998 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
2999 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3000 regTechConverted);
3001 try {
3002 consumer.accept(regTechConverted);
3003 } catch (RemoteException e) {
3004 // Ignore if the remote process is no longer available to call back.
3005 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3006 }
3007 });
3008 } finally {
3009 Binder.restoreCallingIdentity(token);
3010 }
3011 }
3012
Brad Ebinger35c841c2018-10-01 10:40:55 -07003013 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003014 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3015 throws RemoteException {
3016 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003017 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3018 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3019 "IMS not available on device.");
3020 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003021 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3022 final long token = Binder.clearCallingIdentity();
3023 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003024 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003025 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003026 } catch (ImsException e) {
3027 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003028 } finally {
3029 Binder.restoreCallingIdentity(token);
3030 }
3031 }
3032
3033 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003034 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3035 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003036 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3037 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3038 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003039
3040 final long token = Binder.clearCallingIdentity();
3041 try {
3042 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3043 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003044 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003045 } catch (ImsException e) {
3046 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3047 + "is inactive, ignoring unregister.");
3048 // If the subscription is no longer active, just return, since the callback
3049 // will already have been removed internally.
3050 } finally {
3051 Binder.restoreCallingIdentity(token);
3052 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003053 }
3054
3055 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003056 public boolean isCapable(int subId, int capability, int regTech) {
3057 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003058 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3059 final long token = Binder.clearCallingIdentity();
3060 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003061 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003062 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003063 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003064 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3065 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003066 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003067 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3068 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003069 } finally {
3070 Binder.restoreCallingIdentity(token);
3071 }
3072 }
3073
3074 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003075 public boolean isAvailable(int subId, int capability, int regTech) {
3076 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003077 final long token = Binder.clearCallingIdentity();
3078 try {
3079 Phone phone = getPhone(subId);
3080 if (phone == null) return false;
3081 return phone.isImsCapabilityAvailable(capability, regTech);
3082 } finally {
3083 Binder.restoreCallingIdentity(token);
3084 }
3085 }
3086
Brad Ebinger77b832e2019-10-17 17:03:22 -07003087 /**
3088 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3089 * subscription.
3090 * @param subId The subscription to use to check the configuration.
3091 * @param callback The callback that will be used to send the result.
3092 * @param capability The MmTelFeature capability that will be used to send the result.
3093 * @param transportType The transport type of the MmTelFeature capability.
3094 */
3095 @Override
3096 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3097 int transportType) {
3098 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3099 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3100 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3101 "IMS not available on device.");
3102 }
3103 final long token = Binder.clearCallingIdentity();
3104 try {
3105 int slotId = getSlotIndex(subId);
3106 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3107 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3108 + subId + "'");
3109 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3110 }
3111 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3112 transportType, aBoolean -> {
3113 try {
3114 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3115 } catch (RemoteException e) {
3116 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3117 + "running. Ignore");
3118 }
3119 });
3120 } finally {
3121 Binder.restoreCallingIdentity(token);
3122 }
3123 }
3124
Brad Ebinger35c841c2018-10-01 10:40:55 -07003125 @Override
3126 public boolean isAdvancedCallingSettingEnabled(int subId) {
3127 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3128 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3129 final long token = Binder.clearCallingIdentity();
3130 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003131 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003132 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003133 } catch (ImsException e) {
3134 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003135 } finally {
3136 Binder.restoreCallingIdentity(token);
3137 }
3138 }
3139
3140 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003141 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003143 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003144 final long identity = Binder.clearCallingIdentity();
3145 try {
3146 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003147 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003148 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003149 } catch (ImsException e) {
3150 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003151 } finally {
3152 Binder.restoreCallingIdentity(identity);
3153 }
3154 }
3155
3156 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003157 public boolean isVtSettingEnabled(int subId) {
3158 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003159 final long identity = Binder.clearCallingIdentity();
3160 try {
3161 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003162 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3163 } catch (ImsException e) {
3164 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003165 } finally {
3166 Binder.restoreCallingIdentity(identity);
3167 }
3168 }
3169
3170 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003171 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003173 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003174 final long identity = Binder.clearCallingIdentity();
3175 try {
3176 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003177 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003178 } catch (ImsException e) {
3179 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003180 } finally {
3181 Binder.restoreCallingIdentity(identity);
3182 }
3183 }
3184
3185 @Override
3186 public boolean isVoWiFiSettingEnabled(int subId) {
3187 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3188 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 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003192 getSlotIndexOrException(subId)).isWfcEnabledByUser();
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 Ebinger1c162042019-02-21 14:49:10 -08003201 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003203 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003207 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003208 } catch (ImsException e) {
3209 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003210 } finally {
3211 Binder.restoreCallingIdentity(identity);
3212 }
3213 }
3214
3215 @Override
3216 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3217 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3218 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 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003223 } catch (ImsException e) {
3224 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003225 } finally {
3226 Binder.restoreCallingIdentity(identity);
3227 }
3228 }
3229
3230 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003231 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003233 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003234 final long identity = Binder.clearCallingIdentity();
3235 try {
3236 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003237 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003238 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003239 } catch (ImsException e) {
3240 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 } finally {
3242 Binder.restoreCallingIdentity(identity);
3243 }
3244 }
3245
3246 @Override
3247 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3249 "setVoWiFiNonPersistent");
3250 final long identity = Binder.clearCallingIdentity();
3251 try {
3252 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003253 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003254 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003255 } catch (ImsException e) {
3256 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003257 } finally {
3258 Binder.restoreCallingIdentity(identity);
3259 }
3260 }
3261
3262 @Override
3263 public int getVoWiFiModeSetting(int subId) {
3264 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3265 final long identity = Binder.clearCallingIdentity();
3266 try {
3267 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003268 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003269 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003270 } catch (ImsException e) {
3271 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003272 } finally {
3273 Binder.restoreCallingIdentity(identity);
3274 }
3275 }
3276
3277 @Override
3278 public void setVoWiFiModeSetting(int subId, int mode) {
3279 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3280 "setVoWiFiModeSetting");
3281 final long identity = Binder.clearCallingIdentity();
3282 try {
3283 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003284 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003285 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003286 } catch (ImsException e) {
3287 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003288 } finally {
3289 Binder.restoreCallingIdentity(identity);
3290 }
3291 }
3292
3293 @Override
3294 public int getVoWiFiRoamingModeSetting(int subId) {
3295 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003299 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003300 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003301 } catch (ImsException e) {
3302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003303 } finally {
3304 Binder.restoreCallingIdentity(identity);
3305 }
3306 }
3307
3308 @Override
3309 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3311 "setVoWiFiRoamingModeSetting");
3312 final long identity = Binder.clearCallingIdentity();
3313 try {
3314 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003315 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003316 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003317 } catch (ImsException e) {
3318 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003319 } finally {
3320 Binder.restoreCallingIdentity(identity);
3321 }
3322 }
3323
3324 @Override
3325 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3327 "setRttCapabilityEnabled");
3328 final long identity = Binder.clearCallingIdentity();
3329 try {
3330 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003331 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3332 } catch (ImsException e) {
3333 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003334 } finally {
3335 Binder.restoreCallingIdentity(identity);
3336 }
3337 }
3338
3339 @Override
3340 public boolean isTtyOverVolteEnabled(int subId) {
3341 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003345 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003346 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003347 } catch (ImsException e) {
3348 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 } finally {
3350 Binder.restoreCallingIdentity(identity);
3351 }
3352 }
3353
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003354 @Override
3355 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3356 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003360 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003361 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003362 } catch (ImsException e) {
3363 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003364 } finally {
3365 Binder.restoreCallingIdentity(identity);
3366 }
3367 }
3368
3369 @Override
3370 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3371 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3372 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003373 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3374 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3375 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003376 try {
3377 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003378 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003379 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003380 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003381 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3382 + "is inactive, ignoring unregister.");
3383 // If the subscription is no longer active, just return, since the callback will already
3384 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003385 } finally {
3386 Binder.restoreCallingIdentity(identity);
3387 }
3388 }
3389
3390 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003391 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3392 boolean isProvisioned) {
3393 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3394 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3395 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3396 }
3397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3398 "setProvisioningStatusForCapability");
3399 final long identity = Binder.clearCallingIdentity();
3400 try {
3401 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3402 Phone phone = getPhone(subId);
3403 if (phone == null) {
3404 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3405 + subId);
3406 return;
3407 }
3408 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3409 return;
3410 }
3411
3412 // this capability requires provisioning, route to the correct API.
3413 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3414 switch (capability) {
3415 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3416 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3417 ims.setVolteProvisioned(isProvisioned);
3418 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3419 ims.setWfcProvisioned(isProvisioned);
3420 }
3421 break;
3422 }
3423 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3424 // There is currently no difference in VT provisioning type.
3425 ims.setVtProvisioned(isProvisioned);
3426 break;
3427 }
3428 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3429 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3430 // change the capability of the feature instead if needed.
3431 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3432 == isProvisioned) {
3433 // No change in provisioning.
3434 return;
3435 }
3436 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3437 try {
3438 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003439 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003440 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3441 + ", Exception" + e.getMessage());
3442 }
3443 break;
3444 }
3445 default: {
3446 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3447 + capability + "', which does not require provisioning.");
3448 }
3449 }
3450
3451 } finally {
3452 Binder.restoreCallingIdentity(identity);
3453 }
3454 }
3455
3456 @Override
3457 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3458 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3459 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3460 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3461 }
3462 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3463 final long identity = Binder.clearCallingIdentity();
3464 try {
3465 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3466 Phone phone = getPhone(subId);
3467 if (phone == null) {
3468 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3469 + subId);
3470 // We will fail with "true" as the provisioning status because this is the default
3471 // if we do not require provisioning.
3472 return true;
3473 }
3474
3475 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3476 return true;
3477 }
3478
3479 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3480 switch (capability) {
3481 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3482 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3483 return ims.isVolteProvisionedOnDevice();
3484 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3485 return ims.isWfcProvisionedOnDevice();
3486 }
3487 // This should never happen, since we are checking tech above to make sure it
3488 // is either LTE or IWLAN.
3489 throw new IllegalArgumentException("Invalid radio technology for voice "
3490 + "capability.");
3491 }
3492 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3493 // There is currently no difference in VT provisioning type.
3494 return ims.isVtProvisionedOnDevice();
3495 }
3496 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3497 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3498 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3499 }
3500 default: {
3501 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3502 + capability + "', which does not require provisioning.");
3503 }
3504 }
3505
3506 } finally {
3507 Binder.restoreCallingIdentity(identity);
3508 }
3509 }
3510
3511 @Override
3512 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3513 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3514 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3515 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3516 }
3517 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3518 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3519 return (provisionedBits & capability) > 0;
3520 }
3521
3522 @Override
3523 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3524 boolean isProvisioned) {
3525 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3526 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3527 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3528 }
3529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3530 "setProvisioningStatusForCapability");
3531 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3532 // If the current provisioning status for capability already matches isProvisioned,
3533 // do nothing.
3534 if (((provisionedBits & capability) > 0) == isProvisioned) {
3535 return;
3536 }
3537 if (isProvisioned) {
3538 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3539 } else {
3540 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3541 }
3542 }
3543
3544 /**
3545 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3546 * technology. The bitfield should mirror the bitfield defined by
3547 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3548 */
3549 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3550 String key = getMmTelProvisioningKey(subId, tech);
3551 // Default is no capabilities are provisioned.
3552 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3553 }
3554
3555 /**
3556 * Sets the MmTel capability provisioning bitfield (defined by
3557 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3558 * technology specified.
3559 *
3560 * Note: This is a synchronous command and should not be called on UI thread.
3561 */
3562 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3563 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3564 String key = getMmTelProvisioningKey(subId, tech);
3565 editor.putInt(key, newField);
3566 editor.commit();
3567 }
3568
3569 private static String getMmTelProvisioningKey(int subId, int tech) {
3570 // resulting key is provision_ims_mmtel_{subId}_{tech}
3571 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3572 }
3573
3574 /**
3575 * Query CarrierConfig to see if the specified capability requires provisioning for the
3576 * carrier associated with the subscription id.
3577 */
3578 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3579 int capability) {
3580 CarrierConfigManager configManager = new CarrierConfigManager(context);
3581 PersistableBundle c = configManager.getConfigForSubId(subId);
3582 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003583 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003584 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3585 false);
3586 boolean requireVoiceVtProvisioning = c.getBoolean(
3587 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3588
3589 // First check to make sure that the capability requires provisioning.
3590 switch (capability) {
3591 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3592 // intentional fallthrough
3593 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3594 if (requireVoiceVtProvisioning) {
3595 // Voice and Video requires provisioning
3596 return true;
3597 }
3598 break;
3599 }
3600 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3601 if (requireUtProvisioning) {
3602 // UT requires provisioning
3603 return true;
3604 }
3605 break;
3606 }
3607 }
3608 return false;
3609 }
3610
3611 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003612 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003613 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3614 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3615 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003616 enforceReadPrivilegedPermission("getImsProvisioningInt");
3617 final long identity = Binder.clearCallingIdentity();
3618 try {
3619 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003620 int slotId = getSlotIndex(subId);
3621 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3622 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3623 + subId + "' for key:" + key);
3624 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3625 }
3626 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003627 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003628 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3629 + subId + "' for key:" + key);
3630 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003631 } finally {
3632 Binder.restoreCallingIdentity(identity);
3633 }
3634 }
3635
3636 @Override
3637 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003638 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3639 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3640 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003641 enforceReadPrivilegedPermission("getImsProvisioningString");
3642 final long identity = Binder.clearCallingIdentity();
3643 try {
3644 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003645 int slotId = getSlotIndex(subId);
3646 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3647 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3648 + subId + "' for key:" + key);
3649 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3650 }
3651 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003652 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003653 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3654 + subId + "' for key:" + key);
3655 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003656 } finally {
3657 Binder.restoreCallingIdentity(identity);
3658 }
3659 }
3660
3661 @Override
3662 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003663 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3664 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3665 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3667 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003671 int slotId = getSlotIndex(subId);
3672 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3673 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3674 + subId + "' for key:" + key);
3675 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3676 }
3677 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003678 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003679 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3680 + "' for key:" + key);
3681 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003682 } finally {
3683 Binder.restoreCallingIdentity(identity);
3684 }
3685 }
3686
3687 @Override
3688 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003689 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3690 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3691 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3693 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003694 final long identity = Binder.clearCallingIdentity();
3695 try {
3696 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003697 int slotId = getSlotIndex(subId);
3698 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3699 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3700 + subId + "' for key:" + key);
3701 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3702 }
3703 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003704 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003705 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3706 + "' for key:" + key);
3707 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003708 } finally {
3709 Binder.restoreCallingIdentity(identity);
3710 }
3711 }
3712
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003713 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 int slotId = SubscriptionManager.getSlotIndex(subId);
3715 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003716 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3717 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003718 }
3719 return slotId;
3720 }
3721
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003722 private int getSlotIndex(int subId) {
3723 int slotId = SubscriptionManager.getSlotIndex(subId);
3724 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3725 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3726 }
3727 return slotId;
3728 }
3729
Wink Saville36469e72014-06-11 15:17:00 -07003730 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003731 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003732 */
3733 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003734 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003735 final int targetSdk = getTargetSdk(callingPackage);
3736 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3737 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3738 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003739 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3740 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003741 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3742 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003744 final long identity = Binder.clearCallingIdentity();
3745 try {
3746 final Phone phone = getPhone(subId);
3747 if (phone != null) {
3748 return phone.getServiceState().getDataNetworkType();
3749 } else {
3750 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3751 }
3752 } finally {
3753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003755 }
3756
3757 /**
3758 * Returns the data network type
3759 */
3760 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003761 public int getDataNetworkType(String callingPackage) {
3762 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003763 }
3764
3765 /**
3766 * Returns the data network type for a subId
3767 */
3768 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003769 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003770 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003771 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003772 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3773 }
3774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003775 final long identity = Binder.clearCallingIdentity();
3776 try {
3777 final Phone phone = getPhone(subId);
3778 if (phone != null) {
3779 return phone.getServiceState().getDataNetworkType();
3780 } else {
3781 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3782 }
3783 } finally {
3784 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003786 }
3787
3788 /**
Wink Saville36469e72014-06-11 15:17:00 -07003789 * Returns the Voice network type for a subId
3790 */
3791 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003792 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003793 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003794 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003795 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3796 }
3797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 final Phone phone = getPhone(subId);
3801 if (phone != null) {
3802 return phone.getServiceState().getVoiceNetworkType();
3803 } else {
3804 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3805 }
3806 } finally {
3807 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003809 }
3810
3811 /**
3812 * @return true if a ICC card is present
3813 */
3814 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003815 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003816 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3817 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003818 }
3819
3820 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003821 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003822 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003823 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003824 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825 final long identity = Binder.clearCallingIdentity();
3826 try {
3827 final Phone phone = PhoneFactory.getPhone(slotIndex);
3828 if (phone != null) {
3829 return phone.getIccCard().hasIccCard();
3830 } else {
3831 return false;
3832 }
3833 } finally {
3834 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003835 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003836 }
3837
3838 /**
3839 * Return if the current radio is LTE on CDMA. This
3840 * is a tri-state return value as for a period of time
3841 * the mode may be unknown.
3842 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003843 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003844 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003845 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003846 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003847 @Override
3848 public int getLteOnCdmaMode(String callingPackage) {
3849 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003850 }
3851
Sanket Padawe356d7632015-06-22 14:03:32 -07003852 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003853 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003854 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003855 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003856 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3857 }
3858
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003859 final long identity = Binder.clearCallingIdentity();
3860 try {
3861 final Phone phone = getPhone(subId);
3862 if (phone == null) {
3863 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3864 } else {
3865 return phone.getLteOnCdmaMode();
3866 }
3867 } finally {
3868 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003869 }
Wink Saville36469e72014-06-11 15:17:00 -07003870 }
3871
Wink Saville36469e72014-06-11 15:17:00 -07003872 /**
3873 * {@hide}
3874 * Returns Default subId, 0 in the case of single standby.
3875 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003876 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003877 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003878 }
3879
Shishir Agrawala9f32182016-04-12 12:00:16 -07003880 private int getSlotForDefaultSubscription() {
3881 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3882 }
3883
Wink Savilleb564aae2014-10-23 10:18:09 -07003884 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003885 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003886 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003887
Pengquan Menge92a50d2018-09-21 15:54:48 -07003888 private boolean isActiveSubscription(int subId) {
3889 return mSubscriptionController.isActiveSubId(subId);
3890 }
3891
Ihab Awadf2177b72013-11-25 13:33:23 -08003892 /**
3893 * @see android.telephony.TelephonyManager.WifiCallingChoices
3894 */
3895 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896 final long identity = Binder.clearCallingIdentity();
3897 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003898 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003899 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3900 getWhenToMakeWifiCallsDefaultPreference());
3901 } finally {
3902 Binder.restoreCallingIdentity(identity);
3903 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003904 }
3905
3906 /**
3907 * @see android.telephony.TelephonyManager.WifiCallingChoices
3908 */
3909 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910 final long identity = Binder.clearCallingIdentity();
3911 try {
3912 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003913 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003914 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3915 } finally {
3916 Binder.restoreCallingIdentity(identity);
3917 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003918 }
3919
Sailesh Nepald1e68152013-12-12 19:08:02 -08003920 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003921 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003922 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003923 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003924
Jordan Liu4c733742019-02-28 12:03:40 -08003925 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3926 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3927 if (phoneId == -1) {
3928 throw new IllegalArgumentException("Given slot index: " + slotIndex
3929 + " does not correspond to an active phone");
3930 }
3931 return PhoneFactory.getPhone(phoneId);
3932 }
3933
Shishir Agrawal566b7612013-10-28 14:41:00 -07003934 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003935 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3936 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3938 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003939 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003940 if (DBG) {
3941 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3942 }
3943 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3944 p2);
3945 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003946
Jordan Liu4c733742019-02-28 12:03:40 -08003947
3948 @Override
3949 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3950 int slotIndex, String callingPackage, String aid, int p2) {
3951 enforceModifyPermission();
3952 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3953 if (DBG) {
3954 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3955 }
3956 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3957 callingPackage, aid, p2);
3958 }
3959
3960 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3961 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003962 final long identity = Binder.clearCallingIdentity();
3963 try {
3964 if (TextUtils.equals(ISDR_AID, aid)) {
3965 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003966 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3967 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003968 if (bestComponent == null
3969 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3970 loge("The calling package is not allowed to access ISD-R.");
3971 throw new SecurityException(
3972 "The calling package is not allowed to access ISD-R.");
3973 }
Derek Tan740e1672017-06-27 14:56:27 -07003974 }
Derek Tan740e1672017-06-27 14:56:27 -07003975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003976 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003977 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3978 null /* workSource */);
3979 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003980 return response;
3981 } finally {
3982 Binder.restoreCallingIdentity(identity);
3983 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003984 }
3985
3986 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003987 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3989 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003990 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3991 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3992 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003993
Jordan Liu4c733742019-02-28 12:03:40 -08003994 @Override
3995 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3996 enforceModifyPermission();
3997 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3998 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3999 channel);
4000 }
4001
4002 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004003 final long identity = Binder.clearCallingIdentity();
4004 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005 if (channel < 0) {
4006 return false;
4007 }
Jordan Liu4c733742019-02-28 12:03:40 -08004008 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4009 null /* workSource */);
4010 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004011 return success;
4012 } finally {
4013 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004014 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004015 }
4016
4017 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004018 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004019 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004020 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4021 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004022 if (DBG) {
4023 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4024 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4025 + p3 + " data=" + data);
4026 }
4027 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4028 command, p1, p2, p3, data);
4029 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004030
Jordan Liu4c733742019-02-28 12:03:40 -08004031 @Override
4032 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4033 int command, int p1, int p2, int p3, String data) {
4034 enforceModifyPermission();
4035 if (DBG) {
4036 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4037 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4038 + p3 + " data=" + data);
4039 }
4040 return iccTransmitApduLogicalChannelWithPermission(
4041 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4042 data);
4043 }
4044
4045 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4046 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004047 final long identity = Binder.clearCallingIdentity();
4048 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004049 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 return "";
4051 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004054 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4055 null /* workSource */);
4056 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004057
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058 // Append the returned status code to the end of the response payload.
4059 String s = Integer.toHexString(
4060 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4061 if (response.payload != null) {
4062 s = IccUtils.bytesToHexString(response.payload) + s;
4063 }
4064 return s;
4065 } finally {
4066 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004067 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004068 }
Jake Hambye994d462014-02-03 13:10:13 -08004069
Evan Charltonc66da362014-05-16 14:06:40 -07004070 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004071 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4072 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4074 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004075 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004076 if (DBG) {
4077 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4078 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4079 }
4080 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4081 cla, command, p1, p2, p3, data);
4082 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004083
Jordan Liu4c733742019-02-28 12:03:40 -08004084 @Override
4085 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4086 int command, int p1, int p2, int p3, String data) {
4087 enforceModifyPermission();
4088 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4089 if (DBG) {
4090 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4091 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4092 + " data=" + data);
4093 }
4094
4095 return iccTransmitApduBasicChannelWithPermission(
4096 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4097 p2, p3, data);
4098 }
4099
4100 // open APDU basic channel assuming the caller has sufficient permissions
4101 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4102 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4106 && TextUtils.equals(ISDR_AID, data)) {
4107 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004108 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4109 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004110 if (bestComponent == null
4111 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4112 loge("The calling package is not allowed to select ISD-R.");
4113 throw new SecurityException(
4114 "The calling package is not allowed to select ISD-R.");
4115 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004116 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004118 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004119 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4120 null /* workSource */);
4121 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123 // Append the returned status code to the end of the response payload.
4124 String s = Integer.toHexString(
4125 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4126 if (response.payload != null) {
4127 s = IccUtils.bytesToHexString(response.payload) + s;
4128 }
4129 return s;
4130 } finally {
4131 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004132 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004133 }
4134
4135 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004136 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004137 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4139 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004140
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004141 final long identity = Binder.clearCallingIdentity();
4142 try {
4143 if (DBG) {
4144 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4145 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4146 }
4147
4148 IccIoResult response =
4149 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4150 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4151 subId);
4152
4153 if (DBG) {
4154 log("Exchange SIM_IO [R]" + response);
4155 }
4156
4157 byte[] result = null;
4158 int length = 2;
4159 if (response.payload != null) {
4160 length = 2 + response.payload.length;
4161 result = new byte[length];
4162 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4163 } else {
4164 result = new byte[length];
4165 }
4166
4167 result[length - 1] = (byte) response.sw2;
4168 result[length - 2] = (byte) response.sw1;
4169 return result;
4170 } finally {
4171 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004172 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004173 }
4174
Nathan Haroldb3014052017-01-25 15:57:32 -08004175 /**
4176 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4177 * on a particular subscription
4178 */
sqianb6e41952018-03-12 14:54:01 -07004179 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4181 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4182 return null;
4183 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004184
4185 final long identity = Binder.clearCallingIdentity();
4186 try {
4187 if (appType != TelephonyManager.APPTYPE_USIM
4188 && appType != TelephonyManager.APPTYPE_SIM) {
4189 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4190 return null;
4191 }
4192 Object response = sendRequest(
4193 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4194 if (response instanceof String[]) {
4195 return (String[]) response;
4196 }
yincheng zhaod698b842019-09-06 17:06:54 -07004197 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004198 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004199 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004200 } finally {
4201 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004202 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004203 }
4204
yincheng zhaod698b842019-09-06 17:06:54 -07004205 /**
4206 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4207 * subscription.
4208 *
4209 * @param subId the id of the subscription.
4210 * @param appType the uicc app type, must be USIM or SIM.
4211 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4212 * @param callingPackage the op Package name.
4213 * @return number of fplmns that is successfully written to the SIM.
4214 */
4215 public int setForbiddenPlmns(
4216 int subId, int appType, List<String> fplmns, String callingPackage) {
4217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4218 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4219 if (DBG) logv("no permissions for setForbiddenplmns");
4220 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4221 }
4222 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4223 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4224 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4225 }
4226 if (fplmns == null) {
4227 throw new IllegalArgumentException("Fplmn List provided is null");
4228 }
4229 for (String fplmn : fplmns) {
4230 if (!CellIdentity.isValidPlmn(fplmn)) {
4231 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4232 }
4233 }
4234 final long identity = Binder.clearCallingIdentity();
4235 try {
4236 Object response = sendRequest(
4237 CMD_SET_FORBIDDEN_PLMNS,
4238 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4239 subId);
4240 return (int) response;
4241 } finally {
4242 Binder.restoreCallingIdentity(identity);
4243 }
4244 }
4245
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004246 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004247 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4249 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004251 final long identity = Binder.clearCallingIdentity();
4252 try {
4253 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4254 if (response.payload == null) {
4255 return "";
4256 }
Evan Charltonc66da362014-05-16 14:06:40 -07004257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004258 // Append the returned status code to the end of the response payload.
4259 String s = Integer.toHexString(
4260 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4261 s = IccUtils.bytesToHexString(response.payload) + s;
4262 return s;
4263 } finally {
4264 Binder.restoreCallingIdentity(identity);
4265 }
Evan Charltonc66da362014-05-16 14:06:40 -07004266 }
4267
Jake Hambye994d462014-02-03 13:10:13 -08004268 /**
4269 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4270 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4271 *
4272 * @param itemID the ID of the item to read
4273 * @return the NV item as a String, or null on error.
4274 */
4275 @Override
4276 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004277 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4279 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004280
4281 final long identity = Binder.clearCallingIdentity();
4282 try {
4283 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004284 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004285 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4286 return value;
4287 } finally {
4288 Binder.restoreCallingIdentity(identity);
4289 }
Jake Hambye994d462014-02-03 13:10:13 -08004290 }
4291
4292 /**
4293 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4294 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4295 *
4296 * @param itemID the ID of the item to read
4297 * @param itemValue the value to write, as a String
4298 * @return true on success; false on any failure
4299 */
4300 @Override
4301 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004302 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4304 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004305
4306 final long identity = Binder.clearCallingIdentity();
4307 try {
4308 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4309 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004310 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004311 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4312 return success;
4313 } finally {
4314 Binder.restoreCallingIdentity(identity);
4315 }
Jake Hambye994d462014-02-03 13:10:13 -08004316 }
4317
4318 /**
4319 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4320 * Used for device configuration by some CDMA operators.
4321 *
4322 * @param preferredRoamingList byte array containing the new PRL
4323 * @return true on success; false on any failure
4324 */
4325 @Override
4326 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4328 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004329
4330 final long identity = Binder.clearCallingIdentity();
4331 try {
4332 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4333 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4334 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4335 return success;
4336 } finally {
4337 Binder.restoreCallingIdentity(identity);
4338 }
Jake Hambye994d462014-02-03 13:10:13 -08004339 }
4340
4341 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004342 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004343 * Used for device configuration by some CDMA operators.
4344 *
chen xu6dac5ab2018-10-26 17:39:23 -07004345 * @param slotIndex - device slot.
4346 *
Jake Hambye994d462014-02-03 13:10:13 -08004347 * @return true on success; false on any failure
4348 */
4349 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004350 public boolean resetModemConfig(int slotIndex) {
4351 Phone phone = PhoneFactory.getPhone(slotIndex);
4352 if (phone != null) {
4353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4354 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004355
chen xu6dac5ab2018-10-26 17:39:23 -07004356 final long identity = Binder.clearCallingIdentity();
4357 try {
4358 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4359 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4360 return success;
4361 } finally {
4362 Binder.restoreCallingIdentity(identity);
4363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004364 }
chen xu6dac5ab2018-10-26 17:39:23 -07004365 return false;
4366 }
4367
4368 /**
4369 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4370 *
4371 * @param slotIndex - device slot.
4372 *
4373 * @return true on success; false on any failure
4374 */
4375 @Override
4376 public boolean rebootModem(int slotIndex) {
4377 Phone phone = PhoneFactory.getPhone(slotIndex);
4378 if (phone != null) {
4379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4380 mApp, phone.getSubId(), "rebootModem");
4381
4382 final long identity = Binder.clearCallingIdentity();
4383 try {
4384 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4385 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4386 return success;
4387 } finally {
4388 Binder.restoreCallingIdentity(identity);
4389 }
4390 }
4391 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004392 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004393
Svet Ganovb320e182015-04-16 12:30:10 -07004394 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004395 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004397 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004398 return new String[0];
4399 }
4400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 final long identity = Binder.clearCallingIdentity();
4402 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004403 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 } finally {
4405 Binder.restoreCallingIdentity(identity);
4406 }
Wink Saville36469e72014-06-11 15:17:00 -07004407 }
4408
Brad Ebinger51f743a2017-01-23 13:50:20 -08004409 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004410 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4411 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004412 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004413 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004414 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004415
4416 final long identity = Binder.clearCallingIdentity();
4417 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004418 ImsResolver resolver = PhoneFactory.getImsResolver();
4419 if (resolver == null) {
4420 // may happen if the device does not support IMS.
4421 return;
4422 }
4423 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004424 } finally {
4425 Binder.restoreCallingIdentity(identity);
4426 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004427 }
4428
4429 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004430 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4431 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004432 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004433 public void disableIms(int slotId) {
4434 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004435
4436 final long identity = Binder.clearCallingIdentity();
4437 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004438 ImsResolver resolver = PhoneFactory.getImsResolver();
4439 if (resolver == null) {
4440 // may happen if the device does not support IMS.
4441 return;
4442 }
4443 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 } finally {
4445 Binder.restoreCallingIdentity(identity);
4446 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004447 }
4448
4449 /**
4450 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4451 * feature or {@link null} if the service is not available. If the feature is available, the
4452 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4453 */
4454 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004455 IImsServiceFeatureCallback callback) {
4456 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457
4458 final long identity = Binder.clearCallingIdentity();
4459 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004460 ImsResolver resolver = PhoneFactory.getImsResolver();
4461 if (resolver == null) {
4462 // may happen if the device does not support IMS.
4463 return null;
4464 }
4465 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004469 }
4470
4471 /**
4472 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4473 * feature during emergency calling or {@link null} if the service is not available. If the
4474 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4475 * listener for feature updates.
4476 */
4477 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4478 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004479
4480 final long identity = Binder.clearCallingIdentity();
4481 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004482 ImsResolver resolver = PhoneFactory.getImsResolver();
4483 if (resolver == null) {
4484 // may happen if the device does not support IMS.
4485 return null;
4486 }
4487 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004488 } finally {
4489 Binder.restoreCallingIdentity(identity);
4490 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004491 }
4492
Brad Ebinger5f64b052017-12-14 14:26:15 -08004493 /**
4494 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004495 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004496 */
4497 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4498 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499
4500 final long identity = Binder.clearCallingIdentity();
4501 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004502 ImsResolver resolver = PhoneFactory.getImsResolver();
4503 if (resolver == null) {
4504 // may happen if the device does not support IMS.
4505 return null;
4506 }
4507 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508 } finally {
4509 Binder.restoreCallingIdentity(identity);
4510 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004511 }
4512
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004513 /**
4514 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004515 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004516 */
4517 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4518 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519
4520 final long identity = Binder.clearCallingIdentity();
4521 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004522 ImsResolver resolver = PhoneFactory.getImsResolver();
4523 if (resolver == null) {
4524 // may happen if the device does not support IMS.
4525 return null;
4526 }
4527 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528 } finally {
4529 Binder.restoreCallingIdentity(identity);
4530 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004531 }
4532
Brad Ebinger884c07b2018-02-15 16:17:40 -08004533 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004534 * Sets the ImsService Package Name that Telephony will bind to.
4535 *
4536 * @param slotId the slot ID that the ImsService should bind for.
4537 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4538 * ImsService is the device default ImsService.
4539 * @param packageName The package name of the application that contains the ImsService to bind
4540 * to.
4541 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4542 * @hide
4543 */
4544 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004545 int[] subIds = SubscriptionManager.getSubId(slotId);
4546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4547 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4548 "setImsService");
4549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004550 final long identity = Binder.clearCallingIdentity();
4551 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004552 ImsResolver resolver = PhoneFactory.getImsResolver();
4553 if (resolver == null) {
4554 // may happen if the device does not support IMS.
4555 return false;
4556 }
4557 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4558 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559 } finally {
4560 Binder.restoreCallingIdentity(identity);
4561 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004562 }
4563
4564 /**
4565 * Return the ImsService configuration.
4566 *
4567 * @param slotId The slot that the ImsService is associated with.
4568 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4569 * the device default.
4570 * @return the package name of the ImsService configuration.
4571 */
4572 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004573 int[] subIds = SubscriptionManager.getSubId(slotId);
4574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4575 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4576 "getImsService");
4577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004578 final long identity = Binder.clearCallingIdentity();
4579 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004580 ImsResolver resolver = PhoneFactory.getImsResolver();
4581 if (resolver == null) {
4582 // may happen if the device does not support IMS.
4583 return "";
4584 }
4585 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004586 } finally {
4587 Binder.restoreCallingIdentity(identity);
4588 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004589 }
4590
Brad Ebinger77b832e2019-10-17 17:03:22 -07004591 /**
4592 * Get the MmTelFeature state associated with the requested subscription id.
4593 * @param subId The subscription that the MmTelFeature is associated with.
4594 * @param callback A callback with an integer containing the
4595 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4596 */
4597 @Override
4598 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4599 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4600 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4601 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4602 "IMS not available on device.");
4603 }
4604 final long token = Binder.clearCallingIdentity();
4605 try {
4606 int slotId = getSlotIndex(subId);
4607 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4608 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4609 + subId + "'");
4610 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4611 }
4612 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4613 try {
4614 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4615 } catch (RemoteException e) {
4616 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4617 + "Ignore");
4618 }
4619 });
4620 } finally {
4621 Binder.restoreCallingIdentity(token);
4622 }
4623 }
4624
Wink Saville36469e72014-06-11 15:17:00 -07004625 public void setImsRegistrationState(boolean registered) {
4626 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004627
4628 final long identity = Binder.clearCallingIdentity();
4629 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004630 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004631 } finally {
4632 Binder.restoreCallingIdentity(identity);
4633 }
Wink Saville36469e72014-06-11 15:17:00 -07004634 }
4635
4636 /**
Stuart Scott54788802015-03-30 13:18:01 -07004637 * Set the network selection mode to automatic.
4638 *
4639 */
4640 @Override
4641 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4643 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004644
Pengquan Menge92a50d2018-09-21 15:54:48 -07004645 if (!isActiveSubscription(subId)) {
4646 return;
4647 }
4648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004649 final long identity = Binder.clearCallingIdentity();
4650 try {
4651 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4652 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4653 } finally {
4654 Binder.restoreCallingIdentity(identity);
4655 }
Stuart Scott54788802015-03-30 13:18:01 -07004656 }
4657
Pengquan Mengea84e042018-09-20 14:57:26 -07004658 /**
4659 * Ask the radio to connect to the input network and change selection mode to manual.
4660 *
4661 * @param subId the id of the subscription.
4662 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4663 * the operator to attach to.
4664 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4665 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4666 * normal network selection next time.
4667 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004668 */
4669 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004670 public boolean setNetworkSelectionModeManual(
4671 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4673 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004674
4675 if (!isActiveSubscription(subId)) {
4676 return false;
4677 }
4678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004679 final long identity = Binder.clearCallingIdentity();
4680 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004681 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004682 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004683 if (DBG) {
4684 log("setNetworkSelectionModeManual: subId: " + subId
4685 + " operator: " + operatorInfo);
4686 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004687 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4688 } finally {
4689 Binder.restoreCallingIdentity(identity);
4690 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004691 }
4692
4693 /**
4694 * Scans for available networks.
4695 */
4696 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004697 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4699 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004700 LocationAccessPolicy.LocationPermissionResult locationResult =
4701 LocationAccessPolicy.checkLocationPermission(mApp,
4702 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4703 .setCallingPackage(callingPackage)
4704 .setCallingPid(Binder.getCallingPid())
4705 .setCallingUid(Binder.getCallingUid())
4706 .setMethod("getCellNetworkScanResults")
4707 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4708 .build());
4709 switch (locationResult) {
4710 case DENIED_HARD:
4711 throw new SecurityException("Not allowed to access scan results -- location");
4712 case DENIED_SOFT:
4713 return null;
4714 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004715
Pengquan Menga1bb6272018-09-06 09:59:22 -07004716 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004717 try {
4718 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004719 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004720 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004721 } finally {
4722 Binder.restoreCallingIdentity(identity);
4723 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004724 }
4725
4726 /**
yinxub1bed742017-04-17 11:45:04 -07004727 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004728 *
yinxub1bed742017-04-17 11:45:04 -07004729 * @param subId id of the subscription
4730 * @param request contains the radio access networks with bands/channels to scan
4731 * @param messenger callback messenger for scan results or errors
4732 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004733 * @return the id of the requested scan which can be used to stop the scan.
4734 */
4735 @Override
4736 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004737 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4739 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004740 LocationAccessPolicy.LocationPermissionResult locationResult =
4741 LocationAccessPolicy.checkLocationPermission(mApp,
4742 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4743 .setCallingPackage(callingPackage)
4744 .setCallingPid(Binder.getCallingPid())
4745 .setCallingUid(Binder.getCallingUid())
4746 .setMethod("requestNetworkScan")
4747 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4748 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004749 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004750 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004751 if (e != null) {
4752 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4753 throw e;
4754 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004755 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004756 return TelephonyScanManager.INVALID_SCAN_ID;
4757 }
4758 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 }
Hall Liu912dfd32019-04-25 14:02:26 -07004760 int callingUid = Binder.getCallingUid();
4761 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004762 final long identity = Binder.clearCallingIdentity();
4763 try {
4764 return mNetworkScanRequestTracker.startNetworkScan(
4765 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004766 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004767 } finally {
4768 Binder.restoreCallingIdentity(identity);
4769 }
yinxu504e1392017-04-12 16:03:22 -07004770 }
4771
Hall Liub2ac8ef2019-02-28 15:56:23 -08004772 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004773 NetworkScanRequest request, int subId) {
4774 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4775 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4776 boolean hasNetworkScanPermission =
4777 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4778 == PERMISSION_GRANTED;
4779
4780 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4781 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4782 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004783 }
4784
4785 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4786 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004787 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4788 return new SecurityException("Specific channels must not be"
4789 + " scanned without location access.");
4790 }
4791 }
4792 }
4793
Hall Liub2ac8ef2019-02-28 15:56:23 -08004794 return null;
4795 }
4796
yinxu504e1392017-04-12 16:03:22 -07004797 /**
4798 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004799 *
4800 * @param subId id of the subscription
4801 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004802 */
4803 @Override
4804 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4806 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004807
Hall Liu912dfd32019-04-25 14:02:26 -07004808 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004809 final long identity = Binder.clearCallingIdentity();
4810 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004811 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004812 } finally {
4813 Binder.restoreCallingIdentity(identity);
4814 }
yinxu504e1392017-04-12 16:03:22 -07004815 }
4816
4817 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004818 * Get the calculated preferred network type.
4819 * Used for debugging incorrect network type.
4820 *
4821 * @return the preferred network type, defined in RILConstants.java.
4822 */
4823 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004824 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004825 final Phone defaultPhone = getDefaultPhone();
4826 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4827 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004828 return RILConstants.PREFERRED_NETWORK_MODE;
4829 }
4830
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004831 final long identity = Binder.clearCallingIdentity();
4832 try {
4833 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004834 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004835 } finally {
4836 Binder.restoreCallingIdentity(identity);
4837 }
Junda Liu84d15a22014-07-02 11:21:04 -07004838 }
4839
4840 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004841 * Get the preferred network type.
4842 * Used for device configuration by some CDMA operators.
4843 *
4844 * @return the preferred network type, defined in RILConstants.java.
4845 */
4846 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004847 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004848 TelephonyPermissions
4849 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4850 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004851
4852 final long identity = Binder.clearCallingIdentity();
4853 try {
4854 if (DBG) log("getPreferredNetworkType");
4855 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4856 int networkType = (result != null ? result[0] : -1);
4857 if (DBG) log("getPreferredNetworkType: " + networkType);
4858 return networkType;
4859 } finally {
4860 Binder.restoreCallingIdentity(identity);
4861 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004862 }
4863
4864 /**
4865 * Set the preferred network type.
4866 * Used for device configuration by some CDMA operators.
4867 *
4868 * @param networkType the preferred network type, defined in RILConstants.java.
4869 * @return true on success; false on any failure.
4870 */
4871 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004872 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4874 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004875
4876 final long identity = Binder.clearCallingIdentity();
4877 try {
4878 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4879 Boolean success = (Boolean) sendRequest(
4880 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4881 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4882 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004883 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004884 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4885 }
4886 return success;
4887 } finally {
4888 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004889 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004890 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004891
4892 /**
Miaoa84611c2019-03-15 09:21:10 +08004893 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004894 *
Miaoa84611c2019-03-15 09:21:10 +08004895 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004896 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004897 * @hide
4898 */
4899 @Override
Miaoa84611c2019-03-15 09:21:10 +08004900 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004901 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004903 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904 try {
Miaoa84611c2019-03-15 09:21:10 +08004905 if (phone != null) {
4906 return phone.hasMatchedTetherApnSetting();
4907 } else {
4908 return false;
4909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 } finally {
4911 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004912 }
Junda Liu475951f2014-11-07 16:45:03 -08004913 }
4914
4915 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004916 * Set mobile data enabled
4917 * Used by the user through settings etc to turn on/off mobile data
4918 *
4919 * @param enable {@code true} turn turn data on, else {@code false}
4920 */
4921 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004922 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4924 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004925
4926 final long identity = Binder.clearCallingIdentity();
4927 try {
4928 int phoneId = mSubscriptionController.getPhoneId(subId);
4929 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4930 Phone phone = PhoneFactory.getPhone(phoneId);
4931 if (phone != null) {
4932 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004933 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004935 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 }
4937 } finally {
4938 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004939 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004940 }
4941
4942 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004943 * Get the user enabled state of Mobile Data.
4944 *
4945 * TODO: remove and use isUserDataEnabled.
4946 * This can't be removed now because some vendor codes
4947 * calls through ITelephony directly while they should
4948 * use TelephonyManager.
4949 *
4950 * @return true on enabled
4951 */
4952 @Override
4953 public boolean getDataEnabled(int subId) {
4954 return isUserDataEnabled(subId);
4955 }
4956
4957 /**
4958 * Get whether mobile data is enabled per user setting.
4959 *
4960 * There are other factors deciding whether mobile data is actually enabled, but they are
4961 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004962 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004963 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004964 *
4965 * @return {@code true} if data is enabled else {@code false}
4966 */
4967 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004968 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004969 try {
4970 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4971 null);
4972 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4974 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004975 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004976
4977 final long identity = Binder.clearCallingIdentity();
4978 try {
4979 int phoneId = mSubscriptionController.getPhoneId(subId);
4980 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4981 Phone phone = PhoneFactory.getPhone(phoneId);
4982 if (phone != null) {
4983 boolean retVal = phone.isUserDataEnabled();
4984 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4985 return retVal;
4986 } else {
4987 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4988 return false;
4989 }
4990 } finally {
4991 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004992 }
4993 }
4994
4995 /**
4996 * Get whether mobile data is enabled.
4997 *
4998 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4999 * whether mobile data is actually enabled.
5000 *
5001 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5002 *
5003 * @return {@code true} if data is enabled else {@code false}
5004 */
5005 @Override
5006 public boolean isDataEnabled(int subId) {
5007 try {
5008 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5009 null);
5010 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5012 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005013 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014
5015 final long identity = Binder.clearCallingIdentity();
5016 try {
5017 int phoneId = mSubscriptionController.getPhoneId(subId);
5018 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5019 Phone phone = PhoneFactory.getPhone(phoneId);
5020 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005021 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5023 return retVal;
5024 } else {
5025 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5026 return false;
5027 }
5028 } finally {
5029 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005030 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005031 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005032
5033 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005034 public int getCarrierPrivilegeStatus(int subId) {
5035 final Phone phone = getPhone(subId);
5036 if (phone == null) {
5037 loge("getCarrierPrivilegeStatus: Invalid subId");
5038 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5039 }
5040 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005041 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005042 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005043 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5044 }
5045 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005046 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005047 }
Junda Liu29340342014-07-10 15:23:27 -07005048
5049 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005050 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5051 final Phone phone = getPhone(subId);
5052 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005053 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005054 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5055 }
5056 UiccProfile profile =
5057 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5058 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005059 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005060 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5061 }
5062 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
5063 }
5064
5065 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005066 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5067 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005068 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005069 }
5070
5071 int phoneId = SubscriptionManager.getPhoneId(subId);
5072 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005073 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005074 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005075 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5076 }
chen xuf7e9fe82019-05-09 19:31:02 -07005077
5078 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005079 }
5080
5081 @Override
5082 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005083 if (TextUtils.isEmpty(pkgName))
5084 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005085 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5086 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5087 UiccCard card = UiccController.getInstance().getUiccCard(i);
5088 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005089 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005090 continue;
5091 }
5092
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005093 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005094 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5095 break;
5096 }
5097 }
5098
5099 return result;
Junda Liu29340342014-07-10 15:23:27 -07005100 }
Derek Tan89e89d42014-07-08 17:00:10 -07005101
5102 @Override
Junda Liue64de782015-04-16 17:19:16 -07005103 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5104 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5105 loge("phoneId " + phoneId + " is not valid.");
5106 return null;
5107 }
5108 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005109 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005110 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005111 return null ;
5112 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005113 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005114 }
5115
Amith Yamasani6e118872016-02-19 12:53:51 -08005116 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005117 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005118 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005119 List<String> privilegedPackages = new ArrayList<>();
5120 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005121 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5122 // has UICC in that slot.
5123 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005124 if (card.hasCarrierPrivilegeRules()) {
5125 if (packages == null) {
5126 // Only check packages in user 0 for now
5127 packages = pm.getInstalledPackagesAsUser(
5128 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07005129 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
5130 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005131 }
5132 for (int p = packages.size() - 1; p >= 0; p--) {
5133 PackageInfo pkgInfo = packages.get(p);
5134 if (pkgInfo != null && pkgInfo.packageName != null
5135 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005136 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005137 privilegedPackages.add(pkgInfo.packageName);
5138 }
5139 }
5140 }
5141 }
5142 return privilegedPackages;
5143 }
5144
chen xuf7e9fe82019-05-09 19:31:02 -07005145 @Override
5146 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5147 List<String> privilegedPackages = new ArrayList<>();
5148 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5149 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5150 }
5151 return privilegedPackages;
5152 }
5153
Wink Savilleb564aae2014-10-23 10:18:09 -07005154 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005155 final Phone phone = getPhone(subId);
5156 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005157 if (card == null) {
5158 loge("getIccId: No UICC");
5159 return null;
5160 }
5161 String iccId = card.getIccId();
5162 if (TextUtils.isEmpty(iccId)) {
5163 loge("getIccId: ICC ID is null or empty.");
5164 return null;
5165 }
5166 return iccId;
5167 }
5168
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005169 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005170 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5171 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005172 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5173 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005174
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005175 final long identity = Binder.clearCallingIdentity();
5176 try {
5177 final String iccId = getIccId(subId);
5178 final Phone phone = getPhone(subId);
5179 if (phone == null) {
5180 return false;
5181 }
5182 final String subscriberId = phone.getSubscriberId();
5183
5184 if (DBG_MERGE) {
5185 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5186 + subscriberId + " to " + number);
5187 }
5188
5189 if (TextUtils.isEmpty(iccId)) {
5190 return false;
5191 }
5192
5193 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5194
5195 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5196 if (alphaTag == null) {
5197 editor.remove(alphaTagPrefKey);
5198 } else {
5199 editor.putString(alphaTagPrefKey, alphaTag);
5200 }
5201
5202 // Record both the line number and IMSI for this ICCID, since we need to
5203 // track all merged IMSIs based on line number
5204 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5205 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5206 if (number == null) {
5207 editor.remove(numberPrefKey);
5208 editor.remove(subscriberPrefKey);
5209 } else {
5210 editor.putString(numberPrefKey, number);
5211 editor.putString(subscriberPrefKey, subscriberId);
5212 }
5213
5214 editor.commit();
5215 return true;
5216 } finally {
5217 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005218 }
Derek Tan7226c842014-07-02 17:42:23 -07005219 }
5220
5221 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005222 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005223 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005225 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005226 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005227 return null;
5228 }
Derek Tan97ebb422014-09-05 16:55:38 -07005229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230 final long identity = Binder.clearCallingIdentity();
5231 try {
5232 String iccId = getIccId(subId);
5233 if (iccId != null) {
5234 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5235 if (DBG_MERGE) {
5236 log("getLine1NumberForDisplay returning "
5237 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5238 }
5239 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005240 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5242 return null;
5243 } finally {
5244 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005245 }
Derek Tan7226c842014-07-02 17:42:23 -07005246 }
5247
5248 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005249 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005250 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005251 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005252 return null;
5253 }
Derek Tan97ebb422014-09-05 16:55:38 -07005254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 final long identity = Binder.clearCallingIdentity();
5256 try {
5257 String iccId = getIccId(subId);
5258 if (iccId != null) {
5259 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5260 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5261 }
5262 return null;
5263 } finally {
5264 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005265 }
Derek Tan7226c842014-07-02 17:42:23 -07005266 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005267
5268 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005269 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005270 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5271 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005273 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5274 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005275 return null;
5276 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005277
Jordan Liub49b04b2019-05-06 14:45:15 -07005278 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5279 // the process, where TelephonyManager was instantiated.
5280 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005281 final long identity = Binder.clearCallingIdentity();
5282 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005283 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 final TelephonyManager tele = TelephonyManager.from(context);
5285 final SubscriptionManager sub = SubscriptionManager.from(context);
5286
5287 // Figure out what subscribers are currently active
5288 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289
Jordan Liub49b04b2019-05-06 14:45:15 -07005290 // Only consider subs which match the current subId
5291 // This logic can be simplified. See b/131189269 for progress.
5292 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005293 activeSubscriberIds.add(tele.getSubscriberId(subId));
5294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005295
5296 // First pass, find a number override for an active subscriber
5297 String mergeNumber = null;
5298 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5299 for (String key : prefs.keySet()) {
5300 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5301 final String subscriberId = (String) prefs.get(key);
5302 if (activeSubscriberIds.contains(subscriberId)) {
5303 final String iccId = key.substring(
5304 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5305 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5306 mergeNumber = (String) prefs.get(numberKey);
5307 if (DBG_MERGE) {
5308 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5309 + " for active subscriber " + subscriberId);
5310 }
5311 if (!TextUtils.isEmpty(mergeNumber)) {
5312 break;
5313 }
5314 }
5315 }
5316 }
5317
5318 // Shortcut when no active merged subscribers
5319 if (TextUtils.isEmpty(mergeNumber)) {
5320 return null;
5321 }
5322
5323 // Second pass, find all subscribers under that line override
5324 final ArraySet<String> result = new ArraySet<>();
5325 for (String key : prefs.keySet()) {
5326 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5327 final String number = (String) prefs.get(key);
5328 if (mergeNumber.equals(number)) {
5329 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5330 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5331 final String subscriberId = (String) prefs.get(subscriberKey);
5332 if (!TextUtils.isEmpty(subscriberId)) {
5333 result.add(subscriberId);
5334 }
5335 }
5336 }
5337 }
5338
5339 final String[] resultArray = result.toArray(new String[result.size()]);
5340 Arrays.sort(resultArray);
5341 if (DBG_MERGE) {
5342 Slog.d(LOG_TAG,
5343 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5344 }
5345 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005346 } finally {
5347 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005348 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005349 }
5350
5351 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005352 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5353 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5354
5355 final long identity = Binder.clearCallingIdentity();
5356 try {
5357 final TelephonyManager telephonyManager = mApp.getSystemService(
5358 TelephonyManager.class);
5359 String subscriberId = telephonyManager.getSubscriberId(subId);
5360 if (subscriberId == null) {
5361 if (DBG) {
5362 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5363 + subId);
5364 }
5365 return null;
5366 }
5367
5368 final SubscriptionInfo info = SubscriptionController.getInstance()
5369 .getSubscriptionInfo(subId);
5370 final ParcelUuid groupUuid = info.getGroupUuid();
5371 // If it doesn't belong to any group, return just subscriberId of itself.
5372 if (groupUuid == null) {
5373 return new String[]{subscriberId};
5374 }
5375
5376 // Get all subscriberIds from the group.
5377 final List<String> mergedSubscriberIds = new ArrayList<>();
5378 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5379 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5380 for (SubscriptionInfo subInfo : groupInfos) {
5381 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5382 if (subscriberId != null) {
5383 mergedSubscriberIds.add(subscriberId);
5384 }
5385 }
5386
5387 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5388 } finally {
5389 Binder.restoreCallingIdentity(identity);
5390
5391 }
5392 }
5393
5394 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005395 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005396 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5397 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398
5399 final long identity = Binder.clearCallingIdentity();
5400 try {
5401 final Phone phone = getPhone(subId);
5402 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5403 } finally {
5404 Binder.restoreCallingIdentity(identity);
5405 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005406 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005407
5408 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005409 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005410 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5411 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005412 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413
5414 final long identity = Binder.clearCallingIdentity();
5415 try {
5416 final Phone phone = getPhone(subId);
5417 if (phone == null) {
5418 return false;
5419 }
5420 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5421 cdmaNonRoamingList);
5422 } finally {
5423 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005424 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005425 }
5426
5427 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005428 @Deprecated
5429 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5430 enforceModifyPermission();
5431
5432 int returnValue = 0;
5433 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005434 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005435 if(result.exception == null) {
5436 if (result.result != null) {
5437 byte[] responseData = (byte[])(result.result);
5438 if(responseData.length > oemResp.length) {
5439 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5440 responseData.length + "bytes. Buffer Size is " +
5441 oemResp.length + "bytes.");
5442 }
5443 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5444 returnValue = responseData.length;
5445 }
5446 } else {
5447 CommandException ex = (CommandException) result.exception;
5448 returnValue = ex.getCommandError().ordinal();
5449 if(returnValue > 0) returnValue *= -1;
5450 }
5451 } catch (RuntimeException e) {
5452 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5453 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5454 if(returnValue > 0) returnValue *= -1;
5455 }
5456
5457 return returnValue;
5458 }
5459
5460 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005461 public void setRadioCapability(RadioAccessFamily[] rafs) {
5462 try {
5463 ProxyController.getInstance().setRadioCapability(rafs);
5464 } catch (RuntimeException e) {
5465 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5466 }
5467 }
5468
5469 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005470 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005471 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005472 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005473 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005474 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 final long identity = Binder.clearCallingIdentity();
5477 try {
chen xub97461a2018-10-26 14:17:57 -07005478 TelephonyPermissions
5479 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5480 mApp, phone.getSubId(), "getRadioAccessFamily");
5481 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005482 } finally {
5483 Binder.restoreCallingIdentity(identity);
5484 }
chen xub97461a2018-10-26 14:17:57 -07005485 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005486 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005487
5488 @Override
5489 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005490 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005491 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492
5493 final long identity = Binder.clearCallingIdentity();
5494 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005495 ImsManager.getInstance(defaultPhone.getContext(),
5496 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005497 } finally {
5498 Binder.restoreCallingIdentity(identity);
5499 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005500 }
5501
5502 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005503 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005504 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005505 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005506 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005507 return false;
5508 }
Svet Ganovb320e182015-04-16 12:30:10 -07005509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 final long identity = Binder.clearCallingIdentity();
5511 try {
5512 // Check the user preference and the system-level IMS setting. Even if the user has
5513 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5514 // In the long run, we may instead need to check if there exists a connection service
5515 // which can support video calling.
5516 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005517 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518 return imsManager.isVtEnabledByPlatform()
5519 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5520 && imsManager.isVtEnabledByUser();
5521 } finally {
5522 Binder.restoreCallingIdentity(identity);
5523 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005524 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005525
Andrew Leea1239f22015-03-02 17:44:07 -08005526 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5528 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5529 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5530 return false;
5531 }
5532
5533 final long identity = Binder.clearCallingIdentity();
5534 try {
5535 CarrierConfigManager configManager =
5536 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005537 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005538 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5539 } finally {
5540 Binder.restoreCallingIdentity(identity);
5541 }
Andrew Leea1239f22015-03-02 17:44:07 -08005542 }
5543
5544 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545 public boolean isWorldPhone(int subId, String callingPackage) {
5546 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5547 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5548 return false;
5549 }
5550
5551 final long identity = Binder.clearCallingIdentity();
5552 try {
5553 CarrierConfigManager configManager =
5554 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005555 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5557 } finally {
5558 Binder.restoreCallingIdentity(identity);
5559 }
Andrew Leea1239f22015-03-02 17:44:07 -08005560 }
5561
Andrew Lee9431b832015-03-09 18:46:45 -07005562 @Override
5563 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005564 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005565 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005566 }
5567
5568 @Override
5569 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570 final long identity = Binder.clearCallingIdentity();
5571 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005572 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 } finally {
5574 Binder.restoreCallingIdentity(identity);
5575 }
Andrew Lee9431b832015-03-09 18:46:45 -07005576 }
5577
Hall Liuf6668912018-10-31 17:05:23 -07005578 /**
5579 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5580 * support for the feature and device firmware support.
5581 *
5582 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5583 */
5584 @Override
5585 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005587 final Phone phone = getPhone(subscriptionId);
5588 if (phone == null) {
5589 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5590 return false;
5591 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005593 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5595 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005596 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005597 return isCarrierSupported && isDeviceSupported;
5598 } finally {
5599 Binder.restoreCallingIdentity(identity);
5600 }
Hall Liu98187582018-01-22 19:15:32 -08005601 }
5602
Hall Liuf6668912018-10-31 17:05:23 -07005603 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005604 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5605 * RTT setting, will return true if the device and carrier both support RTT.
5606 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005607 */
5608 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609 final long identity = Binder.clearCallingIdentity();
5610 try {
Hall Liu6a06be62019-07-23 18:39:00 -07005611 boolean isRttSupported = isRttSupported(subscriptionId);
5612 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005613 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liu6a06be62019-07-23 18:39:00 -07005614 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5615 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5616 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617 } finally {
5618 Binder.restoreCallingIdentity(identity);
5619 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005620 }
5621
Sanket Padawe7310cc72015-01-14 09:53:20 -08005622 /**
5623 * Returns the unique device ID of phone, for example, the IMEI for
5624 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5625 *
5626 * <p>Requires Permission:
5627 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5628 */
5629 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005630 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005631 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005632 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005633 return null;
5634 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005635 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005636 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5637 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005638 return null;
5639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640
5641 final long identity = Binder.clearCallingIdentity();
5642 try {
5643 return phone.getDeviceId();
5644 } finally {
5645 Binder.restoreCallingIdentity(identity);
5646 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005647 }
5648
Ping Sunc67b7c22016-03-02 19:16:45 +08005649 /**
5650 * {@hide}
5651 * Returns the IMS Registration Status on a particular subid
5652 *
5653 * @param subId
5654 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005655 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005656 Phone phone = getPhone(subId);
5657 if (phone != null) {
5658 return phone.isImsRegistered();
5659 } else {
5660 return false;
5661 }
5662 }
5663
Santos Cordon7a1885b2015-02-03 11:15:19 -08005664 @Override
5665 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 final long identity = Binder.clearCallingIdentity();
5667 try {
5668 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5669 } finally {
5670 Binder.restoreCallingIdentity(identity);
5671 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005672 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005673
Tyler Gunnf70ed162019-04-03 15:28:53 -07005674 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005675 public int getSubIdForPhoneAccountHandle(
5676 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5677 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5678 callingPackage, "getSubIdForPhoneAccountHandle")) {
5679 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5680 }
5681 final long identity = Binder.clearCallingIdentity();
5682 try {
5683 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
5687 }
5688
5689 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005690 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5691 final long identity = Binder.clearCallingIdentity();
5692 try {
5693 Phone phone = getPhone(subscriptionId);
5694 if (phone == null) {
5695 return null;
5696 }
5697 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
5701 }
5702
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005703 /**
5704 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005705 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005706 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707 final long identity = Binder.clearCallingIdentity();
5708 try {
5709 Phone phone = getPhone(subId);
5710 if (phone != null) {
5711 return phone.isWifiCallingEnabled();
5712 } else {
5713 return false;
5714 }
5715 } finally {
5716 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005717 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005718 }
5719
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005720 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005721 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005722 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005723 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 final long identity = Binder.clearCallingIdentity();
5725 try {
5726 Phone phone = getPhone(subId);
5727 if (phone != null) {
5728 return phone.isVideoEnabled();
5729 } else {
5730 return false;
5731 }
5732 } finally {
5733 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005734 }
5735 }
5736
5737 /**
5738 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5739 * defined in {@link ImsRegistrationImplBase}.
5740 */
5741 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 final long identity = Binder.clearCallingIdentity();
5743 try {
5744 Phone phone = getPhone(subId);
5745 if (phone != null) {
5746 return phone.getImsRegistrationTech();
5747 } else {
5748 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5749 }
5750 } finally {
5751 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005752 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005753 }
5754
Stuart Scott8eef64f2015-04-08 15:13:54 -07005755 @Override
5756 public void factoryReset(int subId) {
5757 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005758 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5759 return;
5760 }
5761
Svet Ganovcc087f82015-05-12 20:35:54 -07005762 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005763
Svet Ganovcc087f82015-05-12 20:35:54 -07005764 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005765 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5766 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005767 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005768 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005769 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005770 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5771 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005772 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005773 // There has been issues when Sms raw table somehow stores orphan
5774 // fragments. They lead to garbled message when new fragments come
5775 // in and combined with those stale ones. In case this happens again,
5776 // user can reset all network settings which will clean up this table.
5777 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005778 // Clean up IMS settings as well here.
5779 int slotId = getSlotIndex(subId);
5780 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5781 ImsManager.getInstance(mApp, slotId).factoryReset();
5782 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005783 } finally {
5784 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005785 }
5786 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005787
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005788 private void cleanUpSmsRawTable(Context context) {
5789 ContentResolver resolver = context.getContentResolver();
5790 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5791 resolver.delete(uri, null, null);
5792 }
5793
Narayan Kamath1c496c22015-04-16 14:40:19 +01005794 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005795 public String getSimLocaleForSubscriber(int subId) {
5796 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5797 final Phone phone = getPhone(subId);
5798 if (phone == null) {
5799 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005800 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005802 final long identity = Binder.clearCallingIdentity();
5803 try {
chen xu5d3637b2019-01-21 23:31:38 -08005804 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5805 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005806 if (info == null) {
5807 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5808 return null;
5809 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005810 // Try and fetch the locale from the carrier properties or from the SIM language
5811 // preferences (EF-PL and EF-LI)...
5812 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005814 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5815 if (localeFromDefaultSim != null) {
5816 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5817 if (DBG) log("Using locale from subId: " + subId + " locale: "
5818 + localeFromDefaultSim);
5819 return localeFromDefaultSim.toLanguageTag();
5820 } else {
5821 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 }
5823 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 // The SIM language preferences only store a language (e.g. fr = French), not an
5826 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5827 // the SIM and carrier preferences does not include a country we add the country
5828 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005829 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005831 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832 return mccLocale.toLanguageTag();
5833 }
5834
5835 if (DBG) log("No locale found - returning null");
5836 return null;
5837 } finally {
5838 Binder.restoreCallingIdentity(identity);
5839 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005840 }
5841
5842 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005843 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005844 }
5845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 /**
5847 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5848 */
5849 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005850 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005851 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005852
Chenjie Yu1ba97252018-01-11 18:16:20 -08005853 private final ModemActivityInfo mLastModemActivityInfo =
5854 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5855
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005856 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005857 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5858 * representing the state of the modem.
5859 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005860 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5861 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005862 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005863 */
5864 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005865 public void requestModemActivityInfo(ResultReceiver result) {
5866 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005867 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868
5869 final long identity = Binder.clearCallingIdentity();
5870 try {
5871 ModemActivityInfo ret = null;
5872 synchronized (mLastModemActivityInfo) {
5873 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5874 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005875 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005876 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005877 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5878 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005879 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5880 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881 }
5882 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005883 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5884 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005885 mLastModemActivityInfo.setIdleTimeMillis(
5886 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5887 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5888 mLastModemActivityInfo.setRxTimeMillis(
5889 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5890 mLastModemActivityInfo.setEnergyUsed(
5891 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005892 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5894 mLastModemActivityInfo.getSleepTimeMillis(),
5895 mLastModemActivityInfo.getIdleTimeMillis(),
5896 mLastModemActivityInfo.getTxTimeMillis(),
5897 mLastModemActivityInfo.getRxTimeMillis(),
5898 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005899 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 Bundle bundle = new Bundle();
5901 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5902 result.send(0, bundle);
5903 } finally {
5904 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005905 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005906 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005907
Siddharth Rayb8114062018-06-17 15:02:38 -07005908 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5909 // less than total activity duration.
5910 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5911 if (info == null) {
5912 return false;
5913 }
5914 int activityDurationMs =
5915 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5916 int totalTxTimeMs = 0;
5917 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5918 totalTxTimeMs += info.getTxTimeMillis()[i];
5919 }
5920 return (info.isValid()
5921 && (info.getSleepTimeMillis() <= activityDurationMs)
5922 && (info.getIdleTimeMillis() <= activityDurationMs)
5923 && (info.getRxTimeMillis() <= activityDurationMs)
5924 && (totalTxTimeMs <= activityDurationMs));
5925 }
5926
Jack Yu85bd38a2015-11-09 11:34:32 -08005927 /**
5928 * {@hide}
5929 * Returns the service state information on specified subscription.
5930 */
5931 @Override
5932 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005933 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005934 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005935 return null;
5936 }
5937
Hall Liuf19c44f2018-11-27 14:38:17 -08005938 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5939 LocationAccessPolicy.checkLocationPermission(mApp,
5940 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5941 .setCallingPackage(callingPackage)
5942 .setCallingPid(Binder.getCallingPid())
5943 .setCallingUid(Binder.getCallingUid())
5944 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005945 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005946 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5947 .build());
5948
5949 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5950 LocationAccessPolicy.checkLocationPermission(mApp,
5951 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5952 .setCallingPackage(callingPackage)
5953 .setCallingPid(Binder.getCallingPid())
5954 .setCallingUid(Binder.getCallingUid())
5955 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005956 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005957 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5958 .build());
5959 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5960 boolean hasFinePermission =
5961 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5962 boolean hasCoarsePermission =
5963 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 final long identity = Binder.clearCallingIdentity();
5966 try {
5967 final Phone phone = getPhone(subId);
5968 if (phone == null) {
5969 return null;
5970 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005971
Hall Liuf19c44f2018-11-27 14:38:17 -08005972 ServiceState ss = phone.getServiceState();
5973
5974 // Scrub out the location info in ServiceState depending on what level of access
5975 // the caller has.
5976 if (hasFinePermission) return ss;
5977 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5978 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 } finally {
5980 Binder.restoreCallingIdentity(identity);
5981 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005982 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005983
5984 /**
5985 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5986 *
5987 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5988 * voicemail ringtone.
5989 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5990 * PhoneAccount.
5991 */
5992 @Override
5993 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 final long identity = Binder.clearCallingIdentity();
5995 try {
5996 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5997 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005998 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6002 } finally {
6003 Binder.restoreCallingIdentity(identity);
6004 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006005 }
6006
6007 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006008 * Sets the per-account voicemail ringtone.
6009 *
6010 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6011 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6012 *
6013 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6014 * voicemail ringtone.
6015 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6016 * PhoneAccount.
6017 */
6018 @Override
6019 public void setVoicemailRingtoneUri(String callingPackage,
6020 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006021 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006022 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6023 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006024 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6026 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6027 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029
6030 final long identity = Binder.clearCallingIdentity();
6031 try {
6032 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6033 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006034 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035 }
6036 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6037 } finally {
6038 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006039 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006040 }
6041
6042 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006043 * Returns whether vibration is set for voicemail notification in Phone settings.
6044 *
6045 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6046 * voicemail vibration setting.
6047 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6048 */
6049 @Override
6050 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 final long identity = Binder.clearCallingIdentity();
6052 try {
6053 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6054 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006055 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006057
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006058 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6059 } finally {
6060 Binder.restoreCallingIdentity(identity);
6061 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006062 }
6063
Youhan Wange64578a2016-05-02 15:32:42 -07006064 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006065 * Sets the per-account voicemail vibration.
6066 *
6067 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6068 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6069 *
6070 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6071 * voicemail vibration setting.
6072 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6073 * specific PhoneAccount.
6074 */
6075 @Override
6076 public void setVoicemailVibrationEnabled(String callingPackage,
6077 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006078 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006079 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6080 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006081 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6083 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6084 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006085 }
6086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 final long identity = Binder.clearCallingIdentity();
6088 try {
6089 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6090 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006091 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 }
6093 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6094 } finally {
6095 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006096 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006097 }
6098
6099 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006100 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6101 *
6102 * @throws SecurityException if the caller does not have the required permission
6103 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006104 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006105 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006106 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006107 }
6108
6109 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006110 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6111 * permission.
6112 *
6113 * @throws SecurityException if the caller does not have the required permission
6114 */
6115 private void enforceSendSmsPermission() {
6116 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6117 }
6118
6119 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006120 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006121 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006122 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006123 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006124 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006125 final long identity = Binder.clearCallingIdentity();
6126 try {
6127 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006128 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129 if (componentName == null) {
6130 throw new SecurityException(
6131 "Caller not current active visual voicemail package[null]");
6132 }
6133 String vvmPackage = componentName.getPackageName();
6134 if (!callingPackage.equals(vvmPackage)) {
6135 throw new SecurityException("Caller not current active visual voicemail package["
6136 + vvmPackage + "]");
6137 }
6138 } finally {
6139 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006140 }
6141 }
6142
6143 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006144 * Return the application ID for the app type.
6145 *
6146 * @param subId the subscription ID that this request applies to.
6147 * @param appType the uicc app type.
6148 * @return Application ID for specificied app type, or null if no uicc.
6149 */
6150 @Override
6151 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006152 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006153 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154
6155 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006156 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157 if (phone == null) {
6158 return null;
6159 }
6160 String aid = null;
6161 try {
6162 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6163 .getApplicationByType(appType).getAid();
6164 } catch (Exception e) {
6165 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6166 }
6167 return aid;
6168 } finally {
6169 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006170 }
Youhan Wange64578a2016-05-02 15:32:42 -07006171 }
6172
Youhan Wang4001d252016-05-11 10:29:41 -07006173 /**
6174 * Return the Electronic Serial Number.
6175 *
6176 * @param subId the subscription ID that this request applies to.
6177 * @return ESN or null if error.
6178 */
6179 @Override
6180 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006181 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006182 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006183
6184 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006185 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006186 if (phone == null) {
6187 return null;
6188 }
6189 String esn = null;
6190 try {
6191 esn = phone.getEsn();
6192 } catch (Exception e) {
6193 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6194 }
6195 return esn;
6196 } finally {
6197 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006198 }
Youhan Wang4001d252016-05-11 10:29:41 -07006199 }
6200
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006201 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006202 * Return the Preferred Roaming List Version.
6203 *
6204 * @param subId the subscription ID that this request applies to.
6205 * @return PRLVersion or null if error.
6206 */
6207 @Override
6208 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006209 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006210 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006211
6212 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006213 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 if (phone == null) {
6215 return null;
6216 }
6217 String cdmaPrlVersion = null;
6218 try {
6219 cdmaPrlVersion = phone.getCdmaPrlVersion();
6220 } catch (Exception e) {
6221 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6222 }
6223 return cdmaPrlVersion;
6224 } finally {
6225 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006226 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006227 }
6228
6229 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006230 * Get snapshot of Telephony histograms
6231 * @return List of Telephony histograms
6232 * @hide
6233 */
6234 @Override
6235 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6237 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238
6239 final long identity = Binder.clearCallingIdentity();
6240 try {
6241 return RIL.getTelephonyRILTimingHistograms();
6242 } finally {
6243 Binder.restoreCallingIdentity(identity);
6244 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006245 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006246
6247 /**
6248 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006249 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6250 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006251 * Require system privileges. In the future we may add this to carrier APIs.
6252 *
Michele Berionne482f8202018-11-27 18:57:59 -08006253 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006254 */
6255 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006256 @TelephonyManager.SetCarrierRestrictionResult
6257 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006258 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006259 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006260
Michele Berionne482f8202018-11-27 18:57:59 -08006261 if (carrierRestrictionRules == null) {
6262 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006263 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006265 final long identity = Binder.clearCallingIdentity();
6266 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006267 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006268 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006269 } finally {
6270 Binder.restoreCallingIdentity(identity);
6271 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006272 }
6273
6274 /**
6275 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006276 * Get the allowed carrier list and the excluded carrier list, including the priority between
6277 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006278 * Require system privileges. In the future we may add this to carrier APIs.
6279 *
Michele Berionne482f8202018-11-27 18:57:59 -08006280 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006281 */
6282 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006283 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006284 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006285 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286
6287 final long identity = Binder.clearCallingIdentity();
6288 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006289 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6290 if (response instanceof CarrierRestrictionRules) {
6291 return (CarrierRestrictionRules) response;
6292 }
6293 // Response is an Exception of some kind,
6294 // which is signalled to the user as a NULL retval
6295 return null;
6296 } catch (Exception e) {
6297 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6298 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 } finally {
6300 Binder.restoreCallingIdentity(identity);
6301 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006302 }
6303
fionaxu59545b42016-05-25 15:53:37 -07006304 /**
6305 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6306 * @param subId the subscription ID that this action applies to.
6307 * @param enabled control enable or disable metered apns.
6308 * {@hide}
6309 */
6310 @Override
6311 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6312 enforceModifyPermission();
6313 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314
6315 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006316 if (phone == null) {
6317 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6318 return;
6319 }
6320 try {
6321 phone.carrierActionSetMeteredApnsEnabled(enabled);
6322 } catch (Exception e) {
6323 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324 } finally {
6325 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006326 }
6327 }
6328
6329 /**
6330 * Action set from carrier signalling broadcast receivers to enable/disable radio
6331 * @param subId the subscription ID that this action applies to.
6332 * @param enabled control enable or disable radio.
6333 * {@hide}
6334 */
6335 @Override
6336 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6337 enforceModifyPermission();
6338 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006339
6340 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006341 if (phone == null) {
6342 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6343 return;
6344 }
6345 try {
6346 phone.carrierActionSetRadioEnabled(enabled);
6347 } catch (Exception e) {
6348 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006349 } finally {
6350 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006351 }
6352 }
6353
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006354 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006355 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6356 * network status based on which carrier apps could apply actions accordingly,
6357 * enable/disable default url handler for example.
6358 *
6359 * @param subId the subscription ID that this action applies to.
6360 * @param report control start/stop reporting the default network status.
6361 * {@hide}
6362 */
6363 @Override
6364 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6365 enforceModifyPermission();
6366 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367
6368 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006369 if (phone == null) {
6370 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6371 return;
6372 }
6373 try {
6374 phone.carrierActionReportDefaultNetworkStatus(report);
6375 } catch (Exception e) {
6376 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377 } finally {
6378 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006379 }
6380 }
6381
6382 /**
fionaxud9622282017-07-17 17:51:30 -07006383 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6384 * @param subId the subscription ID that this action applies to.
6385 * {@hide}
6386 */
6387 @Override
6388 public void carrierActionResetAll(int subId) {
6389 enforceModifyPermission();
6390 final Phone phone = getPhone(subId);
6391 if (phone == null) {
6392 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6393 return;
6394 }
6395 try {
6396 phone.carrierActionResetAll();
6397 } catch (Exception e) {
6398 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6399 }
6400 }
6401
6402 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006403 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6404 * bug report is being generated.
6405 */
6406 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006407 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006408 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6409 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006410 writer.println("Permission Denial: can't dump Phone from pid="
6411 + Binder.getCallingPid()
6412 + ", uid=" + Binder.getCallingUid()
6413 + "without permission "
6414 + android.Manifest.permission.DUMP);
6415 return;
6416 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006417 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006418 }
Jack Yueb89b242016-06-22 13:27:47 -07006419
Brad Ebingerdac2f002018-04-03 15:17:52 -07006420 @Override
6421 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6422 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6423 throws RemoteException {
6424 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6425 }
6426
Jack Yueb89b242016-06-22 13:27:47 -07006427 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006428 * Get aggregated video call data usage since boot.
6429 *
6430 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6431 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006432 * {@hide}
6433 */
6434 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006435 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006436 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6437 null);
6438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439 final long identity = Binder.clearCallingIdentity();
6440 try {
6441 // NetworkStatsService keeps tracking the active network interface and identity. It
6442 // records the delta with the corresponding network identity.
6443 // We just return the total video call data usage snapshot since boot.
6444 Phone phone = getPhone(subId);
6445 if (phone != null) {
6446 return phone.getVtDataUsage(perUidStats);
6447 }
6448 return null;
6449 } finally {
6450 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006451 }
Jack Yueb89b242016-06-22 13:27:47 -07006452 }
Jack Yu75ab2952016-07-08 14:29:33 -07006453
6454 /**
6455 * Policy control of data connection. Usually used when data limit is passed.
6456 * @param enabled True if enabling the data, otherwise disabling.
6457 * @param subId Subscription index
6458 * {@hide}
6459 */
6460 @Override
6461 public void setPolicyDataEnabled(boolean enabled, int subId) {
6462 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006463
6464 final long identity = Binder.clearCallingIdentity();
6465 try {
6466 Phone phone = getPhone(subId);
6467 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006468 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469 }
6470 } finally {
6471 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006472 }
6473 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006474
6475 /**
6476 * Get Client request stats
6477 * @return List of Client Request Stats
6478 * @hide
6479 */
6480 @Override
6481 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006482 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006483 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006484 return null;
6485 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006486 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006488 final long identity = Binder.clearCallingIdentity();
6489 try {
6490 if (phone != null) {
6491 return phone.getClientRequestStats();
6492 }
6493
6494 return null;
6495 } finally {
6496 Binder.restoreCallingIdentity(identity);
6497 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006498 }
6499
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006500 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006501 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006502 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006503 }
Jack Yueb4124c2017-02-16 15:32:43 -08006504
6505 /**
Grace Chen70990072017-03-24 17:21:30 -07006506 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006507 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006508 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006509 * @param state State of SIM (power down, power up, pass through)
6510 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6511 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6512 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006513 *
6514 **/
6515 @Override
Grace Chen70990072017-03-24 17:21:30 -07006516 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006517 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006518 Phone phone = PhoneFactory.getPhone(slotIndex);
6519
vagdeviaf9a5b92018-08-15 16:01:53 -07006520 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006522 final long identity = Binder.clearCallingIdentity();
6523 try {
6524 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006525 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526 }
6527 } finally {
6528 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006529 }
6530 }
Shuo Qiandd210312017-04-12 22:11:33 +00006531
Tyler Gunn65d45c22017-06-05 11:22:26 -07006532 private boolean isUssdApiAllowed(int subId) {
6533 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006534 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006535 if (configManager == null) {
6536 return false;
6537 }
6538 PersistableBundle pb = configManager.getConfigForSubId(subId);
6539 if (pb == null) {
6540 return false;
6541 }
6542 return pb.getBoolean(
6543 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6544 }
6545
Shuo Qiandd210312017-04-12 22:11:33 +00006546 /**
6547 * Check if phone is in emergency callback mode
6548 * @return true if phone is in emergency callback mode
6549 * @param subId sub id
6550 */
goneil9c5f4872017-12-05 14:07:56 -08006551 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006552 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006553 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006554 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555
6556 final long identity = Binder.clearCallingIdentity();
6557 try {
6558 if (phone != null) {
6559 return phone.isInEcm();
6560 } else {
6561 return false;
6562 }
6563 } finally {
6564 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006565 }
6566 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006567
6568 /**
6569 * Get the current signal strength information for the given subscription.
6570 * Because this information is not updated when the device is in a low power state
6571 * it should not be relied-upon to be current.
6572 * @param subId Subscription index
6573 * @return the most recent cached signal strength info from the modem
6574 */
6575 @Override
6576 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006577 final long identity = Binder.clearCallingIdentity();
6578 try {
6579 Phone p = getPhone(subId);
6580 if (p == null) {
6581 return null;
6582 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006583
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584 return p.getSignalStrength();
6585 } finally {
6586 Binder.restoreCallingIdentity(identity);
6587 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006588 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006589
Pengquan Meng77b7f132018-08-22 14:49:57 -07006590 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006591 * Get the current modem radio state for the given slot.
6592 * @param slotIndex slot index.
6593 * @param callingPackage the name of the package making the call.
6594 * @return the current radio power state from the modem
6595 */
6596 @Override
6597 public int getRadioPowerState(int slotIndex, String callingPackage) {
6598 Phone phone = PhoneFactory.getPhone(slotIndex);
6599 if (phone != null) {
6600 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6601 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6602 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6603 }
6604
6605 final long identity = Binder.clearCallingIdentity();
6606 try {
6607 return phone.getRadioPowerState();
6608 } finally {
6609 Binder.restoreCallingIdentity(identity);
6610 }
6611 }
6612 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6613 }
6614
6615 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006616 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6617 *
6618 * <p>Requires one of the following permissions:
6619 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6620 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6621 * privileges.
6622 *
6623 * @param subId subscription id
6624 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6625 * {@code false}.
6626 */
6627 @Override
6628 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006629 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6630 null /* message */);
6631
Pengquan Menga1bb6272018-09-06 09:59:22 -07006632 boolean isEnabled = false;
6633 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006634 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006635 Phone phone = getPhone(subId);
6636 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006637 } catch (Exception e) {
6638 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6639 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006640 } finally {
6641 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006642 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006643 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006644 }
6645
6646
6647 /**
6648 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6649 *
6650 * <p> Requires permission:
6651 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6652 * privileges.
6653 *
6654 * @param subId subscription id
6655 * @param isEnabled {@code true} means enable, {@code false} means disable.
6656 */
6657 @Override
6658 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6660 mApp, subId, "setDataRoamingEnabled");
6661
Pengquan Menga1bb6272018-09-06 09:59:22 -07006662 final long identity = Binder.clearCallingIdentity();
6663 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006664 Phone phone = getPhone(subId);
6665 if (phone != null) {
6666 phone.setDataRoamingEnabled(isEnabled);
6667 }
6668 } finally {
6669 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006670 }
6671 }
6672
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006673 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006674 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006675 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6676 mApp, subId, "isManualNetworkSelectionAllowed");
6677
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006678 boolean isAllowed = true;
6679 final long identity = Binder.clearCallingIdentity();
6680 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006681 Phone phone = getPhone(subId);
6682 if (phone != null) {
6683 isAllowed = phone.isCspPlmnEnabled();
6684 }
6685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
6688 return isAllowed;
6689 }
6690
6691 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006692 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006693 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006694 try {
6695 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006696 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006697 } catch (SecurityException e) {
6698 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6699 // has carrier privileges on an active UICC
6700 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6701 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006702 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006703 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006704 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006705
6706 final long identity = Binder.clearCallingIdentity();
6707 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006708 UiccController uiccController = UiccController.getInstance();
6709 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006710 if (hasReadPermission) {
6711 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006712 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006713
6714 // Remove private info if the caller doesn't have access
6715 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6716 for (UiccCardInfo cardInfo : cardInfos) {
6717 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6718 // is available
6719 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6720 if (card == null || card.getUiccProfile() == null) {
6721 // assume no access if the card or profile is unavailable
6722 filteredInfos.add(cardInfo.getUnprivileged());
6723 continue;
6724 }
6725 UiccProfile profile = card.getUiccProfile();
6726 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6727 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6728 filteredInfos.add(cardInfo);
6729 } else {
6730 filteredInfos.add(cardInfo.getUnprivileged());
6731 }
6732 }
6733 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006734 } finally {
6735 Binder.restoreCallingIdentity(identity);
6736 }
6737 }
6738
6739 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006740 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006741 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743 final long identity = Binder.clearCallingIdentity();
6744 try {
6745 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6746 if (slots == null) {
6747 Rlog.i(LOG_TAG, "slots is null.");
6748 return null;
6749 }
6750
6751 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6752 for (int i = 0; i < slots.length; i++) {
6753 UiccSlot slot = slots[i];
6754 if (slot == null) {
6755 continue;
6756 }
6757
Jordan Liu7be7e652019-05-06 18:55:02 +00006758 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 UiccCard card = slot.getUiccCard();
6760 if (card != null) {
6761 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006762 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006763 cardId = slot.getEid();
6764 if (TextUtils.isEmpty(cardId)) {
6765 cardId = slot.getIccId();
6766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 }
6768
Jordan Liu857451f2019-05-09 16:35:35 -07006769 if (cardId != null) {
6770 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6771 // if cardId is an EID, it's all digits so this is fine
6772 cardId = IccUtils.stripTrailingFs(cardId);
6773 }
6774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775 int cardState = 0;
6776 switch (slot.getCardState()) {
6777 case CARDSTATE_ABSENT:
6778 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6779 break;
6780 case CARDSTATE_PRESENT:
6781 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6782 break;
6783 case CARDSTATE_ERROR:
6784 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6785 break;
6786 case CARDSTATE_RESTRICTED:
6787 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6788 break;
6789 default:
6790 break;
6791
6792 }
6793
6794 infos[i] = new UiccSlotInfo(
6795 slot.isActive(),
6796 slot.isEuicc(),
6797 cardId,
6798 cardState,
6799 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006800 slot.isExtendedApduSupported(),
6801 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006802 }
6803 return infos;
6804 } finally {
6805 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006806 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006807 }
6808
6809 @Override
6810 public boolean switchSlots(int[] physicalSlots) {
6811 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006812
6813 final long identity = Binder.clearCallingIdentity();
6814 try {
6815 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6816 } finally {
6817 Binder.restoreCallingIdentity(identity);
6818 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006819 }
Jack Yu4c988042018-02-27 15:30:01 -08006820
6821 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006822 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006823 final long identity = Binder.clearCallingIdentity();
6824 try {
6825 return UiccController.getInstance().getCardIdForDefaultEuicc();
6826 } finally {
6827 Binder.restoreCallingIdentity(identity);
6828 }
6829 }
6830
6831 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006832 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6833 enforceModifyPermission();
6834 final Phone phone = getPhone(subId);
6835 if (phone == null) {
6836 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6837 return;
6838 }
6839
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006840 final long identity = Binder.clearCallingIdentity();
6841 try {
6842 phone.setRadioIndicationUpdateMode(filters, mode);
6843 } finally {
6844 Binder.restoreCallingIdentity(identity);
6845 }
Jack Yu4c988042018-02-27 15:30:01 -08006846 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006847
6848 /**
goneil47ffb6e2018-04-06 15:40:58 -07006849 * A test API to reload the UICC profile.
6850 *
6851 * <p>Requires that the calling app has permission
6852 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6853 * @hide
6854 */
6855 @Override
6856 public void refreshUiccProfile(int subId) {
6857 enforceModifyPermission();
6858
6859 final long identity = Binder.clearCallingIdentity();
6860 try {
6861 Phone phone = getPhone(subId);
6862 if (phone == null) {
6863 return;
6864 }
6865 UiccCard uiccCard = phone.getUiccCard();
6866 if (uiccCard == null) {
6867 return;
6868 }
6869 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6870 if (uiccProfile == null) {
6871 return;
6872 }
6873 uiccProfile.refresh();
6874 } finally {
6875 Binder.restoreCallingIdentity(identity);
6876 }
6877 }
6878
6879 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006880 * Returns false if the mobile data is disabled by default, otherwise return true.
6881 */
6882 private boolean getDefaultDataEnabled() {
6883 return "true".equalsIgnoreCase(
6884 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6885 }
6886
6887 /**
6888 * Returns true if the data roaming is enabled by default, i.e the system property
6889 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6890 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6891 */
6892 private boolean getDefaultDataRoamingEnabled(int subId) {
6893 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006894 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006895 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6896 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6897 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6898 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6899 return isDataRoamingEnabled;
6900 }
6901
6902 /**
6903 * Returns the default network type for the given {@code subId}, if the default network type is
6904 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6905 */
6906 private int getDefaultNetworkType(int subId) {
6907 return Integer.parseInt(
6908 TelephonyManager.getTelephonyProperty(
6909 mSubscriptionController.getPhoneId(subId),
6910 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6911 String.valueOf(Phone.PREFERRED_NT_MODE)));
6912 }
fionaxua13278b2018-03-21 00:08:13 -07006913
6914 @Override
6915 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006916 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006917 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006918
6919 final long identity = Binder.clearCallingIdentity();
6920 try {
6921 final Phone phone = getPhone(subId);
6922 if (phone == null) {
6923 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6924 return;
6925 }
chen xueaba88a2019-03-15 13:15:10 -07006926 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6927 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928 } finally {
6929 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006930 }
fionaxua13278b2018-03-21 00:08:13 -07006931 }
6932
6933 @Override
6934 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006935 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006936
6937 final long identity = Binder.clearCallingIdentity();
6938 try {
6939 final Phone phone = getPhone(subId);
6940 if (phone == null) {
6941 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6942 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6943 }
6944 return phone.getCarrierIdListVersion();
6945 } finally {
6946 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006947 }
fionaxua13278b2018-03-21 00:08:13 -07006948 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006949
6950 @Override
6951 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6952 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6953 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6954 return -1;
6955 }
6956
6957 final long identity = Binder.clearCallingIdentity();
6958 try {
6959 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6960 } finally {
6961 Binder.restoreCallingIdentity(identity);
6962 }
6963 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006964
6965 @Override
6966 public int getCdmaRoamingMode(int subId) {
6967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6968 mApp, subId, "getCdmaRoamingMode");
6969
6970 final long identity = Binder.clearCallingIdentity();
6971 try {
6972 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6973 } finally {
6974 Binder.restoreCallingIdentity(identity);
6975 }
6976 }
6977
6978 @Override
6979 public boolean setCdmaRoamingMode(int subId, int mode) {
6980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6981 mApp, subId, "setCdmaRoamingMode");
6982
6983 final long identity = Binder.clearCallingIdentity();
6984 try {
6985 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6986 } finally {
6987 Binder.restoreCallingIdentity(identity);
6988 }
6989 }
6990
6991 @Override
6992 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6994 mApp, subId, "setCdmaSubscriptionMode");
6995
6996 final long identity = Binder.clearCallingIdentity();
6997 try {
6998 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6999 } finally {
7000 Binder.restoreCallingIdentity(identity);
7001 }
7002 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007003
sqianc5eccab2018-10-19 18:46:41 -07007004 @Override
sqian8c685422019-02-22 15:55:18 -08007005 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007006 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007007 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007008 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007009 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7010 }
7011 final long identity = Binder.clearCallingIdentity();
7012 try {
sqian854d44b2018-12-12 16:48:18 -08007013 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7014 for (Phone phone: PhoneFactory.getPhones()) {
7015 if (phone.getEmergencyNumberTracker() != null
7016 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7017 emergencyNumberListInternal.put(
7018 phone.getSubId(),
7019 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7020 }
sqian11b7a0e2018-12-05 18:48:28 -08007021 }
sqian854d44b2018-12-12 16:48:18 -08007022 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007023 } finally {
7024 Binder.restoreCallingIdentity(identity);
7025 }
sqianc5eccab2018-10-19 18:46:41 -07007026 }
7027
7028 @Override
sqian8c685422019-02-22 15:55:18 -08007029 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007030 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007031 if (!exactMatch) {
7032 TelephonyPermissions
7033 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007034 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007035 }
7036 final long identity = Binder.clearCallingIdentity();
7037 try {
sqian854d44b2018-12-12 16:48:18 -08007038 for (Phone phone: PhoneFactory.getPhones()) {
7039 if (phone.getEmergencyNumberTracker() != null
7040 && phone.getEmergencyNumberTracker() != null) {
7041 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7042 number, exactMatch)) {
7043 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007044 }
7045 }
sqian11b7a0e2018-12-05 18:48:28 -08007046 }
7047 return false;
7048 } finally {
7049 Binder.restoreCallingIdentity(identity);
7050 }
7051 }
7052
sqianf4ca7ed2019-01-15 18:32:07 -08007053 /**
7054 * Update emergency number list for test mode.
7055 */
7056 @Override
7057 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7058 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7059 "updateEmergencyNumberListTestMode");
7060
7061 final long identity = Binder.clearCallingIdentity();
7062 try {
7063 for (Phone phone: PhoneFactory.getPhones()) {
7064 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7065 if (tracker != null) {
7066 tracker.executeEmergencyNumberTestModeCommand(action, num);
7067 }
7068 }
7069 } finally {
7070 Binder.restoreCallingIdentity(identity);
7071 }
7072 }
7073
7074 /**
7075 * Get the full emergency number list for test mode.
7076 */
7077 @Override
7078 public List<String> getEmergencyNumberListTestMode() {
7079 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7080 "getEmergencyNumberListTestMode");
7081
7082 final long identity = Binder.clearCallingIdentity();
7083 try {
7084 Set<String> emergencyNumbers = new HashSet<>();
7085 for (Phone phone: PhoneFactory.getPhones()) {
7086 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7087 if (tracker != null) {
7088 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7089 emergencyNumbers.add(num.getNumber());
7090 }
7091 }
7092 }
7093 return new ArrayList<>(emergencyNumbers);
7094 } finally {
7095 Binder.restoreCallingIdentity(identity);
7096 }
7097 }
7098
chen xud6b45bd2018-10-30 22:27:10 -07007099 @Override
7100 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7101 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7102 Phone phone = getPhone(subId);
7103 if (phone == null) {
7104 return null;
7105 }
7106 final long identity = Binder.clearCallingIdentity();
7107 try {
7108 UiccProfile profile = UiccController.getInstance()
7109 .getUiccProfileForPhone(phone.getPhoneId());
7110 if (profile != null) {
7111 return profile.getCertsFromCarrierPrivilegeAccessRules();
7112 }
7113 } finally {
7114 Binder.restoreCallingIdentity(identity);
7115 }
7116 return null;
7117 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007118
7119 /**
7120 * Enable or disable a modem stack.
7121 */
7122 @Override
7123 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7124 enforceModifyPermission();
7125
7126 final long identity = Binder.clearCallingIdentity();
7127 try {
7128 Phone phone = PhoneFactory.getPhone(slotIndex);
7129 if (phone == null) {
7130 return false;
7131 } else {
7132 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7133 }
7134 } finally {
7135 Binder.restoreCallingIdentity(identity);
7136 }
7137 }
Michelecea4cf22018-12-21 15:00:11 -08007138
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007139 /**
7140 * Whether a modem stack is enabled or not.
7141 */
7142 @Override
7143 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7144 Phone phone = PhoneFactory.getPhone(slotIndex);
7145 if (phone == null) return false;
7146
7147 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7148 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7149 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7150 }
7151
7152 final long identity = Binder.clearCallingIdentity();
7153 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007154 try {
7155 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7156 } catch (NoSuchElementException ex) {
7157 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7158 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007159 } finally {
7160 Binder.restoreCallingIdentity(identity);
7161 }
7162 }
7163
Michelecea4cf22018-12-21 15:00:11 -08007164 @Override
Michele0ea7d782019-03-19 14:58:42 -07007165 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007166 enforceModifyPermission();
7167
7168 final long identity = Binder.clearCallingIdentity();
7169 try {
7170 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007171 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007172 .commit();
7173 } finally {
7174 Binder.restoreCallingIdentity(identity);
7175 }
7176 }
7177
7178 @Override
Michele0ea7d782019-03-19 14:58:42 -07007179 @TelephonyManager.IsMultiSimSupportedResult
7180 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007181 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007182 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7183 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007184 }
Michelecea4cf22018-12-21 15:00:11 -08007185
7186 final long identity = Binder.clearCallingIdentity();
7187 try {
Michele0ea7d782019-03-19 14:58:42 -07007188 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007189 } finally {
7190 Binder.restoreCallingIdentity(identity);
7191 }
7192 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007193
Michele0ea7d782019-03-19 14:58:42 -07007194 @TelephonyManager.IsMultiSimSupportedResult
7195 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007196 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7197 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7198 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007199 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7200 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007201 }
7202 // Check if the hardware supports multisim functionality. If usage of multisim is not
7203 // supported by the modem, indicate that it is restricted.
7204 PhoneCapability staticCapability =
7205 mPhoneConfigurationManager.getStaticPhoneCapability();
7206 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007207 loge("isMultiSimSupportedInternal: no static configuration available");
7208 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007209 }
7210 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007211 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7212 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007213 }
7214 // Check if support of multiple SIMs is restricted by carrier
7215 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007216 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007217 }
7218
Michele0ea7d782019-03-19 14:58:42 -07007219 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007220 }
7221
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007222 /**
7223 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007224 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7225 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7226 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007227 * @param numOfSims number of active sims we want to switch to
7228 */
7229 @Override
7230 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007231 if (numOfSims == 1) {
7232 enforceModifyPermission();
7233 } else {
7234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7235 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7236 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007237 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007238
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007239 try {
Michele30b57b22019-03-01 12:01:14 -08007240 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007241 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007242 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7243 return;
7244 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007245 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7246 } finally {
7247 Binder.restoreCallingIdentity(identity);
7248 }
7249 }
7250
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007251 @Override
7252 public boolean isApplicationOnUicc(int subId, int appType) {
7253 enforceReadPrivilegedPermission("isApplicationOnUicc");
7254 Phone phone = getPhone(subId);
7255 if (phone == null) {
7256 return false;
7257 }
7258 final long identity = Binder.clearCallingIdentity();
7259 try {
7260 UiccCard uiccCard = phone.getUiccCard();
7261 if (uiccCard == null) {
7262 return false;
7263 }
7264 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7265 if (uiccProfile == null) {
7266 return false;
7267 }
7268 if (TelephonyManager.APPTYPE_SIM <= appType
7269 && appType <= TelephonyManager.APPTYPE_ISIM) {
7270 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7271 }
7272 return false;
7273 } finally {
7274 Binder.restoreCallingIdentity(identity);
7275 }
7276 }
7277
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007278 /**
chen xub4baa772019-04-03 10:23:41 -07007279 * Get whether making changes to modem configurations will trigger reboot.
7280 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007281 */
7282 @Override
chen xub4baa772019-04-03 10:23:41 -07007283 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7284 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7285 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7286 return false;
7287 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007288 final long identity = Binder.clearCallingIdentity();
7289 try {
7290 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7291 } finally {
7292 Binder.restoreCallingIdentity(identity);
7293 }
7294 }
7295
Nathan Harold29f5f052019-02-15 13:41:57 -08007296 private void updateModemStateMetrics() {
7297 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7298 // TODO: check the state for each modem if the api is ready.
7299 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7300 }
7301
Pengquan Meng3889a572019-01-23 11:16:29 -08007302 @Override
7303 public int[] getSlotsMapping() {
7304 enforceReadPrivilegedPermission("getSlotsMapping");
7305
7306 final long identity = Binder.clearCallingIdentity();
7307 try {
7308 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7309 // All logical slots should have a mapping to a physical slot.
7310 int[] logicalSlotsMapping = new int[phoneCount];
7311 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7312 for (int i = 0; i < slotInfos.length; i++) {
7313 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7314 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7315 }
7316 }
7317 return logicalSlotsMapping;
7318 } finally {
7319 Binder.restoreCallingIdentity(identity);
7320 }
7321 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007322
7323 /**
7324 * Get the IRadio HAL Version
7325 */
7326 @Override
7327 public int getRadioHalVersion() {
7328 Phone phone = getDefaultPhone();
7329 if (phone == null) return -1;
7330 HalVersion hv = phone.getHalVersion();
7331 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7332 return hv.major * 100 + hv.minor;
7333 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007334
7335 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007336 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7337 * corresponding network requests on a subId.
7338 *
7339 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007340 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007341 * 2) APN is un-metered for this subscription, or
7342 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7343 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7344 *
7345 * @return whether data is allowed for a apn type.
7346 *
7347 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007348 */
7349 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007350 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007351 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7352 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007353
7354 // Now that all security checks passes, perform the operation as ourselves.
7355 final long identity = Binder.clearCallingIdentity();
7356 try {
7357 Phone phone = getPhone(subId);
7358 if (phone == null) return false;
7359
Jack Yu41407ee2019-05-13 16:54:09 -07007360 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007361 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7362 } finally {
7363 Binder.restoreCallingIdentity(identity);
7364 }
7365 }
7366
7367 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007368 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007369 enforceReadPrivilegedPermission("isApnMetered");
7370
7371 // Now that all security checks passes, perform the operation as ourselves.
7372 final long identity = Binder.clearCallingIdentity();
7373 try {
7374 Phone phone = getPhone(subId);
7375 if (phone == null) return true; // By default return true.
7376
Jack Yu41407ee2019-05-13 16:54:09 -07007377 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007378 } finally {
7379 Binder.restoreCallingIdentity(identity);
7380 }
7381 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007382
7383 @Override
7384 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7385 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7386 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7387 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7388 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7389 }
7390 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7391 Intent intent = new Intent();
7392 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7393 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7394 // Bring up choose default SMS subscription dialog right now
7395 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7396 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7397 mApp.startActivity(intent);
7398 }
chen xud5ca2d52019-05-28 15:20:57 -07007399
7400 @Override
7401 public String getMmsUAProfUrl(int subId) {
7402 //TODO investigate if this API should require proper permission check in R b/133791609
7403 final long identity = Binder.clearCallingIdentity();
7404 try {
7405 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7406 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7407 } finally {
7408 Binder.restoreCallingIdentity(identity);
7409 }
7410 }
7411
7412 @Override
7413 public String getMmsUserAgent(int subId) {
7414 //TODO investigate if this API should require proper permission check in R b/133791609
7415 final long identity = Binder.clearCallingIdentity();
7416 try {
7417 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7418 .getString(com.android.internal.R.string.config_mms_user_agent);
7419 } finally {
7420 Binder.restoreCallingIdentity(identity);
7421 }
7422 }
Jack Yub07d4972019-05-28 16:12:25 -07007423
7424 @Override
7425 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7426 enforceModifyPermission();
7427
7428 // Now that all security checks passes, perform the operation as ourselves.
7429 final long identity = Binder.clearCallingIdentity();
7430 try {
7431 Phone phone = getPhone(subId);
7432 if (phone == null) return false;
7433
7434 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7435 } finally {
7436 Binder.restoreCallingIdentity(identity);
7437 }
7438 }
7439
7440 @Override
7441 public boolean isDataAllowedInVoiceCall(int subId) {
7442 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7443
7444 // Now that all security checks passes, perform the operation as ourselves.
7445 final long identity = Binder.clearCallingIdentity();
7446 try {
7447 Phone phone = getPhone(subId);
7448 if (phone == null) return false;
7449
7450 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7451 } finally {
7452 Binder.restoreCallingIdentity(identity);
7453 }
7454 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007455
7456 /**
7457 * Updates whether conference event pacakge handling is enabled.
7458 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7459 * otherwise.
7460 */
7461 @Override
7462 public void setCepEnabled(boolean isCepEnabled) {
7463 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7464
7465 final long identity = Binder.clearCallingIdentity();
7466 try {
7467 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7468 for (Phone phone : PhoneFactory.getPhones()) {
7469 Phone defaultPhone = phone.getImsPhone();
7470 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7471 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7472 ImsPhoneCallTracker imsPhoneCallTracker =
7473 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7474 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7475 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7476 + imsPhone.getMsisdn());
7477 }
7478 }
7479 } finally {
7480 Binder.restoreCallingIdentity(identity);
7481 }
7482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007483}