blob: f32f7e60468d097fedaf1e32b9e3e811dbf19a61 [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);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001080 cb.onError(
1081 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1082 ar.exception.getClass().getName(),
1083 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001086 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001087 } else {
1088 // use the result as returned
1089 cb.onCellInfo((List<CellInfo>) ar.result);
1090 }
1091 } catch (RemoteException re) {
1092 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1093 }
1094 break;
1095 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001096 request = (MainThreadRequest) msg.obj;
1097 WorkSource ws = (WorkSource) request.argument;
1098 Phone phone = getPhoneFromRequest(request);
1099 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1100 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001101 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001102 ar = (AsyncResult) msg.obj;
1103 request = (MainThreadRequest) ar.userObj;
1104 if (ar.exception == null) {
1105 request.result = ar.result;
1106 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001107 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001108 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1109 ? new CdmaCellLocation() : new GsmCellLocation();
1110 }
1111
1112 synchronized (request) {
1113 request.notifyAll();
1114 }
1115 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001116 case CMD_MODEM_REBOOT:
1117 request = (MainThreadRequest) msg.obj;
1118 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001119 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001120 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001121 case EVENT_CMD_MODEM_REBOOT_DONE:
1122 handleNullReturnEvent(msg, "rebootModem");
1123 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001124 case CMD_REQUEST_ENABLE_MODEM:
1125 request = (MainThreadRequest) msg.obj;
1126 boolean enable = (boolean) request.argument;
1127 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001128 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001129 PhoneConfigurationManager.getInstance()
1130 .enablePhone(request.phone, enable, onCompleted);
1131 break;
1132 case EVENT_ENABLE_MODEM_DONE:
1133 ar = (AsyncResult) msg.obj;
1134 request = (MainThreadRequest) ar.userObj;
1135 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001136 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001137 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001138 if ((boolean) request.result) {
1139 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1140 updateModemStateMetrics();
1141 } else {
1142 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1143 + ar.exception);
1144 }
1145 notifyRequester(request);
1146 break;
1147 case CMD_GET_MODEM_STATUS:
1148 request = (MainThreadRequest) msg.obj;
1149 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1150 PhoneConfigurationManager.getInstance()
1151 .getPhoneStatusFromModem(request.phone, onCompleted);
1152 break;
1153 case EVENT_GET_MODEM_STATUS_DONE:
1154 ar = (AsyncResult) msg.obj;
1155 request = (MainThreadRequest) ar.userObj;
1156 int id = request.phone.getPhoneId();
1157 if (ar.exception == null && ar.result != null) {
1158 request.result = ar.result;
1159 //update the cache as modem status has changed
1160 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1161 (boolean) request.result);
1162 } else {
1163 // Return true if modem status cannot be retrieved. For most cases,
1164 // modem status is on. And for older version modems, GET_MODEM_STATUS
1165 // and disable modem are not supported. Modem is always on.
1166 // TODO: this should be fixed in R to support a third
1167 // status UNKNOWN b/131631629
1168 request.result = true;
1169 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1170 + ar.exception);
1171 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001172 notifyRequester(request);
1173 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001174 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1175 ar = (AsyncResult) msg.obj;
1176 request = (MainThreadRequest) ar.userObj;
1177 if (ar.exception == null && ar.result != null) {
1178 request.result = ar.result;
1179 } else {
1180 request.result = -1;
1181 loge("Failed to set Forbidden Plmns");
1182 if (ar.result == null) {
1183 loge("setForbidenPlmns: Empty response");
1184 } else if (ar.exception != null) {
1185 loge("setForbiddenPlmns: Exception: " + ar.exception);
1186 request.result = -1;
1187 } else {
1188 loge("setForbiddenPlmns: Unknown exception");
1189 }
1190 }
1191 notifyRequester(request);
1192 break;
1193 case CMD_SET_FORBIDDEN_PLMNS:
1194 request = (MainThreadRequest) msg.obj;
1195 uiccCard = getUiccCardFromRequest(request);
1196 if (uiccCard == null) {
1197 loge("setForbiddenPlmns: UiccCard is null");
1198 request.result = -1;
1199 notifyRequester(request);
1200 break;
1201 }
1202 Pair<Integer, List<String>> setFplmnsArgs =
1203 (Pair<Integer, List<String>>) request.argument;
1204 appType = setFplmnsArgs.first;
1205 List<String> fplmns = setFplmnsArgs.second;
1206 uiccApp = uiccCard.getApplicationByType(appType);
1207 if (uiccApp == null) {
1208 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1209 request.result = -1;
1210 loge("Failed to get UICC App");
1211 notifyRequester(request);
1212 } else {
1213 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1214 ((SIMRecords) uiccApp.getIccRecords())
1215 .setForbiddenPlmns(onCompleted, fplmns);
1216 }
1217 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218 default:
1219 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1220 break;
1221 }
1222 }
Jake Hambye994d462014-02-03 13:10:13 -08001223
Pengquan Menga1bb6272018-09-06 09:59:22 -07001224 private void notifyRequester(MainThreadRequest request) {
1225 synchronized (request) {
1226 request.notifyAll();
1227 }
1228 }
1229
Jake Hambye994d462014-02-03 13:10:13 -08001230 private void handleNullReturnEvent(Message msg, String command) {
1231 AsyncResult ar = (AsyncResult) msg.obj;
1232 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1233 if (ar.exception == null) {
1234 request.result = true;
1235 } else {
1236 request.result = false;
1237 if (ar.exception instanceof CommandException) {
1238 loge(command + ": CommandException: " + ar.exception);
1239 } else {
1240 loge(command + ": Unknown exception");
1241 }
1242 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001243 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 }
1246
1247 /**
1248 * Posts the specified command to be executed on the main thread,
1249 * waits for the request to complete, and returns the result.
1250 * @see #sendRequestAsync
1251 */
1252 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001253 return sendRequest(
1254 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001255 }
1256
1257 /**
1258 * Posts the specified command to be executed on the main thread,
1259 * waits for the request to complete, and returns the result.
1260 * @see #sendRequestAsync
1261 */
1262 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1263 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001264 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001265 }
1266
1267 /**
1268 * Posts the specified command to be executed on the main thread,
1269 * waits for the request to complete, and returns the result.
1270 * @see #sendRequestAsync
1271 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001272 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001273 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001274 }
1275
1276 /**
1277 * Posts the specified command to be executed on the main thread,
1278 * waits for the request to complete, and returns the result.
1279 * @see #sendRequestAsync
1280 */
Nathan Harold92bed182018-10-12 18:16:49 -07001281 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1282 return sendRequest(command, argument, subId, null, workSource);
1283 }
1284
1285 /**
1286 * Posts the specified command to be executed on the main thread,
1287 * waits for the request to complete, and returns the result.
1288 * @see #sendRequestAsync
1289 */
1290 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1291 return sendRequest(
1292 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1293 }
1294
1295 /**
1296 * Posts the specified command to be executed on the main thread,
1297 * waits for the request to complete, and returns the result.
1298 * @see #sendRequestAsync
1299 */
1300 private Object sendRequest(
1301 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001302 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1303 throw new RuntimeException("This method will deadlock if called from the main thread.");
1304 }
1305
Nathan Harold92bed182018-10-12 18:16:49 -07001306 MainThreadRequest request = null;
1307 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1308 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1309 } else if (phone != null) {
1310 request = new MainThreadRequest(argument, phone, workSource);
1311 } else {
1312 request = new MainThreadRequest(argument, subId, workSource);
1313 }
1314
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 Message msg = mMainThreadHandler.obtainMessage(command, request);
1316 msg.sendToTarget();
1317
1318 // Wait for the request to complete
1319 synchronized (request) {
1320 while (request.result == null) {
1321 try {
1322 request.wait();
1323 } catch (InterruptedException e) {
1324 // Do nothing, go back and wait until the request is complete
1325 }
1326 }
1327 }
1328 return request.result;
1329 }
1330
1331 /**
1332 * Asynchronous ("fire and forget") version of sendRequest():
1333 * Posts the specified command to be executed on the main thread, and
1334 * returns immediately.
1335 * @see #sendRequest
1336 */
1337 private void sendRequestAsync(int command) {
1338 mMainThreadHandler.sendEmptyMessage(command);
1339 }
1340
1341 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001342 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001343 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001344 */
1345 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001346 sendRequestAsync(command, argument, null, null);
1347 }
1348
1349 /**
1350 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1351 * @see {@link #sendRequest(int,Object)}
1352 */
1353 private void sendRequestAsync(
1354 int command, Object argument, Phone phone, WorkSource workSource) {
1355 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001356 Message msg = mMainThreadHandler.obtainMessage(command, request);
1357 msg.sendToTarget();
1358 }
1359
1360 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 * Initialize the singleton PhoneInterfaceManager instance.
1362 * This is only done once, at startup, from PhoneApp.onCreate().
1363 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001364 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365 synchronized (PhoneInterfaceManager.class) {
1366 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001367 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001368 } else {
1369 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1370 }
1371 return sInstance;
1372 }
1373 }
1374
1375 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001376 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001379 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1381 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001382 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001383 mTelephonySharedPreferences =
1384 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001385 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001386 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001387
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001388 publish();
1389 }
1390
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001391 private Phone getDefaultPhone() {
1392 Phone thePhone = getPhone(getDefaultSubscription());
1393 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1394 }
1395
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 private void publish() {
1397 if (DBG) log("publish: " + this);
1398
1399 ServiceManager.addService("phone", this);
1400 }
1401
Stuart Scott584921c2015-01-15 17:10:34 -08001402 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001403 if (request.phone != null) {
1404 return request.phone;
1405 } else {
1406 return getPhoneFromSubId(request.subId);
1407 }
1408 }
1409
1410 private Phone getPhoneFromSubId(int subId) {
1411 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1412 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001413 }
1414
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001415 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1416 Phone phone = getPhoneFromRequest(request);
1417 return phone == null ? null :
1418 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1419 }
1420
Wink Saville36469e72014-06-11 15:17:00 -07001421 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001422 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001423 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425
1426 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001427 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001428 }
1429
Wink Savilleb564aae2014-10-23 10:18:09 -07001430 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 if (DBG) log("dial: " + number);
1432 // No permission check needed here: This is just a wrapper around the
1433 // ACTION_DIAL intent, which is available to any app since it puts up
1434 // the UI before it does anything.
1435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001436 final long identity = Binder.clearCallingIdentity();
1437 try {
1438 String url = createTelUrl(number);
1439 if (url == null) {
1440 return;
1441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001443 // PENDING: should we just silently fail if phone is offhook or ringing?
1444 PhoneConstants.State state = mCM.getState(subId);
1445 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1446 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1447 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1448 mApp.startActivity(intent);
1449 }
1450 } finally {
1451 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001452 }
1453 }
1454
1455 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001456 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001457 }
1458
Wink Savilleb564aae2014-10-23 10:18:09 -07001459 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 if (DBG) log("call: " + number);
1461
1462 // This is just a wrapper around the ACTION_CALL intent, but we still
1463 // need to do a permission check since we're calling startActivity()
1464 // from the context of the phone app.
1465 enforceCallPermission();
1466
Jordan Liu1617b712019-07-10 15:06:26 -07001467 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468 != AppOpsManager.MODE_ALLOWED) {
1469 return;
1470 }
1471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001472 final long identity = Binder.clearCallingIdentity();
1473 try {
1474 String url = createTelUrl(number);
1475 if (url == null) {
1476 return;
1477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001479 boolean isValid = false;
1480 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1481 if (slist != null) {
1482 for (SubscriptionInfo subInfoRecord : slist) {
1483 if (subInfoRecord.getSubscriptionId() == subId) {
1484 isValid = true;
1485 break;
1486 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001487 }
Wink Saville08874612014-08-31 19:19:58 -07001488 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001489 if (!isValid) {
1490 return;
1491 }
Wink Saville08874612014-08-31 19:19:58 -07001492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001493 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1494 intent.putExtra(SUBSCRIPTION_KEY, subId);
1495 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1496 mApp.startActivity(intent);
1497 } finally {
1498 Binder.restoreCallingIdentity(identity);
1499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001500 }
1501
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001502 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001503 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001504 }
1505
Wink Savilleb564aae2014-10-23 10:18:09 -07001506 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001507 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001508 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1509 }
1510
1511 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001512 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001513 }
1514
Wink Savilleb564aae2014-10-23 10:18:09 -07001515 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001516 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001517 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1518 }
1519
1520 /** {@hide} */
1521 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001522 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001523 }
1524
Wink Savilleb564aae2014-10-23 10:18:09 -07001525 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001527
1528 final long identity = Binder.clearCallingIdentity();
1529 try {
1530 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1531 checkSimPin.start();
1532 return checkSimPin.unlockSim(null, pin);
1533 } finally {
1534 Binder.restoreCallingIdentity(identity);
1535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 }
1537
Wink Saville9de0f752013-10-22 19:04:03 -07001538 /** {@hide} */
1539 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001540 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001545
1546 final long identity = Binder.clearCallingIdentity();
1547 try {
1548 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1549 checkSimPuk.start();
1550 return checkSimPuk.unlockSim(puk, pin);
1551 } finally {
1552 Binder.restoreCallingIdentity(identity);
1553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 }
1555
1556 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001557 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001558 * a synchronous one.
1559 */
1560 private static class UnlockSim extends Thread {
1561
1562 private final IccCard mSimCard;
1563
1564 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001565 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1566 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567
1568 // For replies from SimCard interface
1569 private Handler mHandler;
1570
1571 // For async handler to identify request type
1572 private static final int SUPPLY_PIN_COMPLETE = 100;
1573
1574 public UnlockSim(IccCard simCard) {
1575 mSimCard = simCard;
1576 }
1577
1578 @Override
1579 public void run() {
1580 Looper.prepare();
1581 synchronized (UnlockSim.this) {
1582 mHandler = new Handler() {
1583 @Override
1584 public void handleMessage(Message msg) {
1585 AsyncResult ar = (AsyncResult) msg.obj;
1586 switch (msg.what) {
1587 case SUPPLY_PIN_COMPLETE:
1588 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1589 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001590 mRetryCount = msg.arg1;
1591 if (ar.exception != null) {
1592 if (ar.exception instanceof CommandException &&
1593 ((CommandException)(ar.exception)).getCommandError()
1594 == CommandException.Error.PASSWORD_INCORRECT) {
1595 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1596 } else {
1597 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1598 }
1599 } else {
1600 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001602 mDone = true;
1603 UnlockSim.this.notifyAll();
1604 }
1605 break;
1606 }
1607 }
1608 };
1609 UnlockSim.this.notifyAll();
1610 }
1611 Looper.loop();
1612 }
1613
1614 /*
1615 * Use PIN or PUK to unlock SIM card
1616 *
1617 * If PUK is null, unlock SIM card with PIN
1618 *
1619 * If PUK is not null, unlock SIM card with PUK and set PIN code
1620 */
Wink Saville9de0f752013-10-22 19:04:03 -07001621 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622
1623 while (mHandler == null) {
1624 try {
1625 wait();
1626 } catch (InterruptedException e) {
1627 Thread.currentThread().interrupt();
1628 }
1629 }
1630 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1631
1632 if (puk == null) {
1633 mSimCard.supplyPin(pin, callback);
1634 } else {
1635 mSimCard.supplyPuk(puk, pin, callback);
1636 }
1637
1638 while (!mDone) {
1639 try {
1640 Log.d(LOG_TAG, "wait for done");
1641 wait();
1642 } catch (InterruptedException e) {
1643 // Restore the interrupted status
1644 Thread.currentThread().interrupt();
1645 }
1646 }
1647 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001648 int[] resultArray = new int[2];
1649 resultArray[0] = mResult;
1650 resultArray[1] = mRetryCount;
1651 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 }
1653 }
1654
1655 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001656 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001657
1658 }
1659
Wink Savilleb564aae2014-10-23 10:18:09 -07001660 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 // No permission check needed here: this call is harmless, and it's
1662 // needed for the ServiceState.requestStateUpdate() call (which is
1663 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001664 final long identity = Binder.clearCallingIdentity();
1665 try {
1666 final Phone phone = getPhone(subId);
1667 if (phone != null) {
1668 phone.updateServiceLocation();
1669 }
1670 } finally {
1671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 }
1674
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001675 @Override
1676 public boolean isRadioOn(String callingPackage) {
1677 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001678 }
1679
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001680 @Override
1681 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001683 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001684 return false;
1685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001686
1687 final long identity = Binder.clearCallingIdentity();
1688 try {
1689 return isRadioOnForSubscriber(subId);
1690 } finally {
1691 Binder.restoreCallingIdentity(identity);
1692 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001693 }
1694
1695 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001696 final long identity = Binder.clearCallingIdentity();
1697 try {
1698 final Phone phone = getPhone(subId);
1699 if (phone != null) {
1700 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1701 } else {
1702 return false;
1703 }
1704 } finally {
1705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 }
1708
1709 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001710 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 }
Wink Saville36469e72014-06-11 15:17:00 -07001712
Wink Savilleb564aae2014-10-23 10:18:09 -07001713 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715
1716 final long identity = Binder.clearCallingIdentity();
1717 try {
1718 final Phone phone = getPhone(subId);
1719 if (phone != null) {
1720 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1721 }
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 }
Wink Saville36469e72014-06-11 15:17:00 -07001725 }
1726
1727 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001728 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001729 }
1730
Wink Savilleb564aae2014-10-23 10:18:09 -07001731 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001732 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001733
1734 final long identity = Binder.clearCallingIdentity();
1735 try {
1736 final Phone phone = getPhone(subId);
1737 if (phone == null) {
1738 return false;
1739 }
1740 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1741 toggleRadioOnOffForSubscriber(subId);
1742 }
1743 return true;
1744 } finally {
1745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 }
Wink Saville36469e72014-06-11 15:17:00 -07001748
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001749 public boolean needMobileRadioShutdown() {
1750 /*
1751 * If any of the Radios are available, it will need to be
1752 * shutdown. So return true if any Radio is available.
1753 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001754 final long identity = Binder.clearCallingIdentity();
1755 try {
1756 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1757 Phone phone = PhoneFactory.getPhone(i);
1758 if (phone != null && phone.isRadioAvailable()) return true;
1759 }
1760 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1761 return false;
1762 } finally {
1763 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001764 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001765 }
1766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001767 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001768 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001769 enforceModifyPermission();
1770
1771 final long identity = Binder.clearCallingIdentity();
1772 try {
1773 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1774 logv("Shutting down Phone " + i);
1775 shutdownRadioUsingPhoneId(i);
1776 }
1777 } finally {
1778 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001779 }
1780 }
1781
1782 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001783 Phone phone = PhoneFactory.getPhone(phoneId);
1784 if (phone != null && phone.isRadioAvailable()) {
1785 phone.shutdownRadio();
1786 }
1787 }
1788
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001790 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001791
1792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1795 if (defaultPhone != null) {
1796 defaultPhone.setRadioPower(turnOn);
1797 return true;
1798 } else {
1799 loge("There's no default phone.");
1800 return false;
1801 }
1802 } finally {
1803 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001804 }
Wink Saville36469e72014-06-11 15:17:00 -07001805 }
1806
Wink Savilleb564aae2014-10-23 10:18:09 -07001807 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001809
1810 final long identity = Binder.clearCallingIdentity();
1811 try {
1812 final Phone phone = getPhone(subId);
1813 if (phone != null) {
1814 phone.setRadioPower(turnOn);
1815 return true;
1816 } else {
1817 return false;
1818 }
1819 } finally {
1820 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001821 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 }
1823
Wink Saville36469e72014-06-11 15:17:00 -07001824 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001825 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 public boolean enableDataConnectivity() {
1827 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001828
1829 final long identity = Binder.clearCallingIdentity();
1830 try {
1831 int subId = mSubscriptionController.getDefaultDataSubId();
1832 final Phone phone = getPhone(subId);
1833 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001834 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001835 return true;
1836 } else {
1837 return false;
1838 }
1839 } finally {
1840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 }
1843
Wink Saville36469e72014-06-11 15:17:00 -07001844 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001845 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 public boolean disableDataConnectivity() {
1847 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001848
1849 final long identity = Binder.clearCallingIdentity();
1850 try {
1851 int subId = mSubscriptionController.getDefaultDataSubId();
1852 final Phone phone = getPhone(subId);
1853 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001854 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001855 return true;
1856 } else {
1857 return false;
1858 }
1859 } finally {
1860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001862 }
1863
Sanket Padawe356d7632015-06-22 14:03:32 -07001864 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001865 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001866 final long identity = Binder.clearCallingIdentity();
1867 try {
1868 final Phone phone = getPhone(subId);
1869 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001870 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001871 } else {
1872 return false;
1873 }
1874 } finally {
1875 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 }
1878
1879 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001880 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001881 }
1882
pkanwarae03a6b2016-11-06 20:37:09 -08001883 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001884 enforceCallPermission();
1885
1886 final long identity = Binder.clearCallingIdentity();
1887 try {
1888 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1889 return;
1890 }
1891 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1892 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1893 } finally {
1894 Binder.restoreCallingIdentity(identity);
1895 }
pkanwar32d516d2016-10-14 19:37:38 -07001896 };
1897
Wink Savilleb564aae2014-10-23 10:18:09 -07001898 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001900
1901 final long identity = Binder.clearCallingIdentity();
1902 try {
1903 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1904 return false;
1905 }
1906 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1907 } finally {
1908 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 }
1911
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001912 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001913 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001914 }
1915
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001916 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001917 final long identity = Binder.clearCallingIdentity();
1918 try {
1919 Phone phone = PhoneFactory.getPhone(slotIndex);
1920 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1921 PhoneConstantConversions.convertCallState(phone.getState());
1922 } finally {
1923 Binder.restoreCallingIdentity(identity);
1924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 }
1926
Sanket Padawe356d7632015-06-22 14:03:32 -07001927 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001928 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001929 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1930 }
1931
1932 @Override
1933 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001934 final long identity = Binder.clearCallingIdentity();
1935 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001936 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001937 if (phone != null) {
1938 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1939 } else {
1940 return PhoneConstantConversions.convertDataState(
1941 PhoneConstants.DataState.DISCONNECTED);
1942 }
1943 } finally {
1944 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 }
1947
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001949 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001950 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1951 }
1952
1953 @Override
1954 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001955 final long identity = Binder.clearCallingIdentity();
1956 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001957 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001958 if (phone != null) {
1959 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1960 } else {
1961 return TelephonyManager.DATA_ACTIVITY_NONE;
1962 }
1963 } finally {
1964 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 }
1967
1968 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001969 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001970 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001971 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001972
1973 LocationAccessPolicy.LocationPermissionResult locationResult =
1974 LocationAccessPolicy.checkLocationPermission(mApp,
1975 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1976 .setCallingPackage(callingPackage)
1977 .setCallingPid(Binder.getCallingPid())
1978 .setCallingUid(Binder.getCallingUid())
1979 .setMethod("getCellLocation")
1980 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1981 .build());
1982 switch (locationResult) {
1983 case DENIED_HARD:
1984 throw new SecurityException("Not allowed to access cell location");
1985 case DENIED_SOFT:
1986 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 }
1988
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001989 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001990 final long identity = Binder.clearCallingIdentity();
1991 try {
1992 if (DBG_LOC) log("getCellLocation: is active user");
1993 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001994 int subId = mSubscriptionController.getDefaultDataSubId();
1995 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1996 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001997 return data;
1998 } finally {
1999 Binder.restoreCallingIdentity(identity);
2000 }
Svetoslav64fad262015-04-14 14:35:21 -07002001 }
2002
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002004 public String getNetworkCountryIsoForPhone(int phoneId) {
2005 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2006 // registered cell info, so return a NULL country instead.
2007 final long identity = Binder.clearCallingIdentity();
2008 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002009 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2010 // Get default phone in this case.
2011 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2012 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002013 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002014 // Todo: fix this when we can get the actual cellular network info when the device
2015 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002016 if (TelephonyManager.NETWORK_TYPE_IWLAN
2017 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2018 return "";
2019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020 Phone phone = PhoneFactory.getPhone(phoneId);
2021 if (phone != null) {
2022 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002023 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002024 if (sst != null) {
2025 LocaleTracker lt = sst.getLocaleTracker();
2026 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002027 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2028 return lt.getCurrentCountry();
2029 } else if (emergencyNumberTracker != null) {
2030 return emergencyNumberTracker.getEmergencyCountryIso();
2031 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002032 }
2033 }
2034 }
2035 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002036 } finally {
2037 Binder.restoreCallingIdentity(identity);
2038 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002039 }
2040
2041 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002042 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002043 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002044 }
2045
Sanket Padawe356d7632015-06-22 14:03:32 -07002046 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002047 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048 mApp.enforceCallingOrSelfPermission(
2049 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002050
2051 final long identity = Binder.clearCallingIdentity();
2052 try {
2053 final Phone phone = getPhone(subId);
2054 if (phone != null) {
2055 phone.enableLocationUpdates();
2056 }
2057 } finally {
2058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002060 }
2061
2062 @Override
2063 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002064 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002065 }
2066
Sanket Padawe356d7632015-06-22 14:03:32 -07002067 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002068 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069 mApp.enforceCallingOrSelfPermission(
2070 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002071
2072 final long identity = Binder.clearCallingIdentity();
2073 try {
2074 final Phone phone = getPhone(subId);
2075 if (phone != null) {
2076 phone.disableLocationUpdates();
2077 }
2078 } finally {
2079 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 }
2082
Nathan Harold31d7ff32018-10-15 20:20:30 -07002083 /**
2084 * Returns the target SDK version number for a given package name.
2085 *
Nathan Haroldec184742019-07-10 17:04:16 -07002086 * This call MUST be invoked before clearing the calling UID.
2087 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002088 * @return target SDK if the package is found or INT_MAX.
2089 */
2090 private int getTargetSdk(String packageName) {
2091 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002092 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002093 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002094 if (ai != null) return ai.targetSdkVersion;
2095 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002096 loge("Failed to get package info for pkg="
2097 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002098 }
2099 return Integer.MAX_VALUE;
2100 }
2101
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 @Override
2103 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002104 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2105 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002106 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2107 throw new SecurityException(
2108 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2109 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002110
Jordan Liu1617b712019-07-10 15:06:26 -07002111 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2113 return null;
2114 }
Svetoslav64fad262015-04-14 14:35:21 -07002115
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002116 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002117
Nathan Haroldf180aac2018-06-01 18:43:55 -07002118 List<CellInfo> info = getAllCellInfo(callingPackage);
2119 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120
Nathan Haroldf180aac2018-06-01 18:43:55 -07002121 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2122 for (CellInfo ci : info) {
2123 if (ci instanceof CellInfoGsm) {
2124 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2125 } else if (ci instanceof CellInfoWcdma) {
2126 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002129 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002130 }
2131
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002132 private List<CellInfo> getCachedCellInfo() {
2133 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2134 for (Phone phone : PhoneFactory.getPhones()) {
2135 List<CellInfo> info = phone.getAllCellInfo();
2136 if (info != null) cellInfos.addAll(info);
2137 }
2138 return cellInfos;
2139 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140
2141 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002142 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002143 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002144 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002145
2146 LocationAccessPolicy.LocationPermissionResult locationResult =
2147 LocationAccessPolicy.checkLocationPermission(mApp,
2148 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2149 .setCallingPackage(callingPackage)
2150 .setCallingPid(Binder.getCallingPid())
2151 .setCallingUid(Binder.getCallingUid())
2152 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002153 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002154 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2155 .build());
2156 switch (locationResult) {
2157 case DENIED_HARD:
2158 throw new SecurityException("Not allowed to access cell info");
2159 case DENIED_SOFT:
2160 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 }
2162
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002163 final int targetSdk = getTargetSdk(callingPackage);
2164 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2165 return getCachedCellInfo();
2166 }
2167
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002168 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002169 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2173 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002174 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002175 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176 if (info != null) cellInfos.addAll(info);
2177 }
2178 return cellInfos;
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
2182 }
2183
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002184 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002185 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2186 requestCellInfoUpdateInternal(
2187 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2188 }
2189
2190 @Override
2191 public void requestCellInfoUpdateWithWorkSource(
2192 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2193 enforceModifyPermission();
2194 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2195 }
2196
2197 private void requestCellInfoUpdateInternal(
2198 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002199 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002200 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002201
2202 LocationAccessPolicy.LocationPermissionResult locationResult =
2203 LocationAccessPolicy.checkLocationPermission(mApp,
2204 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2205 .setCallingPackage(callingPackage)
2206 .setCallingPid(Binder.getCallingPid())
2207 .setCallingUid(Binder.getCallingUid())
2208 .setMethod("requestCellInfoUpdate")
2209 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2210 .build());
2211 switch (locationResult) {
2212 case DENIED_HARD:
2213 throw new SecurityException("Not allowed to access cell info");
2214 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002215 try {
2216 cb.onCellInfo(new ArrayList<CellInfo>());
2217 } catch (RemoteException re) {
2218 // Drop without consequences
2219 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002220 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002221 }
2222
Nathan Harolda939a962019-05-09 10:13:47 -07002223
2224 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002225 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2226
2227 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2228 }
2229
2230 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002232 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002233 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002234
2235 final long identity = Binder.clearCallingIdentity();
2236 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002237 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238 } finally {
2239 Binder.restoreCallingIdentity(identity);
2240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 }
2242
Shishir Agrawala9f32182016-04-12 12:00:16 -07002243 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002244 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002245 Phone phone = PhoneFactory.getPhone(slotIndex);
2246 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002247 return null;
2248 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002249 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002250 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2251 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002252 return null;
2253 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002254
2255 final long identity = Binder.clearCallingIdentity();
2256 try {
2257 return phone.getImei();
2258 } finally {
2259 Binder.restoreCallingIdentity(identity);
2260 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002261 }
2262
2263 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002264 public String getTypeAllocationCodeForSlot(int slotIndex) {
2265 Phone phone = PhoneFactory.getPhone(slotIndex);
2266 String tac = null;
2267 if (phone != null) {
2268 String imei = phone.getImei();
2269 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2270 }
2271 return tac;
2272 }
2273
2274 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002275 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002276 Phone phone = PhoneFactory.getPhone(slotIndex);
2277 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002278 return null;
2279 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002280
Jeff Davidson913390f2018-02-23 17:11:49 -08002281 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002282 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2283 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002284 return null;
2285 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286
2287 final long identity = Binder.clearCallingIdentity();
2288 try {
2289 return phone.getMeid();
2290 } finally {
2291 Binder.restoreCallingIdentity(identity);
2292 }
Jack Yu2af8d712017-03-15 17:14:14 -07002293 }
2294
2295 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002296 public String getManufacturerCodeForSlot(int slotIndex) {
2297 Phone phone = PhoneFactory.getPhone(slotIndex);
2298 String manufacturerCode = null;
2299 if (phone != null) {
2300 String meid = phone.getMeid();
2301 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2302 }
2303 return manufacturerCode;
2304 }
2305
2306 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002307 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002308 Phone phone = PhoneFactory.getPhone(slotIndex);
2309 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002310 return null;
2311 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002312 int subId = phone.getSubId();
2313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2314 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2315 return null;
2316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002317
2318 final long identity = Binder.clearCallingIdentity();
2319 try {
2320 return phone.getDeviceSvn();
2321 } finally {
2322 Binder.restoreCallingIdentity(identity);
2323 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002324 }
2325
fionaxu43304da2017-11-27 22:51:16 -08002326 @Override
2327 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 final Phone phone = getPhone(subId);
2331 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2332 } finally {
2333 Binder.restoreCallingIdentity(identity);
2334 }
fionaxu43304da2017-11-27 22:51:16 -08002335 }
2336
2337 @Override
2338 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002339 final long identity = Binder.clearCallingIdentity();
2340 try {
2341 final Phone phone = getPhone(subId);
2342 return phone == null ? null : phone.getCarrierName();
2343 } finally {
2344 Binder.restoreCallingIdentity(identity);
2345 }
fionaxu43304da2017-11-27 22:51:16 -08002346 }
2347
calvinpanffe225e2018-11-01 19:43:06 +08002348 @Override
chen xu0026ca62019-03-06 15:28:50 -08002349 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002350 final long identity = Binder.clearCallingIdentity();
2351 try {
2352 final Phone phone = getPhone(subId);
2353 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002354 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002355 } finally {
2356 Binder.restoreCallingIdentity(identity);
2357 }
2358 }
2359
2360 @Override
chen xu0026ca62019-03-06 15:28:50 -08002361 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002362 final long identity = Binder.clearCallingIdentity();
2363 try {
2364 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002365 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002366 } finally {
2367 Binder.restoreCallingIdentity(identity);
2368 }
2369 }
2370
chen xu651eec72018-11-11 19:03:44 -08002371 @Override
chen xu864e11c2018-12-06 22:10:03 -08002372 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2373 if (!isSubscriptionMccMnc) {
2374 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2375 }
chen xu651eec72018-11-11 19:03:44 -08002376 final Phone phone = PhoneFactory.getPhone(slotIndex);
2377 if (phone == null) {
2378 return TelephonyManager.UNKNOWN_CARRIER_ID;
2379 }
2380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2383 } finally {
2384 Binder.restoreCallingIdentity(identity);
2385 }
2386 }
2387
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 //
2389 // Internal helper methods.
2390 //
2391
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002392 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2394 *
2395 * @throws SecurityException if the caller does not have the required permission
2396 */
2397 private void enforceModifyPermission() {
2398 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2399 }
2400
2401 /**
2402 * Make sure the caller has the CALL_PHONE permission.
2403 *
2404 * @throws SecurityException if the caller does not have the required permission
2405 */
2406 private void enforceCallPermission() {
2407 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2408 }
2409
Stuart Scott8eef64f2015-04-08 15:13:54 -07002410 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002411 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002412 "ConnectivityService");
2413 }
2414
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415 private String createTelUrl(String number) {
2416 if (TextUtils.isEmpty(number)) {
2417 return null;
2418 }
2419
Jake Hambye994d462014-02-03 13:10:13 -08002420 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 }
2422
Ihab Awadf9e92732013-12-05 18:02:52 -08002423 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2425 }
2426
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002427 private static void logv(String msg) {
2428 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2429 }
2430
Ihab Awadf9e92732013-12-05 18:02:52 -08002431 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2433 }
2434
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002435 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002437 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002438 }
2439
Sanket Padawe356d7632015-06-22 14:03:32 -07002440 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002441 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002442 final long identity = Binder.clearCallingIdentity();
2443 try {
2444 final Phone phone = PhoneFactory.getPhone(slotIndex);
2445 if (phone == null) {
2446 return PhoneConstants.PHONE_TYPE_NONE;
2447 } else {
2448 return phone.getPhoneType();
2449 }
2450 } finally {
2451 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002452 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 }
2454
2455 /**
2456 * Returns the CDMA ERI icon index to display
2457 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002458 @Override
2459 public int getCdmaEriIconIndex(String callingPackage) {
2460 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002461 }
2462
Sanket Padawe356d7632015-06-22 14:03:32 -07002463 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002464 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002466 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002467 return -1;
2468 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469
2470 final long identity = Binder.clearCallingIdentity();
2471 try {
2472 final Phone phone = getPhone(subId);
2473 if (phone != null) {
2474 return phone.getCdmaEriIconIndex();
2475 } else {
2476 return -1;
2477 }
2478 } finally {
2479 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 }
2482
2483 /**
2484 * Returns the CDMA ERI icon mode,
2485 * 0 - ON
2486 * 1 - FLASHING
2487 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002488 @Override
2489 public int getCdmaEriIconMode(String callingPackage) {
2490 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002491 }
2492
Sanket Padawe356d7632015-06-22 14:03:32 -07002493 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002494 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002495 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002496 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002497 return -1;
2498 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499
2500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 final Phone phone = getPhone(subId);
2503 if (phone != null) {
2504 return phone.getCdmaEriIconMode();
2505 } else {
2506 return -1;
2507 }
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 }
2512
2513 /**
2514 * Returns the CDMA ERI text,
2515 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002516 @Override
2517 public String getCdmaEriText(String callingPackage) {
2518 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002519 }
2520
Sanket Padawe356d7632015-06-22 14:03:32 -07002521 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002522 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002524 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002525 return null;
2526 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527
2528 final long identity = Binder.clearCallingIdentity();
2529 try {
2530 final Phone phone = getPhone(subId);
2531 if (phone != null) {
2532 return phone.getCdmaEriText();
2533 } else {
2534 return null;
2535 }
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539 }
2540
2541 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002542 * Returns the CDMA MDN.
2543 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002544 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002545 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2547 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548
2549 final long identity = Binder.clearCallingIdentity();
2550 try {
2551 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002552 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002553 return phone.getLine1Number();
2554 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002555 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556 return null;
2557 }
2558 } finally {
2559 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002560 }
2561 }
2562
2563 /**
2564 * Returns the CDMA MIN.
2565 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002566 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002567 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2569 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 final Phone phone = getPhone(subId);
2574 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2575 return phone.getCdmaMin();
2576 } else {
2577 return null;
2578 }
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002581 }
2582 }
2583
Hall Liud892bec2018-11-30 14:51:45 -08002584 @Override
2585 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2586 INumberVerificationCallback callback, String callingPackage) {
2587 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2588 != PERMISSION_GRANTED) {
2589 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2590 }
2591 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2592
2593 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2594 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2595 throw new SecurityException("Calling package must be configured in the device config");
2596 }
2597
2598 if (range == null) {
2599 throw new NullPointerException("Range must be non-null");
2600 }
2601
2602 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002603 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002604
2605 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2606 }
2607
Junda Liuca05d5d2014-08-14 22:36:34 -07002608 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 * Returns true if CDMA provisioning needs to run.
2610 */
2611 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 final long identity = Binder.clearCallingIdentity();
2613 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002614 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 } finally {
2616 Binder.restoreCallingIdentity(identity);
2617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 }
2619
2620 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002621 * Sets the voice mail number of a given subId.
2622 */
2623 @Override
2624 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002625 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2630 new Pair<String, String>(alphaTag, number), new Integer(subId));
2631 return success;
2632 } finally {
2633 Binder.restoreCallingIdentity(identity);
2634 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002635 }
2636
Ta-wei Yen87c49842016-05-13 21:19:52 -07002637 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002638 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2639 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002640 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002641 if (!TextUtils.equals(callingPackage, systemDialer)) {
2642 throw new SecurityException("caller must be system dialer");
2643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644
2645 final long identity = Binder.clearCallingIdentity();
2646 try {
2647 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2648 if (phoneAccountHandle == null) {
2649 return null;
2650 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002651 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652 } finally {
2653 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002654 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002655 }
2656
2657 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002658 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002659 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002661 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002662 return null;
2663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002664
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002665 final long identity = Binder.clearCallingIdentity();
2666 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002667 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002668 } finally {
2669 Binder.restoreCallingIdentity(identity);
2670 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002671 }
2672
2673 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002674 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2675 VisualVoicemailSmsFilterSettings settings) {
2676 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002677
2678 final long identity = Binder.clearCallingIdentity();
2679 try {
2680 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002681 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682 } finally {
2683 Binder.restoreCallingIdentity(identity);
2684 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002685 }
2686
2687 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002688 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2689 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690
2691 final long identity = Binder.clearCallingIdentity();
2692 try {
2693 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002694 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695 } finally {
2696 Binder.restoreCallingIdentity(identity);
2697 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002698 }
2699
2700 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002701 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2702 String callingPackage, int subId) {
2703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704
2705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002708 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709 } finally {
2710 Binder.restoreCallingIdentity(identity);
2711 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002712 }
2713
2714 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002715 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002716 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717
2718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002721 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 } finally {
2723 Binder.restoreCallingIdentity(identity);
2724 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002725 }
2726
2727 @Override
2728 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2729 String number, int port, String text, PendingIntent sentIntent) {
2730 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002731 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002732 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002733 SmsController smsController = PhoneFactory.getSmsController();
2734 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2735 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002736 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002737
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002738 /**
fionaxu0152e512016-11-14 13:36:14 -08002739 * Sets the voice activation state of a given subId.
2740 */
2741 @Override
2742 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2744 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002745
2746 final long identity = Binder.clearCallingIdentity();
2747 try {
2748 final Phone phone = getPhone(subId);
2749 if (phone != null) {
2750 phone.setVoiceActivationState(activationState);
2751 } else {
2752 loge("setVoiceActivationState fails with invalid subId: " + subId);
2753 }
2754 } finally {
2755 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002756 }
2757 }
2758
2759 /**
2760 * Sets the data activation state of a given subId.
2761 */
2762 @Override
2763 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2765 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766
2767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 final Phone phone = getPhone(subId);
2770 if (phone != null) {
2771 phone.setDataActivationState(activationState);
2772 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002773 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774 }
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002777 }
2778 }
2779
2780 /**
2781 * Returns the voice activation state of a given subId.
2782 */
2783 @Override
2784 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002785 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786
fionaxu0152e512016-11-14 13:36:14 -08002787 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 if (phone != null) {
2791 return phone.getVoiceActivationState();
2792 } else {
2793 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2794 }
2795 } finally {
2796 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002797 }
2798 }
2799
2800 /**
2801 * Returns the data activation state of a given subId.
2802 */
2803 @Override
2804 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002805 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806
fionaxu0152e512016-11-14 13:36:14 -08002807 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808 final long identity = Binder.clearCallingIdentity();
2809 try {
2810 if (phone != null) {
2811 return phone.getDataActivationState();
2812 } else {
2813 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2814 }
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002817 }
2818 }
2819
2820 /**
Wink Saville36469e72014-06-11 15:17:00 -07002821 * Returns the unread count of voicemails for a subId
2822 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002823 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002824 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2826 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2827 return 0;
2828 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829 final long identity = Binder.clearCallingIdentity();
2830 try {
2831 final Phone phone = getPhone(subId);
2832 if (phone != null) {
2833 return phone.getVoiceMessageCount();
2834 } else {
2835 return 0;
2836 }
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002840 }
2841
2842 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002843 * returns true, if the device is in a state where both voice and data
2844 * are supported simultaneously. This can change based on location or network condition.
2845 */
2846 @Override
2847 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 final Phone phone = getPhone(subId);
2851 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
2854 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002855 }
2856
2857 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002858 * Send the dialer code if called from the current default dialer or the caller has
2859 * carrier privilege.
2860 * @param inputCode The dialer code to send
2861 */
2862 @Override
2863 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002864 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002865 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002866 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2867 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002868 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002869 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2870 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002871 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872
2873 final long identity = Binder.clearCallingIdentity();
2874 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002875 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 } finally {
2877 Binder.restoreCallingIdentity(identity);
2878 }
fionaxu235cc5e2017-03-06 22:25:57 -08002879 }
2880
Pengquan Menga1bb6272018-09-06 09:59:22 -07002881 @Override
2882 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002883 if (!isActiveSubscription(subId)) {
2884 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2885 }
2886
Pengquan Menga1bb6272018-09-06 09:59:22 -07002887 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2888 }
2889
Brad Ebinger35c841c2018-10-01 10:40:55 -07002890 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002891 public boolean isInEmergencySmsMode() {
2892 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2893 final long identity = Binder.clearCallingIdentity();
2894 try {
2895 for (Phone phone : PhoneFactory.getPhones()) {
2896 if (phone.isInEmergencySmsMode()) {
2897 return true;
2898 }
2899 }
2900 } finally {
2901 Binder.restoreCallingIdentity(identity);
2902 }
2903 return false;
2904 }
2905
2906 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002907 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2908 throws RemoteException {
2909 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002910 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2911 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2912 "IMS not available on device.");
2913 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002914 final long token = Binder.clearCallingIdentity();
2915 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002917 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002918 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002919 } catch (ImsException e) {
2920 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002921 } finally {
2922 Binder.restoreCallingIdentity(token);
2923 }
2924 }
2925
2926 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002927 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2928 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002929 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2930 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2931 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002932 final long token = Binder.clearCallingIdentity();
2933 try {
2934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2935 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2936 .removeRegistrationCallbackForSubscription(c, subId);
2937 } catch (ImsException e) {
2938 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2939 + "is inactive, ignoring unregister.");
2940 // If the subscription is no longer active, just return, since the callback
2941 // will already have been removed internally.
2942 } finally {
2943 Binder.restoreCallingIdentity(token);
2944 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002945 }
2946
Brad Ebinger774ba362019-10-22 17:36:18 -07002947 /**
2948 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2949 */
2950 @Override
2951 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2952 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2953 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2954 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2955 "IMS not available on device.");
2956 }
2957 final long token = Binder.clearCallingIdentity();
2958 try {
2959 Phone phone = getPhone(subId);
2960 if (phone == null) {
2961 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2962 + subId + "'");
2963 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
2964 }
2965 phone.getImsRegistrationState(regState -> {
2966 try {
2967 consumer.accept((regState == null)
2968 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
2969 } catch (RemoteException e) {
2970 // Ignore if the remote process is no longer available to call back.
2971 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
2972 }
2973 });
2974 } finally {
2975 Binder.restoreCallingIdentity(token);
2976 }
2977 }
2978
2979 /**
2980 * Get the transport type for the IMS service registration state.
2981 */
2982 @Override
2983 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
2984 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
2985 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2986 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2987 "IMS not available on device.");
2988 }
2989 final long token = Binder.clearCallingIdentity();
2990 try {
2991 Phone phone = getPhone(subId);
2992 if (phone == null) {
2993 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2994 + subId + "'");
2995 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
2996 }
2997 phone.getImsRegistrationTech(regTech -> {
2998 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
2999 int regTechConverted = (regTech == null)
3000 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3001 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3002 regTechConverted);
3003 try {
3004 consumer.accept(regTechConverted);
3005 } catch (RemoteException e) {
3006 // Ignore if the remote process is no longer available to call back.
3007 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3008 }
3009 });
3010 } finally {
3011 Binder.restoreCallingIdentity(token);
3012 }
3013 }
3014
Brad Ebinger35c841c2018-10-01 10:40:55 -07003015 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003016 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3017 throws RemoteException {
3018 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003019 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3020 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3021 "IMS not available on device.");
3022 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003023 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3024 final long token = Binder.clearCallingIdentity();
3025 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003026 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003027 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003028 } catch (ImsException e) {
3029 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003030 } finally {
3031 Binder.restoreCallingIdentity(token);
3032 }
3033 }
3034
3035 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003036 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3037 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003038 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3039 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3040 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003041
3042 final long token = Binder.clearCallingIdentity();
3043 try {
3044 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3045 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003046 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003047 } catch (ImsException e) {
3048 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3049 + "is inactive, ignoring unregister.");
3050 // If the subscription is no longer active, just return, since the callback
3051 // will already have been removed internally.
3052 } finally {
3053 Binder.restoreCallingIdentity(token);
3054 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003055 }
3056
3057 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003058 public boolean isCapable(int subId, int capability, int regTech) {
3059 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003060 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3061 final long token = Binder.clearCallingIdentity();
3062 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003063 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003064 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003065 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003066 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3067 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003068 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003069 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3070 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003071 } finally {
3072 Binder.restoreCallingIdentity(token);
3073 }
3074 }
3075
3076 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003077 public boolean isAvailable(int subId, int capability, int regTech) {
3078 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003079 final long token = Binder.clearCallingIdentity();
3080 try {
3081 Phone phone = getPhone(subId);
3082 if (phone == null) return false;
3083 return phone.isImsCapabilityAvailable(capability, regTech);
3084 } finally {
3085 Binder.restoreCallingIdentity(token);
3086 }
3087 }
3088
Brad Ebinger77b832e2019-10-17 17:03:22 -07003089 /**
3090 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3091 * subscription.
3092 * @param subId The subscription to use to check the configuration.
3093 * @param callback The callback that will be used to send the result.
3094 * @param capability The MmTelFeature capability that will be used to send the result.
3095 * @param transportType The transport type of the MmTelFeature capability.
3096 */
3097 @Override
3098 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3099 int transportType) {
3100 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3101 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3102 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3103 "IMS not available on device.");
3104 }
3105 final long token = Binder.clearCallingIdentity();
3106 try {
3107 int slotId = getSlotIndex(subId);
3108 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3109 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3110 + subId + "'");
3111 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3112 }
3113 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3114 transportType, aBoolean -> {
3115 try {
3116 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3117 } catch (RemoteException e) {
3118 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3119 + "running. Ignore");
3120 }
3121 });
3122 } finally {
3123 Binder.restoreCallingIdentity(token);
3124 }
3125 }
3126
Brad Ebinger35c841c2018-10-01 10:40:55 -07003127 @Override
3128 public boolean isAdvancedCallingSettingEnabled(int subId) {
3129 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3130 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3131 final long token = Binder.clearCallingIdentity();
3132 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003133 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003134 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003135 } catch (ImsException e) {
3136 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003137 } finally {
3138 Binder.restoreCallingIdentity(token);
3139 }
3140 }
3141
3142 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003143 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003145 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003149 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003150 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003151 } catch (ImsException e) {
3152 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
3156 }
3157
3158 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003159 public boolean isVtSettingEnabled(int subId) {
3160 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003161 final long identity = Binder.clearCallingIdentity();
3162 try {
3163 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003164 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3165 } catch (ImsException e) {
3166 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003167 } finally {
3168 Binder.restoreCallingIdentity(identity);
3169 }
3170 }
3171
3172 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003173 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003175 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003176 final long identity = Binder.clearCallingIdentity();
3177 try {
3178 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003179 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003180 } catch (ImsException e) {
3181 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003182 } finally {
3183 Binder.restoreCallingIdentity(identity);
3184 }
3185 }
3186
3187 @Override
3188 public boolean isVoWiFiSettingEnabled(int subId) {
3189 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3190 final long identity = Binder.clearCallingIdentity();
3191 try {
3192 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003193 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003194 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003195 } catch (ImsException e) {
3196 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003197 } finally {
3198 Binder.restoreCallingIdentity(identity);
3199 }
3200 }
3201
3202 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003203 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003205 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003206 final long identity = Binder.clearCallingIdentity();
3207 try {
3208 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003209 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003210 } catch (ImsException e) {
3211 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003212 } finally {
3213 Binder.restoreCallingIdentity(identity);
3214 }
3215 }
3216
3217 @Override
3218 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3219 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3220 final long identity = Binder.clearCallingIdentity();
3221 try {
3222 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003223 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003224 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003225 } catch (ImsException e) {
3226 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003227 } finally {
3228 Binder.restoreCallingIdentity(identity);
3229 }
3230 }
3231
3232 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003233 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003235 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003236 final long identity = Binder.clearCallingIdentity();
3237 try {
3238 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003239 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003241 } catch (ImsException e) {
3242 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003243 } finally {
3244 Binder.restoreCallingIdentity(identity);
3245 }
3246 }
3247
3248 @Override
3249 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3251 "setVoWiFiNonPersistent");
3252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003255 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003256 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003257 } catch (ImsException e) {
3258 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003259 } finally {
3260 Binder.restoreCallingIdentity(identity);
3261 }
3262 }
3263
3264 @Override
3265 public int getVoWiFiModeSetting(int subId) {
3266 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3267 final long identity = Binder.clearCallingIdentity();
3268 try {
3269 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003270 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003271 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003272 } catch (ImsException e) {
3273 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 } finally {
3275 Binder.restoreCallingIdentity(identity);
3276 }
3277 }
3278
3279 @Override
3280 public void setVoWiFiModeSetting(int subId, int mode) {
3281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3282 "setVoWiFiModeSetting");
3283 final long identity = Binder.clearCallingIdentity();
3284 try {
3285 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003286 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003287 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003288 } catch (ImsException e) {
3289 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003290 } finally {
3291 Binder.restoreCallingIdentity(identity);
3292 }
3293 }
3294
3295 @Override
3296 public int getVoWiFiRoamingModeSetting(int subId) {
3297 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003301 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003302 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003303 } catch (ImsException e) {
3304 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003305 } finally {
3306 Binder.restoreCallingIdentity(identity);
3307 }
3308 }
3309
3310 @Override
3311 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3313 "setVoWiFiRoamingModeSetting");
3314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003317 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003318 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003319 } catch (ImsException e) {
3320 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
3324 }
3325
3326 @Override
3327 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3329 "setRttCapabilityEnabled");
3330 final long identity = Binder.clearCallingIdentity();
3331 try {
3332 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003333 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3334 } catch (ImsException e) {
3335 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003336 } finally {
3337 Binder.restoreCallingIdentity(identity);
3338 }
3339 }
3340
3341 @Override
3342 public boolean isTtyOverVolteEnabled(int subId) {
3343 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003347 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003348 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003349 } catch (ImsException e) {
3350 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003351 } finally {
3352 Binder.restoreCallingIdentity(identity);
3353 }
3354 }
3355
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003356 @Override
3357 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3358 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3359 final long identity = Binder.clearCallingIdentity();
3360 try {
3361 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003362 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003363 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003364 } catch (ImsException e) {
3365 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003366 } finally {
3367 Binder.restoreCallingIdentity(identity);
3368 }
3369 }
3370
3371 @Override
3372 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3373 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3374 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003375 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3376 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3377 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003378 try {
3379 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003380 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003381 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003382 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003383 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3384 + "is inactive, ignoring unregister.");
3385 // If the subscription is no longer active, just return, since the callback will already
3386 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003387 } finally {
3388 Binder.restoreCallingIdentity(identity);
3389 }
3390 }
3391
3392 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003393 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3394 boolean isProvisioned) {
3395 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3396 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3397 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3398 }
3399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3400 "setProvisioningStatusForCapability");
3401 final long identity = Binder.clearCallingIdentity();
3402 try {
3403 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3404 Phone phone = getPhone(subId);
3405 if (phone == null) {
3406 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3407 + subId);
3408 return;
3409 }
3410 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3411 return;
3412 }
3413
3414 // this capability requires provisioning, route to the correct API.
3415 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3416 switch (capability) {
3417 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3418 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3419 ims.setVolteProvisioned(isProvisioned);
3420 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3421 ims.setWfcProvisioned(isProvisioned);
3422 }
3423 break;
3424 }
3425 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3426 // There is currently no difference in VT provisioning type.
3427 ims.setVtProvisioned(isProvisioned);
3428 break;
3429 }
3430 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3431 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3432 // change the capability of the feature instead if needed.
3433 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3434 == isProvisioned) {
3435 // No change in provisioning.
3436 return;
3437 }
3438 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3439 try {
3440 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003441 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003442 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3443 + ", Exception" + e.getMessage());
3444 }
3445 break;
3446 }
3447 default: {
3448 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3449 + capability + "', which does not require provisioning.");
3450 }
3451 }
3452
3453 } finally {
3454 Binder.restoreCallingIdentity(identity);
3455 }
3456 }
3457
3458 @Override
3459 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3460 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3461 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3462 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3463 }
3464 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3465 final long identity = Binder.clearCallingIdentity();
3466 try {
3467 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3468 Phone phone = getPhone(subId);
3469 if (phone == null) {
3470 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3471 + subId);
3472 // We will fail with "true" as the provisioning status because this is the default
3473 // if we do not require provisioning.
3474 return true;
3475 }
3476
3477 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3478 return true;
3479 }
3480
3481 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3482 switch (capability) {
3483 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3484 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3485 return ims.isVolteProvisionedOnDevice();
3486 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3487 return ims.isWfcProvisionedOnDevice();
3488 }
3489 // This should never happen, since we are checking tech above to make sure it
3490 // is either LTE or IWLAN.
3491 throw new IllegalArgumentException("Invalid radio technology for voice "
3492 + "capability.");
3493 }
3494 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3495 // There is currently no difference in VT provisioning type.
3496 return ims.isVtProvisionedOnDevice();
3497 }
3498 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3499 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3500 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3501 }
3502 default: {
3503 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3504 + capability + "', which does not require provisioning.");
3505 }
3506 }
3507
3508 } finally {
3509 Binder.restoreCallingIdentity(identity);
3510 }
3511 }
3512
3513 @Override
3514 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3515 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3516 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3517 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3518 }
3519 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3520 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3521 return (provisionedBits & capability) > 0;
3522 }
3523
3524 @Override
3525 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3526 boolean isProvisioned) {
3527 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3528 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3529 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3530 }
3531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3532 "setProvisioningStatusForCapability");
3533 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3534 // If the current provisioning status for capability already matches isProvisioned,
3535 // do nothing.
3536 if (((provisionedBits & capability) > 0) == isProvisioned) {
3537 return;
3538 }
3539 if (isProvisioned) {
3540 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3541 } else {
3542 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3543 }
3544 }
3545
3546 /**
3547 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3548 * technology. The bitfield should mirror the bitfield defined by
3549 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3550 */
3551 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3552 String key = getMmTelProvisioningKey(subId, tech);
3553 // Default is no capabilities are provisioned.
3554 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3555 }
3556
3557 /**
3558 * Sets the MmTel capability provisioning bitfield (defined by
3559 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3560 * technology specified.
3561 *
3562 * Note: This is a synchronous command and should not be called on UI thread.
3563 */
3564 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3565 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3566 String key = getMmTelProvisioningKey(subId, tech);
3567 editor.putInt(key, newField);
3568 editor.commit();
3569 }
3570
3571 private static String getMmTelProvisioningKey(int subId, int tech) {
3572 // resulting key is provision_ims_mmtel_{subId}_{tech}
3573 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3574 }
3575
3576 /**
3577 * Query CarrierConfig to see if the specified capability requires provisioning for the
3578 * carrier associated with the subscription id.
3579 */
3580 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3581 int capability) {
3582 CarrierConfigManager configManager = new CarrierConfigManager(context);
3583 PersistableBundle c = configManager.getConfigForSubId(subId);
3584 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003585 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003586 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3587 false);
3588 boolean requireVoiceVtProvisioning = c.getBoolean(
3589 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3590
3591 // First check to make sure that the capability requires provisioning.
3592 switch (capability) {
3593 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3594 // intentional fallthrough
3595 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3596 if (requireVoiceVtProvisioning) {
3597 // Voice and Video requires provisioning
3598 return true;
3599 }
3600 break;
3601 }
3602 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3603 if (requireUtProvisioning) {
3604 // UT requires provisioning
3605 return true;
3606 }
3607 break;
3608 }
3609 }
3610 return false;
3611 }
3612
3613 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003614 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003615 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3616 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3617 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003618 enforceReadPrivilegedPermission("getImsProvisioningInt");
3619 final long identity = Binder.clearCallingIdentity();
3620 try {
3621 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003622 int slotId = getSlotIndex(subId);
3623 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3624 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3625 + subId + "' for key:" + key);
3626 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3627 }
3628 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003629 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003630 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3631 + subId + "' for key:" + key);
3632 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003633 } finally {
3634 Binder.restoreCallingIdentity(identity);
3635 }
3636 }
3637
3638 @Override
3639 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003640 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3641 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3642 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003643 enforceReadPrivilegedPermission("getImsProvisioningString");
3644 final long identity = Binder.clearCallingIdentity();
3645 try {
3646 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003647 int slotId = getSlotIndex(subId);
3648 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3649 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3650 + subId + "' for key:" + key);
3651 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3652 }
3653 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003654 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003655 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3656 + subId + "' for key:" + key);
3657 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003658 } finally {
3659 Binder.restoreCallingIdentity(identity);
3660 }
3661 }
3662
3663 @Override
3664 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003665 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3666 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3667 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3669 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003673 int slotId = getSlotIndex(subId);
3674 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3675 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3676 + subId + "' for key:" + key);
3677 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3678 }
3679 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003680 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003681 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3682 + "' for key:" + key);
3683 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003684 } finally {
3685 Binder.restoreCallingIdentity(identity);
3686 }
3687 }
3688
3689 @Override
3690 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003691 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3692 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3693 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3695 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003696 final long identity = Binder.clearCallingIdentity();
3697 try {
3698 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003699 int slotId = getSlotIndex(subId);
3700 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3701 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3702 + subId + "' for key:" + key);
3703 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3704 }
3705 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003706 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003707 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3708 + "' for key:" + key);
3709 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
3713 }
3714
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003715 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003716 int slotId = SubscriptionManager.getSlotIndex(subId);
3717 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003718 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3719 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 }
3721 return slotId;
3722 }
3723
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003724 private int getSlotIndex(int subId) {
3725 int slotId = SubscriptionManager.getSlotIndex(subId);
3726 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3727 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3728 }
3729 return slotId;
3730 }
3731
Wink Saville36469e72014-06-11 15:17:00 -07003732 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003733 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003734 */
3735 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003736 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003737 final int targetSdk = getTargetSdk(callingPackage);
3738 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3739 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3740 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003741 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3742 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003743 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3744 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746 final long identity = Binder.clearCallingIdentity();
3747 try {
3748 final Phone phone = getPhone(subId);
3749 if (phone != null) {
3750 return phone.getServiceState().getDataNetworkType();
3751 } else {
3752 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3753 }
3754 } finally {
3755 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003757 }
3758
3759 /**
3760 * Returns the data network type
3761 */
3762 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003763 public int getDataNetworkType(String callingPackage) {
3764 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003765 }
3766
3767 /**
3768 * Returns the data network type for a subId
3769 */
3770 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003771 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003772 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003773 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003774 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3775 }
3776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003777 final long identity = Binder.clearCallingIdentity();
3778 try {
3779 final Phone phone = getPhone(subId);
3780 if (phone != null) {
3781 return phone.getServiceState().getDataNetworkType();
3782 } else {
3783 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3784 }
3785 } finally {
3786 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003788 }
3789
3790 /**
Wink Saville36469e72014-06-11 15:17:00 -07003791 * Returns the Voice network type for a subId
3792 */
3793 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003794 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003795 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003796 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003797 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3798 }
3799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 final long identity = Binder.clearCallingIdentity();
3801 try {
3802 final Phone phone = getPhone(subId);
3803 if (phone != null) {
3804 return phone.getServiceState().getVoiceNetworkType();
3805 } else {
3806 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3807 }
3808 } finally {
3809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003811 }
3812
3813 /**
3814 * @return true if a ICC card is present
3815 */
3816 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003817 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003818 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3819 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003820 }
3821
3822 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003823 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003824 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003825 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003826 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 final long identity = Binder.clearCallingIdentity();
3828 try {
3829 final Phone phone = PhoneFactory.getPhone(slotIndex);
3830 if (phone != null) {
3831 return phone.getIccCard().hasIccCard();
3832 } else {
3833 return false;
3834 }
3835 } finally {
3836 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003838 }
3839
3840 /**
3841 * Return if the current radio is LTE on CDMA. This
3842 * is a tri-state return value as for a period of time
3843 * the mode may be unknown.
3844 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003845 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003846 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003847 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003848 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003849 @Override
3850 public int getLteOnCdmaMode(String callingPackage) {
3851 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003852 }
3853
Sanket Padawe356d7632015-06-22 14:03:32 -07003854 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003855 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003856 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003857 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003858 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3859 }
3860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 final Phone phone = getPhone(subId);
3864 if (phone == null) {
3865 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3866 } else {
3867 return phone.getLteOnCdmaMode();
3868 }
3869 } finally {
3870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003871 }
Wink Saville36469e72014-06-11 15:17:00 -07003872 }
3873
Wink Saville36469e72014-06-11 15:17:00 -07003874 /**
3875 * {@hide}
3876 * Returns Default subId, 0 in the case of single standby.
3877 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003878 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003879 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003880 }
3881
Shishir Agrawala9f32182016-04-12 12:00:16 -07003882 private int getSlotForDefaultSubscription() {
3883 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3884 }
3885
Wink Savilleb564aae2014-10-23 10:18:09 -07003886 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003887 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003888 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003889
Pengquan Menge92a50d2018-09-21 15:54:48 -07003890 private boolean isActiveSubscription(int subId) {
3891 return mSubscriptionController.isActiveSubId(subId);
3892 }
3893
Ihab Awadf2177b72013-11-25 13:33:23 -08003894 /**
3895 * @see android.telephony.TelephonyManager.WifiCallingChoices
3896 */
3897 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003898 final long identity = Binder.clearCallingIdentity();
3899 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003900 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003901 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3902 getWhenToMakeWifiCallsDefaultPreference());
3903 } finally {
3904 Binder.restoreCallingIdentity(identity);
3905 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003906 }
3907
3908 /**
3909 * @see android.telephony.TelephonyManager.WifiCallingChoices
3910 */
3911 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912 final long identity = Binder.clearCallingIdentity();
3913 try {
3914 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003915 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003916 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3917 } finally {
3918 Binder.restoreCallingIdentity(identity);
3919 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003920 }
3921
Sailesh Nepald1e68152013-12-12 19:08:02 -08003922 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003923 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003924 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003925 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003926
Jordan Liu4c733742019-02-28 12:03:40 -08003927 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3928 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3929 if (phoneId == -1) {
3930 throw new IllegalArgumentException("Given slot index: " + slotIndex
3931 + " does not correspond to an active phone");
3932 }
3933 return PhoneFactory.getPhone(phoneId);
3934 }
3935
Shishir Agrawal566b7612013-10-28 14:41:00 -07003936 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003937 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3938 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3940 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003942 if (DBG) {
3943 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3944 }
3945 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3946 p2);
3947 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003948
Jordan Liu4c733742019-02-28 12:03:40 -08003949
3950 @Override
3951 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3952 int slotIndex, String callingPackage, String aid, int p2) {
3953 enforceModifyPermission();
3954 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3955 if (DBG) {
3956 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3957 }
3958 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3959 callingPackage, aid, p2);
3960 }
3961
3962 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3963 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003964 final long identity = Binder.clearCallingIdentity();
3965 try {
3966 if (TextUtils.equals(ISDR_AID, aid)) {
3967 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003968 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3969 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970 if (bestComponent == null
3971 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3972 loge("The calling package is not allowed to access ISD-R.");
3973 throw new SecurityException(
3974 "The calling package is not allowed to access ISD-R.");
3975 }
Derek Tan740e1672017-06-27 14:56:27 -07003976 }
Derek Tan740e1672017-06-27 14:56:27 -07003977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003979 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3980 null /* workSource */);
3981 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003982 return response;
3983 } finally {
3984 Binder.restoreCallingIdentity(identity);
3985 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003986 }
3987
3988 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003989 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3991 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003992 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3993 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3994 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003995
Jordan Liu4c733742019-02-28 12:03:40 -08003996 @Override
3997 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3998 enforceModifyPermission();
3999 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4000 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4001 channel);
4002 }
4003
4004 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005 final long identity = Binder.clearCallingIdentity();
4006 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007 if (channel < 0) {
4008 return false;
4009 }
Jordan Liu4c733742019-02-28 12:03:40 -08004010 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4011 null /* workSource */);
4012 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013 return success;
4014 } finally {
4015 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004016 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004017 }
4018
4019 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004020 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004021 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4023 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004024 if (DBG) {
4025 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4026 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4027 + p3 + " data=" + data);
4028 }
4029 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4030 command, p1, p2, p3, data);
4031 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004032
Jordan Liu4c733742019-02-28 12:03:40 -08004033 @Override
4034 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4035 int command, int p1, int p2, int p3, String data) {
4036 enforceModifyPermission();
4037 if (DBG) {
4038 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4039 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4040 + p3 + " data=" + data);
4041 }
4042 return iccTransmitApduLogicalChannelWithPermission(
4043 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4044 data);
4045 }
4046
4047 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4048 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049 final long identity = Binder.clearCallingIdentity();
4050 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004051 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 return "";
4053 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004055 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004056 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4057 null /* workSource */);
4058 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004060 // Append the returned status code to the end of the response payload.
4061 String s = Integer.toHexString(
4062 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4063 if (response.payload != null) {
4064 s = IccUtils.bytesToHexString(response.payload) + s;
4065 }
4066 return s;
4067 } finally {
4068 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004069 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004070 }
Jake Hambye994d462014-02-03 13:10:13 -08004071
Evan Charltonc66da362014-05-16 14:06:40 -07004072 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004073 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4074 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4076 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004077 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004078 if (DBG) {
4079 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4080 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4081 }
4082 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4083 cla, command, p1, p2, p3, data);
4084 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004085
Jordan Liu4c733742019-02-28 12:03:40 -08004086 @Override
4087 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4088 int command, int p1, int p2, int p3, String data) {
4089 enforceModifyPermission();
4090 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4091 if (DBG) {
4092 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4093 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4094 + " data=" + data);
4095 }
4096
4097 return iccTransmitApduBasicChannelWithPermission(
4098 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4099 p2, p3, data);
4100 }
4101
4102 // open APDU basic channel assuming the caller has sufficient permissions
4103 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4104 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004105 final long identity = Binder.clearCallingIdentity();
4106 try {
4107 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4108 && TextUtils.equals(ISDR_AID, data)) {
4109 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004110 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4111 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112 if (bestComponent == null
4113 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4114 loge("The calling package is not allowed to select ISD-R.");
4115 throw new SecurityException(
4116 "The calling package is not allowed to select ISD-R.");
4117 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004118 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004120 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004121 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4122 null /* workSource */);
4123 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004124
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125 // Append the returned status code to the end of the response payload.
4126 String s = Integer.toHexString(
4127 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4128 if (response.payload != null) {
4129 s = IccUtils.bytesToHexString(response.payload) + s;
4130 }
4131 return s;
4132 } finally {
4133 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004134 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004135 }
4136
4137 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004138 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004139 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4141 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143 final long identity = Binder.clearCallingIdentity();
4144 try {
4145 if (DBG) {
4146 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4147 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4148 }
4149
4150 IccIoResult response =
4151 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4152 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4153 subId);
4154
4155 if (DBG) {
4156 log("Exchange SIM_IO [R]" + response);
4157 }
4158
4159 byte[] result = null;
4160 int length = 2;
4161 if (response.payload != null) {
4162 length = 2 + response.payload.length;
4163 result = new byte[length];
4164 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4165 } else {
4166 result = new byte[length];
4167 }
4168
4169 result[length - 1] = (byte) response.sw2;
4170 result[length - 2] = (byte) response.sw1;
4171 return result;
4172 } finally {
4173 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004174 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004175 }
4176
Nathan Haroldb3014052017-01-25 15:57:32 -08004177 /**
4178 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4179 * on a particular subscription
4180 */
sqianb6e41952018-03-12 14:54:01 -07004181 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4183 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4184 return null;
4185 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004186
4187 final long identity = Binder.clearCallingIdentity();
4188 try {
4189 if (appType != TelephonyManager.APPTYPE_USIM
4190 && appType != TelephonyManager.APPTYPE_SIM) {
4191 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4192 return null;
4193 }
4194 Object response = sendRequest(
4195 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4196 if (response instanceof String[]) {
4197 return (String[]) response;
4198 }
yincheng zhaod698b842019-09-06 17:06:54 -07004199 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004200 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004201 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004202 } finally {
4203 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004204 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004205 }
4206
yincheng zhaod698b842019-09-06 17:06:54 -07004207 /**
4208 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4209 * subscription.
4210 *
4211 * @param subId the id of the subscription.
4212 * @param appType the uicc app type, must be USIM or SIM.
4213 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4214 * @param callingPackage the op Package name.
4215 * @return number of fplmns that is successfully written to the SIM.
4216 */
4217 public int setForbiddenPlmns(
4218 int subId, int appType, List<String> fplmns, String callingPackage) {
4219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4220 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4221 if (DBG) logv("no permissions for setForbiddenplmns");
4222 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4223 }
4224 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4225 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4226 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4227 }
4228 if (fplmns == null) {
4229 throw new IllegalArgumentException("Fplmn List provided is null");
4230 }
4231 for (String fplmn : fplmns) {
4232 if (!CellIdentity.isValidPlmn(fplmn)) {
4233 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4234 }
4235 }
4236 final long identity = Binder.clearCallingIdentity();
4237 try {
4238 Object response = sendRequest(
4239 CMD_SET_FORBIDDEN_PLMNS,
4240 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4241 subId);
4242 return (int) response;
4243 } finally {
4244 Binder.restoreCallingIdentity(identity);
4245 }
4246 }
4247
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004248 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004249 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4251 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253 final long identity = Binder.clearCallingIdentity();
4254 try {
4255 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4256 if (response.payload == null) {
4257 return "";
4258 }
Evan Charltonc66da362014-05-16 14:06:40 -07004259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 // Append the returned status code to the end of the response payload.
4261 String s = Integer.toHexString(
4262 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4263 s = IccUtils.bytesToHexString(response.payload) + s;
4264 return s;
4265 } finally {
4266 Binder.restoreCallingIdentity(identity);
4267 }
Evan Charltonc66da362014-05-16 14:06:40 -07004268 }
4269
Jake Hambye994d462014-02-03 13:10:13 -08004270 /**
4271 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4272 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4273 *
4274 * @param itemID the ID of the item to read
4275 * @return the NV item as a String, or null on error.
4276 */
4277 @Override
4278 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004279 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4281 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004282
4283 final long identity = Binder.clearCallingIdentity();
4284 try {
4285 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004286 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4288 return value;
4289 } finally {
4290 Binder.restoreCallingIdentity(identity);
4291 }
Jake Hambye994d462014-02-03 13:10:13 -08004292 }
4293
4294 /**
4295 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4296 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4297 *
4298 * @param itemID the ID of the item to read
4299 * @param itemValue the value to write, as a String
4300 * @return true on success; false on any failure
4301 */
4302 @Override
4303 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004304 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4306 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307
4308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4311 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004312 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004313 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4314 return success;
4315 } finally {
4316 Binder.restoreCallingIdentity(identity);
4317 }
Jake Hambye994d462014-02-03 13:10:13 -08004318 }
4319
4320 /**
4321 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4322 * Used for device configuration by some CDMA operators.
4323 *
4324 * @param preferredRoamingList byte array containing the new PRL
4325 * @return true on success; false on any failure
4326 */
4327 @Override
4328 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4330 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004331
4332 final long identity = Binder.clearCallingIdentity();
4333 try {
4334 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4335 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4336 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4337 return success;
4338 } finally {
4339 Binder.restoreCallingIdentity(identity);
4340 }
Jake Hambye994d462014-02-03 13:10:13 -08004341 }
4342
4343 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004344 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004345 * Used for device configuration by some CDMA operators.
4346 *
chen xu6dac5ab2018-10-26 17:39:23 -07004347 * @param slotIndex - device slot.
4348 *
Jake Hambye994d462014-02-03 13:10:13 -08004349 * @return true on success; false on any failure
4350 */
4351 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004352 public boolean resetModemConfig(int slotIndex) {
4353 Phone phone = PhoneFactory.getPhone(slotIndex);
4354 if (phone != null) {
4355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4356 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357
chen xu6dac5ab2018-10-26 17:39:23 -07004358 final long identity = Binder.clearCallingIdentity();
4359 try {
4360 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4361 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4362 return success;
4363 } finally {
4364 Binder.restoreCallingIdentity(identity);
4365 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366 }
chen xu6dac5ab2018-10-26 17:39:23 -07004367 return false;
4368 }
4369
4370 /**
4371 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4372 *
4373 * @param slotIndex - device slot.
4374 *
4375 * @return true on success; false on any failure
4376 */
4377 @Override
4378 public boolean rebootModem(int slotIndex) {
4379 Phone phone = PhoneFactory.getPhone(slotIndex);
4380 if (phone != null) {
4381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4382 mApp, phone.getSubId(), "rebootModem");
4383
4384 final long identity = Binder.clearCallingIdentity();
4385 try {
4386 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4387 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4388 return success;
4389 } finally {
4390 Binder.restoreCallingIdentity(identity);
4391 }
4392 }
4393 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004394 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004395
Svet Ganovb320e182015-04-16 12:30:10 -07004396 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004397 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004398 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004399 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004400 return new String[0];
4401 }
4402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 final long identity = Binder.clearCallingIdentity();
4404 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004405 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
Wink Saville36469e72014-06-11 15:17:00 -07004409 }
4410
Brad Ebinger51f743a2017-01-23 13:50:20 -08004411 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004412 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4413 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004414 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004415 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004416 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004417
4418 final long identity = Binder.clearCallingIdentity();
4419 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004420 ImsResolver resolver = PhoneFactory.getImsResolver();
4421 if (resolver == null) {
4422 // may happen if the device does not support IMS.
4423 return;
4424 }
4425 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004426 } finally {
4427 Binder.restoreCallingIdentity(identity);
4428 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004429 }
4430
4431 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004432 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4433 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004434 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004435 public void disableIms(int slotId) {
4436 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004437
4438 final long identity = Binder.clearCallingIdentity();
4439 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004440 ImsResolver resolver = PhoneFactory.getImsResolver();
4441 if (resolver == null) {
4442 // may happen if the device does not support IMS.
4443 return;
4444 }
4445 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 } finally {
4447 Binder.restoreCallingIdentity(identity);
4448 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004449 }
4450
4451 /**
4452 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4453 * feature or {@link null} if the service is not available. If the feature is available, the
4454 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4455 */
4456 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004457 IImsServiceFeatureCallback callback) {
4458 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004459
4460 final long identity = Binder.clearCallingIdentity();
4461 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004462 ImsResolver resolver = PhoneFactory.getImsResolver();
4463 if (resolver == null) {
4464 // may happen if the device does not support IMS.
4465 return null;
4466 }
4467 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004468 } finally {
4469 Binder.restoreCallingIdentity(identity);
4470 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004471 }
4472
4473 /**
4474 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4475 * feature during emergency calling or {@link null} if the service is not available. If the
4476 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4477 * listener for feature updates.
4478 */
4479 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4480 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481
4482 final long identity = Binder.clearCallingIdentity();
4483 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004484 ImsResolver resolver = PhoneFactory.getImsResolver();
4485 if (resolver == null) {
4486 // may happen if the device does not support IMS.
4487 return null;
4488 }
4489 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004490 } finally {
4491 Binder.restoreCallingIdentity(identity);
4492 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004493 }
4494
Brad Ebinger5f64b052017-12-14 14:26:15 -08004495 /**
4496 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004497 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004498 */
4499 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4500 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004501
4502 final long identity = Binder.clearCallingIdentity();
4503 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004504 ImsResolver resolver = PhoneFactory.getImsResolver();
4505 if (resolver == null) {
4506 // may happen if the device does not support IMS.
4507 return null;
4508 }
4509 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004510 } finally {
4511 Binder.restoreCallingIdentity(identity);
4512 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004513 }
4514
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004515 /**
4516 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004517 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004518 */
4519 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4520 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004521
4522 final long identity = Binder.clearCallingIdentity();
4523 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004524 ImsResolver resolver = PhoneFactory.getImsResolver();
4525 if (resolver == null) {
4526 // may happen if the device does not support IMS.
4527 return null;
4528 }
4529 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004530 } finally {
4531 Binder.restoreCallingIdentity(identity);
4532 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004533 }
4534
Brad Ebinger884c07b2018-02-15 16:17:40 -08004535 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004536 * Sets the ImsService Package Name that Telephony will bind to.
4537 *
4538 * @param slotId the slot ID that the ImsService should bind for.
4539 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4540 * ImsService is the device default ImsService.
4541 * @param packageName The package name of the application that contains the ImsService to bind
4542 * to.
4543 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4544 * @hide
4545 */
4546 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004547 int[] subIds = SubscriptionManager.getSubId(slotId);
4548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4549 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4550 "setImsService");
4551
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004552 final long identity = Binder.clearCallingIdentity();
4553 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004554 ImsResolver resolver = PhoneFactory.getImsResolver();
4555 if (resolver == null) {
4556 // may happen if the device does not support IMS.
4557 return false;
4558 }
4559 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4560 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004564 }
4565
4566 /**
4567 * Return the ImsService configuration.
4568 *
4569 * @param slotId The slot that the ImsService is associated with.
4570 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4571 * the device default.
4572 * @return the package name of the ImsService configuration.
4573 */
4574 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004575 int[] subIds = SubscriptionManager.getSubId(slotId);
4576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4577 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4578 "getImsService");
4579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004580 final long identity = Binder.clearCallingIdentity();
4581 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004582 ImsResolver resolver = PhoneFactory.getImsResolver();
4583 if (resolver == null) {
4584 // may happen if the device does not support IMS.
4585 return "";
4586 }
4587 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004588 } finally {
4589 Binder.restoreCallingIdentity(identity);
4590 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004591 }
4592
Brad Ebinger77b832e2019-10-17 17:03:22 -07004593 /**
4594 * Get the MmTelFeature state associated with the requested subscription id.
4595 * @param subId The subscription that the MmTelFeature is associated with.
4596 * @param callback A callback with an integer containing the
4597 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4598 */
4599 @Override
4600 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4601 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4602 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4603 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4604 "IMS not available on device.");
4605 }
4606 final long token = Binder.clearCallingIdentity();
4607 try {
4608 int slotId = getSlotIndex(subId);
4609 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4610 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4611 + subId + "'");
4612 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4613 }
4614 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4615 try {
4616 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4617 } catch (RemoteException e) {
4618 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4619 + "Ignore");
4620 }
4621 });
4622 } finally {
4623 Binder.restoreCallingIdentity(token);
4624 }
4625 }
4626
Wink Saville36469e72014-06-11 15:17:00 -07004627 public void setImsRegistrationState(boolean registered) {
4628 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629
4630 final long identity = Binder.clearCallingIdentity();
4631 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004632 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004633 } finally {
4634 Binder.restoreCallingIdentity(identity);
4635 }
Wink Saville36469e72014-06-11 15:17:00 -07004636 }
4637
4638 /**
Stuart Scott54788802015-03-30 13:18:01 -07004639 * Set the network selection mode to automatic.
4640 *
4641 */
4642 @Override
4643 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4645 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646
Pengquan Menge92a50d2018-09-21 15:54:48 -07004647 if (!isActiveSubscription(subId)) {
4648 return;
4649 }
4650
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651 final long identity = Binder.clearCallingIdentity();
4652 try {
4653 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4654 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4655 } finally {
4656 Binder.restoreCallingIdentity(identity);
4657 }
Stuart Scott54788802015-03-30 13:18:01 -07004658 }
4659
Pengquan Mengea84e042018-09-20 14:57:26 -07004660 /**
4661 * Ask the radio to connect to the input network and change selection mode to manual.
4662 *
4663 * @param subId the id of the subscription.
4664 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4665 * the operator to attach to.
4666 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4667 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4668 * normal network selection next time.
4669 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004670 */
4671 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004672 public boolean setNetworkSelectionModeManual(
4673 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4675 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004676
4677 if (!isActiveSubscription(subId)) {
4678 return false;
4679 }
4680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681 final long identity = Binder.clearCallingIdentity();
4682 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004683 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004684 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004685 if (DBG) {
4686 log("setNetworkSelectionModeManual: subId: " + subId
4687 + " operator: " + operatorInfo);
4688 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4690 } finally {
4691 Binder.restoreCallingIdentity(identity);
4692 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004693 }
4694
4695 /**
4696 * Scans for available networks.
4697 */
4698 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004699 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4701 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004702 LocationAccessPolicy.LocationPermissionResult locationResult =
4703 LocationAccessPolicy.checkLocationPermission(mApp,
4704 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4705 .setCallingPackage(callingPackage)
4706 .setCallingPid(Binder.getCallingPid())
4707 .setCallingUid(Binder.getCallingUid())
4708 .setMethod("getCellNetworkScanResults")
4709 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4710 .build());
4711 switch (locationResult) {
4712 case DENIED_HARD:
4713 throw new SecurityException("Not allowed to access scan results -- location");
4714 case DENIED_SOFT:
4715 return null;
4716 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004717
Pengquan Menga1bb6272018-09-06 09:59:22 -07004718 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719 try {
4720 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004721 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004722 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723 } finally {
4724 Binder.restoreCallingIdentity(identity);
4725 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004726 }
4727
4728 /**
yinxub1bed742017-04-17 11:45:04 -07004729 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004730 *
yinxub1bed742017-04-17 11:45:04 -07004731 * @param subId id of the subscription
4732 * @param request contains the radio access networks with bands/channels to scan
4733 * @param messenger callback messenger for scan results or errors
4734 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004735 * @return the id of the requested scan which can be used to stop the scan.
4736 */
4737 @Override
4738 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004739 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004740 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4741 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004742 LocationAccessPolicy.LocationPermissionResult locationResult =
4743 LocationAccessPolicy.checkLocationPermission(mApp,
4744 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4745 .setCallingPackage(callingPackage)
4746 .setCallingPid(Binder.getCallingPid())
4747 .setCallingUid(Binder.getCallingUid())
4748 .setMethod("requestNetworkScan")
4749 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4750 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004751 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004752 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004753 if (e != null) {
4754 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4755 throw e;
4756 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004757 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004758 return TelephonyScanManager.INVALID_SCAN_ID;
4759 }
4760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761 }
Hall Liu912dfd32019-04-25 14:02:26 -07004762 int callingUid = Binder.getCallingUid();
4763 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004764 final long identity = Binder.clearCallingIdentity();
4765 try {
4766 return mNetworkScanRequestTracker.startNetworkScan(
4767 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004768 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004769 } finally {
4770 Binder.restoreCallingIdentity(identity);
4771 }
yinxu504e1392017-04-12 16:03:22 -07004772 }
4773
Hall Liub2ac8ef2019-02-28 15:56:23 -08004774 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004775 NetworkScanRequest request, int subId) {
4776 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4777 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4778 boolean hasNetworkScanPermission =
4779 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4780 == PERMISSION_GRANTED;
4781
4782 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4783 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4784 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004785 }
4786
4787 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4788 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004789 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4790 return new SecurityException("Specific channels must not be"
4791 + " scanned without location access.");
4792 }
4793 }
4794 }
4795
Hall Liub2ac8ef2019-02-28 15:56:23 -08004796 return null;
4797 }
4798
yinxu504e1392017-04-12 16:03:22 -07004799 /**
4800 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004801 *
4802 * @param subId id of the subscription
4803 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004804 */
4805 @Override
4806 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4808 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004809
Hall Liu912dfd32019-04-25 14:02:26 -07004810 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004811 final long identity = Binder.clearCallingIdentity();
4812 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004813 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004814 } finally {
4815 Binder.restoreCallingIdentity(identity);
4816 }
yinxu504e1392017-04-12 16:03:22 -07004817 }
4818
4819 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004820 * Get the calculated preferred network type.
4821 * Used for debugging incorrect network type.
4822 *
4823 * @return the preferred network type, defined in RILConstants.java.
4824 */
4825 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004826 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004827 final Phone defaultPhone = getDefaultPhone();
4828 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4829 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004830 return RILConstants.PREFERRED_NETWORK_MODE;
4831 }
4832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833 final long identity = Binder.clearCallingIdentity();
4834 try {
4835 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004836 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004837 } finally {
4838 Binder.restoreCallingIdentity(identity);
4839 }
Junda Liu84d15a22014-07-02 11:21:04 -07004840 }
4841
4842 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004843 * Get the preferred network type.
4844 * Used for device configuration by some CDMA operators.
4845 *
4846 * @return the preferred network type, defined in RILConstants.java.
4847 */
4848 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004849 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004850 TelephonyPermissions
4851 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4852 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853
4854 final long identity = Binder.clearCallingIdentity();
4855 try {
4856 if (DBG) log("getPreferredNetworkType");
4857 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4858 int networkType = (result != null ? result[0] : -1);
4859 if (DBG) log("getPreferredNetworkType: " + networkType);
4860 return networkType;
4861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004864 }
4865
4866 /**
4867 * Set the preferred network type.
4868 * Used for device configuration by some CDMA operators.
4869 *
4870 * @param networkType the preferred network type, defined in RILConstants.java.
4871 * @return true on success; false on any failure.
4872 */
4873 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004874 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4876 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004877
4878 final long identity = Binder.clearCallingIdentity();
4879 try {
4880 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4881 Boolean success = (Boolean) sendRequest(
4882 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4883 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4884 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004885 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004886 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4887 }
4888 return success;
4889 } finally {
4890 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004891 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004892 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004893
4894 /**
Miaoa84611c2019-03-15 09:21:10 +08004895 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004896 *
Miaoa84611c2019-03-15 09:21:10 +08004897 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004898 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004899 * @hide
4900 */
4901 @Override
Miaoa84611c2019-03-15 09:21:10 +08004902 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004903 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004905 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906 try {
Miaoa84611c2019-03-15 09:21:10 +08004907 if (phone != null) {
4908 return phone.hasMatchedTetherApnSetting();
4909 } else {
4910 return false;
4911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 } finally {
4913 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004914 }
Junda Liu475951f2014-11-07 16:45:03 -08004915 }
4916
4917 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004918 * Set mobile data enabled
4919 * Used by the user through settings etc to turn on/off mobile data
4920 *
4921 * @param enable {@code true} turn turn data on, else {@code false}
4922 */
4923 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004924 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4926 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004927
4928 final long identity = Binder.clearCallingIdentity();
4929 try {
4930 int phoneId = mSubscriptionController.getPhoneId(subId);
4931 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4932 Phone phone = PhoneFactory.getPhone(phoneId);
4933 if (phone != null) {
4934 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004935 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004937 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004938 }
4939 } finally {
4940 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004941 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004942 }
4943
4944 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004945 * Get the user enabled state of Mobile Data.
4946 *
4947 * TODO: remove and use isUserDataEnabled.
4948 * This can't be removed now because some vendor codes
4949 * calls through ITelephony directly while they should
4950 * use TelephonyManager.
4951 *
4952 * @return true on enabled
4953 */
4954 @Override
4955 public boolean getDataEnabled(int subId) {
4956 return isUserDataEnabled(subId);
4957 }
4958
4959 /**
4960 * Get whether mobile data is enabled per user setting.
4961 *
4962 * There are other factors deciding whether mobile data is actually enabled, but they are
4963 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004964 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004965 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004966 *
4967 * @return {@code true} if data is enabled else {@code false}
4968 */
4969 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004970 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004971 try {
4972 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4973 null);
4974 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4976 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004977 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004978
4979 final long identity = Binder.clearCallingIdentity();
4980 try {
4981 int phoneId = mSubscriptionController.getPhoneId(subId);
4982 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4983 Phone phone = PhoneFactory.getPhone(phoneId);
4984 if (phone != null) {
4985 boolean retVal = phone.isUserDataEnabled();
4986 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4987 return retVal;
4988 } else {
4989 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4990 return false;
4991 }
4992 } finally {
4993 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004994 }
4995 }
4996
4997 /**
4998 * Get whether mobile data is enabled.
4999 *
5000 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5001 * whether mobile data is actually enabled.
5002 *
5003 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5004 *
5005 * @return {@code true} if data is enabled else {@code false}
5006 */
5007 @Override
5008 public boolean isDataEnabled(int subId) {
5009 try {
5010 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5011 null);
5012 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5014 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005015 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016
5017 final long identity = Binder.clearCallingIdentity();
5018 try {
5019 int phoneId = mSubscriptionController.getPhoneId(subId);
5020 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5021 Phone phone = PhoneFactory.getPhone(phoneId);
5022 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005023 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5025 return retVal;
5026 } else {
5027 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5028 return false;
5029 }
5030 } finally {
5031 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005032 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005033 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005034
5035 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005036 public int getCarrierPrivilegeStatus(int subId) {
5037 final Phone phone = getPhone(subId);
5038 if (phone == null) {
5039 loge("getCarrierPrivilegeStatus: Invalid subId");
5040 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5041 }
5042 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005043 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005044 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005045 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5046 }
5047 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005048 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005049 }
Junda Liu29340342014-07-10 15:23:27 -07005050
5051 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005052 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5053 final Phone phone = getPhone(subId);
5054 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005055 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005056 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5057 }
5058 UiccProfile profile =
5059 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5060 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005061 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005062 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5063 }
5064 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
5065 }
5066
5067 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005068 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5069 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005070 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005071 }
5072
5073 int phoneId = SubscriptionManager.getPhoneId(subId);
5074 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005075 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005076 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005077 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5078 }
chen xuf7e9fe82019-05-09 19:31:02 -07005079
5080 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005081 }
5082
5083 @Override
5084 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005085 if (TextUtils.isEmpty(pkgName))
5086 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005087 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5088 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5089 UiccCard card = UiccController.getInstance().getUiccCard(i);
5090 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005091 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005092 continue;
5093 }
5094
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005095 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005096 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5097 break;
5098 }
5099 }
5100
5101 return result;
Junda Liu29340342014-07-10 15:23:27 -07005102 }
Derek Tan89e89d42014-07-08 17:00:10 -07005103
5104 @Override
Junda Liue64de782015-04-16 17:19:16 -07005105 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5106 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5107 loge("phoneId " + phoneId + " is not valid.");
5108 return null;
5109 }
5110 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005111 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005112 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005113 return null ;
5114 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005115 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005116 }
5117
Amith Yamasani6e118872016-02-19 12:53:51 -08005118 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005119 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005120 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005121 List<String> privilegedPackages = new ArrayList<>();
5122 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005123 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5124 // has UICC in that slot.
5125 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005126 if (card.hasCarrierPrivilegeRules()) {
5127 if (packages == null) {
5128 // Only check packages in user 0 for now
5129 packages = pm.getInstalledPackagesAsUser(
5130 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07005131 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
5132 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005133 }
5134 for (int p = packages.size() - 1; p >= 0; p--) {
5135 PackageInfo pkgInfo = packages.get(p);
5136 if (pkgInfo != null && pkgInfo.packageName != null
5137 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005138 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005139 privilegedPackages.add(pkgInfo.packageName);
5140 }
5141 }
5142 }
5143 }
5144 return privilegedPackages;
5145 }
5146
chen xuf7e9fe82019-05-09 19:31:02 -07005147 @Override
5148 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5149 List<String> privilegedPackages = new ArrayList<>();
5150 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5151 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5152 }
5153 return privilegedPackages;
5154 }
5155
Wink Savilleb564aae2014-10-23 10:18:09 -07005156 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005157 final Phone phone = getPhone(subId);
5158 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005159 if (card == null) {
5160 loge("getIccId: No UICC");
5161 return null;
5162 }
5163 String iccId = card.getIccId();
5164 if (TextUtils.isEmpty(iccId)) {
5165 loge("getIccId: ICC ID is null or empty.");
5166 return null;
5167 }
5168 return iccId;
5169 }
5170
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005171 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005172 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5173 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005174 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5175 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005176
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177 final long identity = Binder.clearCallingIdentity();
5178 try {
5179 final String iccId = getIccId(subId);
5180 final Phone phone = getPhone(subId);
5181 if (phone == null) {
5182 return false;
5183 }
5184 final String subscriberId = phone.getSubscriberId();
5185
5186 if (DBG_MERGE) {
5187 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5188 + subscriberId + " to " + number);
5189 }
5190
5191 if (TextUtils.isEmpty(iccId)) {
5192 return false;
5193 }
5194
5195 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5196
5197 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5198 if (alphaTag == null) {
5199 editor.remove(alphaTagPrefKey);
5200 } else {
5201 editor.putString(alphaTagPrefKey, alphaTag);
5202 }
5203
5204 // Record both the line number and IMSI for this ICCID, since we need to
5205 // track all merged IMSIs based on line number
5206 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5207 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5208 if (number == null) {
5209 editor.remove(numberPrefKey);
5210 editor.remove(subscriberPrefKey);
5211 } else {
5212 editor.putString(numberPrefKey, number);
5213 editor.putString(subscriberPrefKey, subscriberId);
5214 }
5215
5216 editor.commit();
5217 return true;
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005220 }
Derek Tan7226c842014-07-02 17:42:23 -07005221 }
5222
5223 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005224 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005225 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005226 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005227 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005228 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005229 return null;
5230 }
Derek Tan97ebb422014-09-05 16:55:38 -07005231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 final long identity = Binder.clearCallingIdentity();
5233 try {
5234 String iccId = getIccId(subId);
5235 if (iccId != null) {
5236 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5237 if (DBG_MERGE) {
5238 log("getLine1NumberForDisplay returning "
5239 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5240 }
5241 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005242 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5244 return null;
5245 } finally {
5246 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005247 }
Derek Tan7226c842014-07-02 17:42:23 -07005248 }
5249
5250 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005251 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005252 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005253 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005254 return null;
5255 }
Derek Tan97ebb422014-09-05 16:55:38 -07005256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 final long identity = Binder.clearCallingIdentity();
5258 try {
5259 String iccId = getIccId(subId);
5260 if (iccId != null) {
5261 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5262 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5263 }
5264 return null;
5265 } finally {
5266 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005267 }
Derek Tan7226c842014-07-02 17:42:23 -07005268 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005269
5270 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005271 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005272 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5273 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005274 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005275 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5276 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005277 return null;
5278 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005279
Jordan Liub49b04b2019-05-06 14:45:15 -07005280 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5281 // the process, where TelephonyManager was instantiated.
5282 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005283 final long identity = Binder.clearCallingIdentity();
5284 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005285 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 final TelephonyManager tele = TelephonyManager.from(context);
5287 final SubscriptionManager sub = SubscriptionManager.from(context);
5288
5289 // Figure out what subscribers are currently active
5290 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291
Jordan Liub49b04b2019-05-06 14:45:15 -07005292 // Only consider subs which match the current subId
5293 // This logic can be simplified. See b/131189269 for progress.
5294 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005295 activeSubscriberIds.add(tele.getSubscriberId(subId));
5296 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297
5298 // First pass, find a number override for an active subscriber
5299 String mergeNumber = null;
5300 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5301 for (String key : prefs.keySet()) {
5302 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5303 final String subscriberId = (String) prefs.get(key);
5304 if (activeSubscriberIds.contains(subscriberId)) {
5305 final String iccId = key.substring(
5306 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5307 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5308 mergeNumber = (String) prefs.get(numberKey);
5309 if (DBG_MERGE) {
5310 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5311 + " for active subscriber " + subscriberId);
5312 }
5313 if (!TextUtils.isEmpty(mergeNumber)) {
5314 break;
5315 }
5316 }
5317 }
5318 }
5319
5320 // Shortcut when no active merged subscribers
5321 if (TextUtils.isEmpty(mergeNumber)) {
5322 return null;
5323 }
5324
5325 // Second pass, find all subscribers under that line override
5326 final ArraySet<String> result = new ArraySet<>();
5327 for (String key : prefs.keySet()) {
5328 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5329 final String number = (String) prefs.get(key);
5330 if (mergeNumber.equals(number)) {
5331 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5332 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5333 final String subscriberId = (String) prefs.get(subscriberKey);
5334 if (!TextUtils.isEmpty(subscriberId)) {
5335 result.add(subscriberId);
5336 }
5337 }
5338 }
5339 }
5340
5341 final String[] resultArray = result.toArray(new String[result.size()]);
5342 Arrays.sort(resultArray);
5343 if (DBG_MERGE) {
5344 Slog.d(LOG_TAG,
5345 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5346 }
5347 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005348 } finally {
5349 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005350 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005351 }
5352
5353 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005354 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5355 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5356
5357 final long identity = Binder.clearCallingIdentity();
5358 try {
5359 final TelephonyManager telephonyManager = mApp.getSystemService(
5360 TelephonyManager.class);
5361 String subscriberId = telephonyManager.getSubscriberId(subId);
5362 if (subscriberId == null) {
5363 if (DBG) {
5364 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5365 + subId);
5366 }
5367 return null;
5368 }
5369
5370 final SubscriptionInfo info = SubscriptionController.getInstance()
5371 .getSubscriptionInfo(subId);
5372 final ParcelUuid groupUuid = info.getGroupUuid();
5373 // If it doesn't belong to any group, return just subscriberId of itself.
5374 if (groupUuid == null) {
5375 return new String[]{subscriberId};
5376 }
5377
5378 // Get all subscriberIds from the group.
5379 final List<String> mergedSubscriberIds = new ArrayList<>();
5380 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5381 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5382 for (SubscriptionInfo subInfo : groupInfos) {
5383 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5384 if (subscriberId != null) {
5385 mergedSubscriberIds.add(subscriberId);
5386 }
5387 }
5388
5389 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5390 } finally {
5391 Binder.restoreCallingIdentity(identity);
5392
5393 }
5394 }
5395
5396 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005397 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005398 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5399 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400
5401 final long identity = Binder.clearCallingIdentity();
5402 try {
5403 final Phone phone = getPhone(subId);
5404 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5405 } finally {
5406 Binder.restoreCallingIdentity(identity);
5407 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005408 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005409
5410 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005411 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005412 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5413 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005414 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415
5416 final long identity = Binder.clearCallingIdentity();
5417 try {
5418 final Phone phone = getPhone(subId);
5419 if (phone == null) {
5420 return false;
5421 }
5422 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5423 cdmaNonRoamingList);
5424 } finally {
5425 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005426 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005427 }
5428
5429 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005430 @Deprecated
5431 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5432 enforceModifyPermission();
5433
5434 int returnValue = 0;
5435 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005436 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005437 if(result.exception == null) {
5438 if (result.result != null) {
5439 byte[] responseData = (byte[])(result.result);
5440 if(responseData.length > oemResp.length) {
5441 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5442 responseData.length + "bytes. Buffer Size is " +
5443 oemResp.length + "bytes.");
5444 }
5445 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5446 returnValue = responseData.length;
5447 }
5448 } else {
5449 CommandException ex = (CommandException) result.exception;
5450 returnValue = ex.getCommandError().ordinal();
5451 if(returnValue > 0) returnValue *= -1;
5452 }
5453 } catch (RuntimeException e) {
5454 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5455 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5456 if(returnValue > 0) returnValue *= -1;
5457 }
5458
5459 return returnValue;
5460 }
5461
5462 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005463 public void setRadioCapability(RadioAccessFamily[] rafs) {
5464 try {
5465 ProxyController.getInstance().setRadioCapability(rafs);
5466 } catch (RuntimeException e) {
5467 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5468 }
5469 }
5470
5471 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005472 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005473 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005474 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005475 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005476 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478 final long identity = Binder.clearCallingIdentity();
5479 try {
chen xub97461a2018-10-26 14:17:57 -07005480 TelephonyPermissions
5481 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5482 mApp, phone.getSubId(), "getRadioAccessFamily");
5483 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484 } finally {
5485 Binder.restoreCallingIdentity(identity);
5486 }
chen xub97461a2018-10-26 14:17:57 -07005487 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005488 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005489
5490 @Override
5491 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005492 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005493 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494
5495 final long identity = Binder.clearCallingIdentity();
5496 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005497 ImsManager.getInstance(defaultPhone.getContext(),
5498 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499 } finally {
5500 Binder.restoreCallingIdentity(identity);
5501 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005502 }
5503
5504 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005505 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005506 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005507 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005508 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005509 return false;
5510 }
Svet Ganovb320e182015-04-16 12:30:10 -07005511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 final long identity = Binder.clearCallingIdentity();
5513 try {
5514 // Check the user preference and the system-level IMS setting. Even if the user has
5515 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5516 // In the long run, we may instead need to check if there exists a connection service
5517 // which can support video calling.
5518 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005519 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520 return imsManager.isVtEnabledByPlatform()
5521 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5522 && imsManager.isVtEnabledByUser();
5523 } finally {
5524 Binder.restoreCallingIdentity(identity);
5525 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005526 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005527
Andrew Leea1239f22015-03-02 17:44:07 -08005528 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5531 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5532 return false;
5533 }
5534
5535 final long identity = Binder.clearCallingIdentity();
5536 try {
5537 CarrierConfigManager configManager =
5538 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005539 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005540 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
5543 }
Andrew Leea1239f22015-03-02 17:44:07 -08005544 }
5545
5546 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547 public boolean isWorldPhone(int subId, String callingPackage) {
5548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5549 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5550 return false;
5551 }
5552
5553 final long identity = Binder.clearCallingIdentity();
5554 try {
5555 CarrierConfigManager configManager =
5556 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005557 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5559 } finally {
5560 Binder.restoreCallingIdentity(identity);
5561 }
Andrew Leea1239f22015-03-02 17:44:07 -08005562 }
5563
Andrew Lee9431b832015-03-09 18:46:45 -07005564 @Override
5565 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005566 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005567 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005568 }
5569
5570 @Override
5571 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005572 final long identity = Binder.clearCallingIdentity();
5573 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005574 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 } finally {
5576 Binder.restoreCallingIdentity(identity);
5577 }
Andrew Lee9431b832015-03-09 18:46:45 -07005578 }
5579
Hall Liuf6668912018-10-31 17:05:23 -07005580 /**
5581 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5582 * support for the feature and device firmware support.
5583 *
5584 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5585 */
5586 @Override
5587 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005589 final Phone phone = getPhone(subscriptionId);
5590 if (phone == null) {
5591 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5592 return false;
5593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005595 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5597 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005598 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 return isCarrierSupported && isDeviceSupported;
5600 } finally {
5601 Binder.restoreCallingIdentity(identity);
5602 }
Hall Liu98187582018-01-22 19:15:32 -08005603 }
5604
Hall Liuf6668912018-10-31 17:05:23 -07005605 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005606 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5607 * RTT setting, will return true if the device and carrier both support RTT.
5608 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005609 */
5610 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 final long identity = Binder.clearCallingIdentity();
5612 try {
Hall Liu6a06be62019-07-23 18:39:00 -07005613 boolean isRttSupported = isRttSupported(subscriptionId);
5614 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005615 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liu6a06be62019-07-23 18:39:00 -07005616 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5617 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5618 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 } finally {
5620 Binder.restoreCallingIdentity(identity);
5621 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005622 }
5623
Sanket Padawe7310cc72015-01-14 09:53:20 -08005624 /**
5625 * Returns the unique device ID of phone, for example, the IMEI for
5626 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5627 *
5628 * <p>Requires Permission:
5629 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5630 */
5631 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005632 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005633 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005634 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005635 return null;
5636 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005637 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005638 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5639 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005640 return null;
5641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642
5643 final long identity = Binder.clearCallingIdentity();
5644 try {
5645 return phone.getDeviceId();
5646 } finally {
5647 Binder.restoreCallingIdentity(identity);
5648 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005649 }
5650
Ping Sunc67b7c22016-03-02 19:16:45 +08005651 /**
5652 * {@hide}
5653 * Returns the IMS Registration Status on a particular subid
5654 *
5655 * @param subId
5656 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005657 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005658 Phone phone = getPhone(subId);
5659 if (phone != null) {
5660 return phone.isImsRegistered();
5661 } else {
5662 return false;
5663 }
5664 }
5665
Santos Cordon7a1885b2015-02-03 11:15:19 -08005666 @Override
5667 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668 final long identity = Binder.clearCallingIdentity();
5669 try {
5670 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5671 } finally {
5672 Binder.restoreCallingIdentity(identity);
5673 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005674 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005675
Tyler Gunnf70ed162019-04-03 15:28:53 -07005676 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005677 public int getSubIdForPhoneAccountHandle(
5678 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5679 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5680 callingPackage, "getSubIdForPhoneAccountHandle")) {
5681 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5682 }
5683 final long identity = Binder.clearCallingIdentity();
5684 try {
5685 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5686 } finally {
5687 Binder.restoreCallingIdentity(identity);
5688 }
5689 }
5690
5691 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005692 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5693 final long identity = Binder.clearCallingIdentity();
5694 try {
5695 Phone phone = getPhone(subscriptionId);
5696 if (phone == null) {
5697 return null;
5698 }
5699 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5700 } finally {
5701 Binder.restoreCallingIdentity(identity);
5702 }
5703 }
5704
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005705 /**
5706 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005707 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005708 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 final long identity = Binder.clearCallingIdentity();
5710 try {
5711 Phone phone = getPhone(subId);
5712 if (phone != null) {
5713 return phone.isWifiCallingEnabled();
5714 } else {
5715 return false;
5716 }
5717 } finally {
5718 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005719 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005720 }
5721
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005722 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005723 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005724 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005725 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 final long identity = Binder.clearCallingIdentity();
5727 try {
5728 Phone phone = getPhone(subId);
5729 if (phone != null) {
5730 return phone.isVideoEnabled();
5731 } else {
5732 return false;
5733 }
5734 } finally {
5735 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005736 }
5737 }
5738
5739 /**
5740 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5741 * defined in {@link ImsRegistrationImplBase}.
5742 */
5743 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005744 final long identity = Binder.clearCallingIdentity();
5745 try {
5746 Phone phone = getPhone(subId);
5747 if (phone != null) {
5748 return phone.getImsRegistrationTech();
5749 } else {
5750 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5751 }
5752 } finally {
5753 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005754 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005755 }
5756
Stuart Scott8eef64f2015-04-08 15:13:54 -07005757 @Override
5758 public void factoryReset(int subId) {
5759 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005760 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5761 return;
5762 }
5763
Svet Ganovcc087f82015-05-12 20:35:54 -07005764 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005765
Svet Ganovcc087f82015-05-12 20:35:54 -07005766 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005767 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5768 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005769 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005770 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005771 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005772 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5773 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005774 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005775 // There has been issues when Sms raw table somehow stores orphan
5776 // fragments. They lead to garbled message when new fragments come
5777 // in and combined with those stale ones. In case this happens again,
5778 // user can reset all network settings which will clean up this table.
5779 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005780 // Clean up IMS settings as well here.
5781 int slotId = getSlotIndex(subId);
5782 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5783 ImsManager.getInstance(mApp, slotId).factoryReset();
5784 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005785 } finally {
5786 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005787 }
5788 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005789
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005790 private void cleanUpSmsRawTable(Context context) {
5791 ContentResolver resolver = context.getContentResolver();
5792 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5793 resolver.delete(uri, null, null);
5794 }
5795
Narayan Kamath1c496c22015-04-16 14:40:19 +01005796 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005797 public String getSimLocaleForSubscriber(int subId) {
5798 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5799 final Phone phone = getPhone(subId);
5800 if (phone == null) {
5801 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005802 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005803 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 final long identity = Binder.clearCallingIdentity();
5805 try {
chen xu5d3637b2019-01-21 23:31:38 -08005806 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5807 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005808 if (info == null) {
5809 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5810 return null;
5811 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812 // Try and fetch the locale from the carrier properties or from the SIM language
5813 // preferences (EF-PL and EF-LI)...
5814 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005816 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5817 if (localeFromDefaultSim != null) {
5818 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5819 if (DBG) log("Using locale from subId: " + subId + " locale: "
5820 + localeFromDefaultSim);
5821 return localeFromDefaultSim.toLanguageTag();
5822 } else {
5823 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005824 }
5825 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 // The SIM language preferences only store a language (e.g. fr = French), not an
5828 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5829 // the SIM and carrier preferences does not include a country we add the country
5830 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005831 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005833 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005834 return mccLocale.toLanguageTag();
5835 }
5836
5837 if (DBG) log("No locale found - returning null");
5838 return null;
5839 } finally {
5840 Binder.restoreCallingIdentity(identity);
5841 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005842 }
5843
5844 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005845 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005846 }
5847
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848 /**
5849 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5850 */
5851 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005852 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005853 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005854
Chenjie Yu1ba97252018-01-11 18:16:20 -08005855 private final ModemActivityInfo mLastModemActivityInfo =
5856 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5857
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005858 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005859 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5860 * representing the state of the modem.
5861 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005862 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5863 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005864 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005865 */
5866 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005867 public void requestModemActivityInfo(ResultReceiver result) {
5868 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005869 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005870
5871 final long identity = Binder.clearCallingIdentity();
5872 try {
5873 ModemActivityInfo ret = null;
5874 synchronized (mLastModemActivityInfo) {
5875 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5876 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005877 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005878 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5880 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005881 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5882 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883 }
5884 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005885 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5886 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 mLastModemActivityInfo.setIdleTimeMillis(
5888 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5889 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5890 mLastModemActivityInfo.setRxTimeMillis(
5891 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5892 mLastModemActivityInfo.setEnergyUsed(
5893 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005894 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5896 mLastModemActivityInfo.getSleepTimeMillis(),
5897 mLastModemActivityInfo.getIdleTimeMillis(),
5898 mLastModemActivityInfo.getTxTimeMillis(),
5899 mLastModemActivityInfo.getRxTimeMillis(),
5900 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 Bundle bundle = new Bundle();
5903 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5904 result.send(0, bundle);
5905 } finally {
5906 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005907 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005908 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005909
Siddharth Rayb8114062018-06-17 15:02:38 -07005910 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5911 // less than total activity duration.
5912 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5913 if (info == null) {
5914 return false;
5915 }
5916 int activityDurationMs =
5917 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5918 int totalTxTimeMs = 0;
5919 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5920 totalTxTimeMs += info.getTxTimeMillis()[i];
5921 }
5922 return (info.isValid()
5923 && (info.getSleepTimeMillis() <= activityDurationMs)
5924 && (info.getIdleTimeMillis() <= activityDurationMs)
5925 && (info.getRxTimeMillis() <= activityDurationMs)
5926 && (totalTxTimeMs <= activityDurationMs));
5927 }
5928
Jack Yu85bd38a2015-11-09 11:34:32 -08005929 /**
5930 * {@hide}
5931 * Returns the service state information on specified subscription.
5932 */
5933 @Override
5934 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005936 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005937 return null;
5938 }
5939
Hall Liuf19c44f2018-11-27 14:38:17 -08005940 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5941 LocationAccessPolicy.checkLocationPermission(mApp,
5942 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5943 .setCallingPackage(callingPackage)
5944 .setCallingPid(Binder.getCallingPid())
5945 .setCallingUid(Binder.getCallingUid())
5946 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005947 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005948 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5949 .build());
5950
5951 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5952 LocationAccessPolicy.checkLocationPermission(mApp,
5953 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5954 .setCallingPackage(callingPackage)
5955 .setCallingPid(Binder.getCallingPid())
5956 .setCallingUid(Binder.getCallingUid())
5957 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005958 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005959 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5960 .build());
5961 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5962 boolean hasFinePermission =
5963 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5964 boolean hasCoarsePermission =
5965 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967 final long identity = Binder.clearCallingIdentity();
5968 try {
5969 final Phone phone = getPhone(subId);
5970 if (phone == null) {
5971 return null;
5972 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005973
Hall Liuf19c44f2018-11-27 14:38:17 -08005974 ServiceState ss = phone.getServiceState();
5975
5976 // Scrub out the location info in ServiceState depending on what level of access
5977 // the caller has.
5978 if (hasFinePermission) return ss;
5979 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5980 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 } finally {
5982 Binder.restoreCallingIdentity(identity);
5983 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005984 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005985
5986 /**
5987 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5988 *
5989 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5990 * voicemail ringtone.
5991 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5992 * PhoneAccount.
5993 */
5994 @Override
5995 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 final long identity = Binder.clearCallingIdentity();
5997 try {
5998 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5999 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006000 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6004 } finally {
6005 Binder.restoreCallingIdentity(identity);
6006 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006007 }
6008
6009 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006010 * Sets the per-account voicemail ringtone.
6011 *
6012 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6013 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6014 *
6015 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6016 * voicemail ringtone.
6017 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6018 * PhoneAccount.
6019 */
6020 @Override
6021 public void setVoicemailRingtoneUri(String callingPackage,
6022 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006023 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006024 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6025 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006026 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6028 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6029 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031
6032 final long identity = Binder.clearCallingIdentity();
6033 try {
6034 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6035 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006036 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037 }
6038 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6039 } finally {
6040 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006041 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006042 }
6043
6044 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006045 * Returns whether vibration is set for voicemail notification in Phone settings.
6046 *
6047 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6048 * voicemail vibration setting.
6049 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6050 */
6051 @Override
6052 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 final long identity = Binder.clearCallingIdentity();
6054 try {
6055 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6056 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006057 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006058 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6061 } finally {
6062 Binder.restoreCallingIdentity(identity);
6063 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006064 }
6065
Youhan Wange64578a2016-05-02 15:32:42 -07006066 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006067 * Sets the per-account voicemail vibration.
6068 *
6069 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6070 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6071 *
6072 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6073 * voicemail vibration setting.
6074 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6075 * specific PhoneAccount.
6076 */
6077 @Override
6078 public void setVoicemailVibrationEnabled(String callingPackage,
6079 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006080 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006081 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6082 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006083 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6085 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6086 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006087 }
6088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089 final long identity = Binder.clearCallingIdentity();
6090 try {
6091 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6092 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006093 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006094 }
6095 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6096 } finally {
6097 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006098 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006099 }
6100
6101 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006102 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6103 *
6104 * @throws SecurityException if the caller does not have the required permission
6105 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006106 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006107 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006108 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006109 }
6110
6111 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006112 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6113 * permission.
6114 *
6115 * @throws SecurityException if the caller does not have the required permission
6116 */
6117 private void enforceSendSmsPermission() {
6118 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6119 }
6120
6121 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006122 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006123 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006124 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006125 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006126 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006127 final long identity = Binder.clearCallingIdentity();
6128 try {
6129 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006130 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 if (componentName == null) {
6132 throw new SecurityException(
6133 "Caller not current active visual voicemail package[null]");
6134 }
6135 String vvmPackage = componentName.getPackageName();
6136 if (!callingPackage.equals(vvmPackage)) {
6137 throw new SecurityException("Caller not current active visual voicemail package["
6138 + vvmPackage + "]");
6139 }
6140 } finally {
6141 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006142 }
6143 }
6144
6145 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006146 * Return the application ID for the app type.
6147 *
6148 * @param subId the subscription ID that this request applies to.
6149 * @param appType the uicc app type.
6150 * @return Application ID for specificied app type, or null if no uicc.
6151 */
6152 @Override
6153 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006154 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006155 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156
6157 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006158 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 if (phone == null) {
6160 return null;
6161 }
6162 String aid = null;
6163 try {
6164 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6165 .getApplicationByType(appType).getAid();
6166 } catch (Exception e) {
6167 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6168 }
6169 return aid;
6170 } finally {
6171 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006172 }
Youhan Wange64578a2016-05-02 15:32:42 -07006173 }
6174
Youhan Wang4001d252016-05-11 10:29:41 -07006175 /**
6176 * Return the Electronic Serial Number.
6177 *
6178 * @param subId the subscription ID that this request applies to.
6179 * @return ESN or null if error.
6180 */
6181 @Override
6182 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006183 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006184 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006185
6186 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006187 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188 if (phone == null) {
6189 return null;
6190 }
6191 String esn = null;
6192 try {
6193 esn = phone.getEsn();
6194 } catch (Exception e) {
6195 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6196 }
6197 return esn;
6198 } finally {
6199 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006200 }
Youhan Wang4001d252016-05-11 10:29:41 -07006201 }
6202
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006203 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006204 * Return the Preferred Roaming List Version.
6205 *
6206 * @param subId the subscription ID that this request applies to.
6207 * @return PRLVersion or null if error.
6208 */
6209 @Override
6210 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006211 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006212 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006213
6214 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006215 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006216 if (phone == null) {
6217 return null;
6218 }
6219 String cdmaPrlVersion = null;
6220 try {
6221 cdmaPrlVersion = phone.getCdmaPrlVersion();
6222 } catch (Exception e) {
6223 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6224 }
6225 return cdmaPrlVersion;
6226 } finally {
6227 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006228 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006229 }
6230
6231 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006232 * Get snapshot of Telephony histograms
6233 * @return List of Telephony histograms
6234 * @hide
6235 */
6236 @Override
6237 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6239 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240
6241 final long identity = Binder.clearCallingIdentity();
6242 try {
6243 return RIL.getTelephonyRILTimingHistograms();
6244 } finally {
6245 Binder.restoreCallingIdentity(identity);
6246 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006247 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006248
6249 /**
6250 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006251 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6252 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006253 * Require system privileges. In the future we may add this to carrier APIs.
6254 *
Michele Berionne482f8202018-11-27 18:57:59 -08006255 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006256 */
6257 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006258 @TelephonyManager.SetCarrierRestrictionResult
6259 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006260 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006261 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006262
Michele Berionne482f8202018-11-27 18:57:59 -08006263 if (carrierRestrictionRules == null) {
6264 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006265 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006266
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 final long identity = Binder.clearCallingIdentity();
6268 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006269 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006270 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006271 } finally {
6272 Binder.restoreCallingIdentity(identity);
6273 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006274 }
6275
6276 /**
6277 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006278 * Get the allowed carrier list and the excluded carrier list, including the priority between
6279 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006280 * Require system privileges. In the future we may add this to carrier APIs.
6281 *
Michele Berionne482f8202018-11-27 18:57:59 -08006282 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006283 */
6284 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006285 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006286 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006287 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288
6289 final long identity = Binder.clearCallingIdentity();
6290 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006291 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6292 if (response instanceof CarrierRestrictionRules) {
6293 return (CarrierRestrictionRules) response;
6294 }
6295 // Response is an Exception of some kind,
6296 // which is signalled to the user as a NULL retval
6297 return null;
6298 } catch (Exception e) {
6299 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6300 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301 } finally {
6302 Binder.restoreCallingIdentity(identity);
6303 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006304 }
6305
fionaxu59545b42016-05-25 15:53:37 -07006306 /**
6307 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6308 * @param subId the subscription ID that this action applies to.
6309 * @param enabled control enable or disable metered apns.
6310 * {@hide}
6311 */
6312 @Override
6313 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6314 enforceModifyPermission();
6315 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316
6317 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006318 if (phone == null) {
6319 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6320 return;
6321 }
6322 try {
6323 phone.carrierActionSetMeteredApnsEnabled(enabled);
6324 } catch (Exception e) {
6325 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006326 } finally {
6327 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006328 }
6329 }
6330
6331 /**
6332 * Action set from carrier signalling broadcast receivers to enable/disable radio
6333 * @param subId the subscription ID that this action applies to.
6334 * @param enabled control enable or disable radio.
6335 * {@hide}
6336 */
6337 @Override
6338 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6339 enforceModifyPermission();
6340 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006341
6342 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006343 if (phone == null) {
6344 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6345 return;
6346 }
6347 try {
6348 phone.carrierActionSetRadioEnabled(enabled);
6349 } catch (Exception e) {
6350 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006351 } finally {
6352 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006353 }
6354 }
6355
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006356 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006357 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6358 * network status based on which carrier apps could apply actions accordingly,
6359 * enable/disable default url handler for example.
6360 *
6361 * @param subId the subscription ID that this action applies to.
6362 * @param report control start/stop reporting the default network status.
6363 * {@hide}
6364 */
6365 @Override
6366 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6367 enforceModifyPermission();
6368 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006369
6370 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006371 if (phone == null) {
6372 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6373 return;
6374 }
6375 try {
6376 phone.carrierActionReportDefaultNetworkStatus(report);
6377 } catch (Exception e) {
6378 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 } finally {
6380 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006381 }
6382 }
6383
6384 /**
fionaxud9622282017-07-17 17:51:30 -07006385 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6386 * @param subId the subscription ID that this action applies to.
6387 * {@hide}
6388 */
6389 @Override
6390 public void carrierActionResetAll(int subId) {
6391 enforceModifyPermission();
6392 final Phone phone = getPhone(subId);
6393 if (phone == null) {
6394 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6395 return;
6396 }
6397 try {
6398 phone.carrierActionResetAll();
6399 } catch (Exception e) {
6400 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6401 }
6402 }
6403
6404 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006405 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6406 * bug report is being generated.
6407 */
6408 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006409 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006410 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6411 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006412 writer.println("Permission Denial: can't dump Phone from pid="
6413 + Binder.getCallingPid()
6414 + ", uid=" + Binder.getCallingUid()
6415 + "without permission "
6416 + android.Manifest.permission.DUMP);
6417 return;
6418 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006419 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006420 }
Jack Yueb89b242016-06-22 13:27:47 -07006421
Brad Ebingerdac2f002018-04-03 15:17:52 -07006422 @Override
6423 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6424 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6425 throws RemoteException {
6426 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6427 }
6428
Jack Yueb89b242016-06-22 13:27:47 -07006429 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006430 * Get aggregated video call data usage since boot.
6431 *
6432 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6433 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006434 * {@hide}
6435 */
6436 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006437 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006438 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6439 null);
6440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006441 final long identity = Binder.clearCallingIdentity();
6442 try {
6443 // NetworkStatsService keeps tracking the active network interface and identity. It
6444 // records the delta with the corresponding network identity.
6445 // We just return the total video call data usage snapshot since boot.
6446 Phone phone = getPhone(subId);
6447 if (phone != null) {
6448 return phone.getVtDataUsage(perUidStats);
6449 }
6450 return null;
6451 } finally {
6452 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006453 }
Jack Yueb89b242016-06-22 13:27:47 -07006454 }
Jack Yu75ab2952016-07-08 14:29:33 -07006455
6456 /**
6457 * Policy control of data connection. Usually used when data limit is passed.
6458 * @param enabled True if enabling the data, otherwise disabling.
6459 * @param subId Subscription index
6460 * {@hide}
6461 */
6462 @Override
6463 public void setPolicyDataEnabled(boolean enabled, int subId) {
6464 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006465
6466 final long identity = Binder.clearCallingIdentity();
6467 try {
6468 Phone phone = getPhone(subId);
6469 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006470 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006471 }
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006474 }
6475 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006476
6477 /**
6478 * Get Client request stats
6479 * @return List of Client Request Stats
6480 * @hide
6481 */
6482 @Override
6483 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006484 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006485 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006486 return null;
6487 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006488 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490 final long identity = Binder.clearCallingIdentity();
6491 try {
6492 if (phone != null) {
6493 return phone.getClientRequestStats();
6494 }
6495
6496 return null;
6497 } finally {
6498 Binder.restoreCallingIdentity(identity);
6499 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006500 }
6501
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006502 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006503 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006504 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006505 }
Jack Yueb4124c2017-02-16 15:32:43 -08006506
6507 /**
Grace Chen70990072017-03-24 17:21:30 -07006508 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006509 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006510 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006511 * @param state State of SIM (power down, power up, pass through)
6512 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6513 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6514 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006515 *
6516 **/
6517 @Override
Grace Chen70990072017-03-24 17:21:30 -07006518 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006519 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006520 Phone phone = PhoneFactory.getPhone(slotIndex);
6521
vagdeviaf9a5b92018-08-15 16:01:53 -07006522 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006524 final long identity = Binder.clearCallingIdentity();
6525 try {
6526 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006527 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006528 }
6529 } finally {
6530 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006531 }
6532 }
Shuo Qiandd210312017-04-12 22:11:33 +00006533
Tyler Gunn65d45c22017-06-05 11:22:26 -07006534 private boolean isUssdApiAllowed(int subId) {
6535 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006536 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006537 if (configManager == null) {
6538 return false;
6539 }
6540 PersistableBundle pb = configManager.getConfigForSubId(subId);
6541 if (pb == null) {
6542 return false;
6543 }
6544 return pb.getBoolean(
6545 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6546 }
6547
Shuo Qiandd210312017-04-12 22:11:33 +00006548 /**
6549 * Check if phone is in emergency callback mode
6550 * @return true if phone is in emergency callback mode
6551 * @param subId sub id
6552 */
goneil9c5f4872017-12-05 14:07:56 -08006553 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006554 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006555 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006556 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557
6558 final long identity = Binder.clearCallingIdentity();
6559 try {
6560 if (phone != null) {
6561 return phone.isInEcm();
6562 } else {
6563 return false;
6564 }
6565 } finally {
6566 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006567 }
6568 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006569
6570 /**
6571 * Get the current signal strength information for the given subscription.
6572 * Because this information is not updated when the device is in a low power state
6573 * it should not be relied-upon to be current.
6574 * @param subId Subscription index
6575 * @return the most recent cached signal strength info from the modem
6576 */
6577 @Override
6578 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006579 final long identity = Binder.clearCallingIdentity();
6580 try {
6581 Phone p = getPhone(subId);
6582 if (p == null) {
6583 return null;
6584 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006585
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586 return p.getSignalStrength();
6587 } finally {
6588 Binder.restoreCallingIdentity(identity);
6589 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006590 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006591
Pengquan Meng77b7f132018-08-22 14:49:57 -07006592 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006593 * Get the current modem radio state for the given slot.
6594 * @param slotIndex slot index.
6595 * @param callingPackage the name of the package making the call.
6596 * @return the current radio power state from the modem
6597 */
6598 @Override
6599 public int getRadioPowerState(int slotIndex, String callingPackage) {
6600 Phone phone = PhoneFactory.getPhone(slotIndex);
6601 if (phone != null) {
6602 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6603 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6604 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6605 }
6606
6607 final long identity = Binder.clearCallingIdentity();
6608 try {
6609 return phone.getRadioPowerState();
6610 } finally {
6611 Binder.restoreCallingIdentity(identity);
6612 }
6613 }
6614 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6615 }
6616
6617 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006618 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6619 *
6620 * <p>Requires one of the following permissions:
6621 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6622 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6623 * privileges.
6624 *
6625 * @param subId subscription id
6626 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6627 * {@code false}.
6628 */
6629 @Override
6630 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006631 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6632 null /* message */);
6633
Pengquan Menga1bb6272018-09-06 09:59:22 -07006634 boolean isEnabled = false;
6635 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006636 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006637 Phone phone = getPhone(subId);
6638 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006639 } catch (Exception e) {
6640 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6641 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006642 } finally {
6643 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006644 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006645 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006646 }
6647
6648
6649 /**
6650 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6651 *
6652 * <p> Requires permission:
6653 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6654 * privileges.
6655 *
6656 * @param subId subscription id
6657 * @param isEnabled {@code true} means enable, {@code false} means disable.
6658 */
6659 @Override
6660 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6662 mApp, subId, "setDataRoamingEnabled");
6663
Pengquan Menga1bb6272018-09-06 09:59:22 -07006664 final long identity = Binder.clearCallingIdentity();
6665 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006666 Phone phone = getPhone(subId);
6667 if (phone != null) {
6668 phone.setDataRoamingEnabled(isEnabled);
6669 }
6670 } finally {
6671 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006672 }
6673 }
6674
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006675 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006676 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006677 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6678 mApp, subId, "isManualNetworkSelectionAllowed");
6679
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006680 boolean isAllowed = true;
6681 final long identity = Binder.clearCallingIdentity();
6682 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006683 Phone phone = getPhone(subId);
6684 if (phone != null) {
6685 isAllowed = phone.isCspPlmnEnabled();
6686 }
6687 } finally {
6688 Binder.restoreCallingIdentity(identity);
6689 }
6690 return isAllowed;
6691 }
6692
6693 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006694 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006695 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006696 try {
6697 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006698 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006699 } catch (SecurityException e) {
6700 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6701 // has carrier privileges on an active UICC
6702 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6703 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006704 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006705 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006706 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006707
6708 final long identity = Binder.clearCallingIdentity();
6709 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006710 UiccController uiccController = UiccController.getInstance();
6711 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006712 if (hasReadPermission) {
6713 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006714 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006715
6716 // Remove private info if the caller doesn't have access
6717 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6718 for (UiccCardInfo cardInfo : cardInfos) {
6719 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6720 // is available
6721 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6722 if (card == null || card.getUiccProfile() == null) {
6723 // assume no access if the card or profile is unavailable
6724 filteredInfos.add(cardInfo.getUnprivileged());
6725 continue;
6726 }
6727 UiccProfile profile = card.getUiccProfile();
6728 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6729 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6730 filteredInfos.add(cardInfo);
6731 } else {
6732 filteredInfos.add(cardInfo.getUnprivileged());
6733 }
6734 }
6735 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006736 } finally {
6737 Binder.restoreCallingIdentity(identity);
6738 }
6739 }
6740
6741 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006742 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006743 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745 final long identity = Binder.clearCallingIdentity();
6746 try {
6747 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6748 if (slots == null) {
6749 Rlog.i(LOG_TAG, "slots is null.");
6750 return null;
6751 }
6752
6753 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6754 for (int i = 0; i < slots.length; i++) {
6755 UiccSlot slot = slots[i];
6756 if (slot == null) {
6757 continue;
6758 }
6759
Jordan Liu7be7e652019-05-06 18:55:02 +00006760 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761 UiccCard card = slot.getUiccCard();
6762 if (card != null) {
6763 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006764 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006765 cardId = slot.getEid();
6766 if (TextUtils.isEmpty(cardId)) {
6767 cardId = slot.getIccId();
6768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006769 }
6770
Jordan Liu857451f2019-05-09 16:35:35 -07006771 if (cardId != null) {
6772 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6773 // if cardId is an EID, it's all digits so this is fine
6774 cardId = IccUtils.stripTrailingFs(cardId);
6775 }
6776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006777 int cardState = 0;
6778 switch (slot.getCardState()) {
6779 case CARDSTATE_ABSENT:
6780 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6781 break;
6782 case CARDSTATE_PRESENT:
6783 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6784 break;
6785 case CARDSTATE_ERROR:
6786 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6787 break;
6788 case CARDSTATE_RESTRICTED:
6789 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6790 break;
6791 default:
6792 break;
6793
6794 }
6795
6796 infos[i] = new UiccSlotInfo(
6797 slot.isActive(),
6798 slot.isEuicc(),
6799 cardId,
6800 cardState,
6801 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006802 slot.isExtendedApduSupported(),
6803 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006804 }
6805 return infos;
6806 } finally {
6807 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006808 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006809 }
6810
6811 @Override
6812 public boolean switchSlots(int[] physicalSlots) {
6813 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006814
6815 final long identity = Binder.clearCallingIdentity();
6816 try {
6817 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6818 } finally {
6819 Binder.restoreCallingIdentity(identity);
6820 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006821 }
Jack Yu4c988042018-02-27 15:30:01 -08006822
6823 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006824 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006825 final long identity = Binder.clearCallingIdentity();
6826 try {
6827 return UiccController.getInstance().getCardIdForDefaultEuicc();
6828 } finally {
6829 Binder.restoreCallingIdentity(identity);
6830 }
6831 }
6832
6833 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006834 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6835 enforceModifyPermission();
6836 final Phone phone = getPhone(subId);
6837 if (phone == null) {
6838 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6839 return;
6840 }
6841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006842 final long identity = Binder.clearCallingIdentity();
6843 try {
6844 phone.setRadioIndicationUpdateMode(filters, mode);
6845 } finally {
6846 Binder.restoreCallingIdentity(identity);
6847 }
Jack Yu4c988042018-02-27 15:30:01 -08006848 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006849
6850 /**
goneil47ffb6e2018-04-06 15:40:58 -07006851 * A test API to reload the UICC profile.
6852 *
6853 * <p>Requires that the calling app has permission
6854 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6855 * @hide
6856 */
6857 @Override
6858 public void refreshUiccProfile(int subId) {
6859 enforceModifyPermission();
6860
6861 final long identity = Binder.clearCallingIdentity();
6862 try {
6863 Phone phone = getPhone(subId);
6864 if (phone == null) {
6865 return;
6866 }
6867 UiccCard uiccCard = phone.getUiccCard();
6868 if (uiccCard == null) {
6869 return;
6870 }
6871 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6872 if (uiccProfile == null) {
6873 return;
6874 }
6875 uiccProfile.refresh();
6876 } finally {
6877 Binder.restoreCallingIdentity(identity);
6878 }
6879 }
6880
6881 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006882 * Returns false if the mobile data is disabled by default, otherwise return true.
6883 */
6884 private boolean getDefaultDataEnabled() {
6885 return "true".equalsIgnoreCase(
6886 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6887 }
6888
6889 /**
6890 * Returns true if the data roaming is enabled by default, i.e the system property
6891 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6892 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6893 */
6894 private boolean getDefaultDataRoamingEnabled(int subId) {
6895 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006896 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006897 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6898 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6899 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6900 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6901 return isDataRoamingEnabled;
6902 }
6903
6904 /**
6905 * Returns the default network type for the given {@code subId}, if the default network type is
6906 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6907 */
6908 private int getDefaultNetworkType(int subId) {
6909 return Integer.parseInt(
6910 TelephonyManager.getTelephonyProperty(
6911 mSubscriptionController.getPhoneId(subId),
6912 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6913 String.valueOf(Phone.PREFERRED_NT_MODE)));
6914 }
fionaxua13278b2018-03-21 00:08:13 -07006915
6916 @Override
6917 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006918 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006919 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006920
6921 final long identity = Binder.clearCallingIdentity();
6922 try {
6923 final Phone phone = getPhone(subId);
6924 if (phone == null) {
6925 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6926 return;
6927 }
chen xueaba88a2019-03-15 13:15:10 -07006928 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6929 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006930 } finally {
6931 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006932 }
fionaxua13278b2018-03-21 00:08:13 -07006933 }
6934
6935 @Override
6936 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006937 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006938
6939 final long identity = Binder.clearCallingIdentity();
6940 try {
6941 final Phone phone = getPhone(subId);
6942 if (phone == null) {
6943 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6944 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6945 }
6946 return phone.getCarrierIdListVersion();
6947 } finally {
6948 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006949 }
fionaxua13278b2018-03-21 00:08:13 -07006950 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006951
6952 @Override
6953 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6954 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6955 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6956 return -1;
6957 }
6958
6959 final long identity = Binder.clearCallingIdentity();
6960 try {
6961 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6962 } finally {
6963 Binder.restoreCallingIdentity(identity);
6964 }
6965 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006966
6967 @Override
6968 public int getCdmaRoamingMode(int subId) {
6969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6970 mApp, subId, "getCdmaRoamingMode");
6971
6972 final long identity = Binder.clearCallingIdentity();
6973 try {
6974 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6975 } finally {
6976 Binder.restoreCallingIdentity(identity);
6977 }
6978 }
6979
6980 @Override
6981 public boolean setCdmaRoamingMode(int subId, int mode) {
6982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6983 mApp, subId, "setCdmaRoamingMode");
6984
6985 final long identity = Binder.clearCallingIdentity();
6986 try {
6987 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6988 } finally {
6989 Binder.restoreCallingIdentity(identity);
6990 }
6991 }
6992
6993 @Override
6994 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6996 mApp, subId, "setCdmaSubscriptionMode");
6997
6998 final long identity = Binder.clearCallingIdentity();
6999 try {
7000 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7001 } finally {
7002 Binder.restoreCallingIdentity(identity);
7003 }
7004 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007005
sqianc5eccab2018-10-19 18:46:41 -07007006 @Override
sqian8c685422019-02-22 15:55:18 -08007007 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007008 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007009 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007010 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007011 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7012 }
7013 final long identity = Binder.clearCallingIdentity();
7014 try {
sqian854d44b2018-12-12 16:48:18 -08007015 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7016 for (Phone phone: PhoneFactory.getPhones()) {
7017 if (phone.getEmergencyNumberTracker() != null
7018 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7019 emergencyNumberListInternal.put(
7020 phone.getSubId(),
7021 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7022 }
sqian11b7a0e2018-12-05 18:48:28 -08007023 }
sqian854d44b2018-12-12 16:48:18 -08007024 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007025 } finally {
7026 Binder.restoreCallingIdentity(identity);
7027 }
sqianc5eccab2018-10-19 18:46:41 -07007028 }
7029
7030 @Override
sqian8c685422019-02-22 15:55:18 -08007031 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007032 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007033 if (!exactMatch) {
7034 TelephonyPermissions
7035 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007036 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007037 }
7038 final long identity = Binder.clearCallingIdentity();
7039 try {
sqian854d44b2018-12-12 16:48:18 -08007040 for (Phone phone: PhoneFactory.getPhones()) {
7041 if (phone.getEmergencyNumberTracker() != null
7042 && phone.getEmergencyNumberTracker() != null) {
7043 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7044 number, exactMatch)) {
7045 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007046 }
7047 }
sqian11b7a0e2018-12-05 18:48:28 -08007048 }
7049 return false;
7050 } finally {
7051 Binder.restoreCallingIdentity(identity);
7052 }
7053 }
7054
sqianf4ca7ed2019-01-15 18:32:07 -08007055 /**
7056 * Update emergency number list for test mode.
7057 */
7058 @Override
7059 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7060 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7061 "updateEmergencyNumberListTestMode");
7062
7063 final long identity = Binder.clearCallingIdentity();
7064 try {
7065 for (Phone phone: PhoneFactory.getPhones()) {
7066 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7067 if (tracker != null) {
7068 tracker.executeEmergencyNumberTestModeCommand(action, num);
7069 }
7070 }
7071 } finally {
7072 Binder.restoreCallingIdentity(identity);
7073 }
7074 }
7075
7076 /**
7077 * Get the full emergency number list for test mode.
7078 */
7079 @Override
7080 public List<String> getEmergencyNumberListTestMode() {
7081 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7082 "getEmergencyNumberListTestMode");
7083
7084 final long identity = Binder.clearCallingIdentity();
7085 try {
7086 Set<String> emergencyNumbers = new HashSet<>();
7087 for (Phone phone: PhoneFactory.getPhones()) {
7088 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7089 if (tracker != null) {
7090 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7091 emergencyNumbers.add(num.getNumber());
7092 }
7093 }
7094 }
7095 return new ArrayList<>(emergencyNumbers);
7096 } finally {
7097 Binder.restoreCallingIdentity(identity);
7098 }
7099 }
7100
chen xud6b45bd2018-10-30 22:27:10 -07007101 @Override
7102 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7103 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7104 Phone phone = getPhone(subId);
7105 if (phone == null) {
7106 return null;
7107 }
7108 final long identity = Binder.clearCallingIdentity();
7109 try {
7110 UiccProfile profile = UiccController.getInstance()
7111 .getUiccProfileForPhone(phone.getPhoneId());
7112 if (profile != null) {
7113 return profile.getCertsFromCarrierPrivilegeAccessRules();
7114 }
7115 } finally {
7116 Binder.restoreCallingIdentity(identity);
7117 }
7118 return null;
7119 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007120
7121 /**
7122 * Enable or disable a modem stack.
7123 */
7124 @Override
7125 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7126 enforceModifyPermission();
7127
7128 final long identity = Binder.clearCallingIdentity();
7129 try {
7130 Phone phone = PhoneFactory.getPhone(slotIndex);
7131 if (phone == null) {
7132 return false;
7133 } else {
7134 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7135 }
7136 } finally {
7137 Binder.restoreCallingIdentity(identity);
7138 }
7139 }
Michelecea4cf22018-12-21 15:00:11 -08007140
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007141 /**
7142 * Whether a modem stack is enabled or not.
7143 */
7144 @Override
7145 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7146 Phone phone = PhoneFactory.getPhone(slotIndex);
7147 if (phone == null) return false;
7148
7149 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7150 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7151 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7152 }
7153
7154 final long identity = Binder.clearCallingIdentity();
7155 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007156 try {
7157 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7158 } catch (NoSuchElementException ex) {
7159 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7160 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007161 } finally {
7162 Binder.restoreCallingIdentity(identity);
7163 }
7164 }
7165
Michelecea4cf22018-12-21 15:00:11 -08007166 @Override
Michele0ea7d782019-03-19 14:58:42 -07007167 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007168 enforceModifyPermission();
7169
7170 final long identity = Binder.clearCallingIdentity();
7171 try {
7172 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007173 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007174 .commit();
7175 } finally {
7176 Binder.restoreCallingIdentity(identity);
7177 }
7178 }
7179
7180 @Override
Michele0ea7d782019-03-19 14:58:42 -07007181 @TelephonyManager.IsMultiSimSupportedResult
7182 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007183 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007184 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7185 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007186 }
Michelecea4cf22018-12-21 15:00:11 -08007187
7188 final long identity = Binder.clearCallingIdentity();
7189 try {
Michele0ea7d782019-03-19 14:58:42 -07007190 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007191 } finally {
7192 Binder.restoreCallingIdentity(identity);
7193 }
7194 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007195
Michele0ea7d782019-03-19 14:58:42 -07007196 @TelephonyManager.IsMultiSimSupportedResult
7197 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007198 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7199 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7200 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007201 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7202 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007203 }
7204 // Check if the hardware supports multisim functionality. If usage of multisim is not
7205 // supported by the modem, indicate that it is restricted.
7206 PhoneCapability staticCapability =
7207 mPhoneConfigurationManager.getStaticPhoneCapability();
7208 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007209 loge("isMultiSimSupportedInternal: no static configuration available");
7210 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007211 }
7212 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007213 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7214 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007215 }
7216 // Check if support of multiple SIMs is restricted by carrier
7217 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007218 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007219 }
7220
Michele0ea7d782019-03-19 14:58:42 -07007221 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007222 }
7223
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007224 /**
7225 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007226 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7227 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7228 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007229 * @param numOfSims number of active sims we want to switch to
7230 */
7231 @Override
7232 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007233 if (numOfSims == 1) {
7234 enforceModifyPermission();
7235 } else {
7236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7237 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7238 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007239 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007240
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007241 try {
Michele30b57b22019-03-01 12:01:14 -08007242 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007243 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007244 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7245 return;
7246 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007247 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7248 } finally {
7249 Binder.restoreCallingIdentity(identity);
7250 }
7251 }
7252
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007253 @Override
7254 public boolean isApplicationOnUicc(int subId, int appType) {
7255 enforceReadPrivilegedPermission("isApplicationOnUicc");
7256 Phone phone = getPhone(subId);
7257 if (phone == null) {
7258 return false;
7259 }
7260 final long identity = Binder.clearCallingIdentity();
7261 try {
7262 UiccCard uiccCard = phone.getUiccCard();
7263 if (uiccCard == null) {
7264 return false;
7265 }
7266 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7267 if (uiccProfile == null) {
7268 return false;
7269 }
7270 if (TelephonyManager.APPTYPE_SIM <= appType
7271 && appType <= TelephonyManager.APPTYPE_ISIM) {
7272 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7273 }
7274 return false;
7275 } finally {
7276 Binder.restoreCallingIdentity(identity);
7277 }
7278 }
7279
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007280 /**
chen xub4baa772019-04-03 10:23:41 -07007281 * Get whether making changes to modem configurations will trigger reboot.
7282 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007283 */
7284 @Override
chen xub4baa772019-04-03 10:23:41 -07007285 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7287 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7288 return false;
7289 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007290 final long identity = Binder.clearCallingIdentity();
7291 try {
7292 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7293 } finally {
7294 Binder.restoreCallingIdentity(identity);
7295 }
7296 }
7297
Nathan Harold29f5f052019-02-15 13:41:57 -08007298 private void updateModemStateMetrics() {
7299 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7300 // TODO: check the state for each modem if the api is ready.
7301 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7302 }
7303
Pengquan Meng3889a572019-01-23 11:16:29 -08007304 @Override
7305 public int[] getSlotsMapping() {
7306 enforceReadPrivilegedPermission("getSlotsMapping");
7307
7308 final long identity = Binder.clearCallingIdentity();
7309 try {
7310 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7311 // All logical slots should have a mapping to a physical slot.
7312 int[] logicalSlotsMapping = new int[phoneCount];
7313 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7314 for (int i = 0; i < slotInfos.length; i++) {
7315 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7316 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7317 }
7318 }
7319 return logicalSlotsMapping;
7320 } finally {
7321 Binder.restoreCallingIdentity(identity);
7322 }
7323 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007324
7325 /**
7326 * Get the IRadio HAL Version
7327 */
7328 @Override
7329 public int getRadioHalVersion() {
7330 Phone phone = getDefaultPhone();
7331 if (phone == null) return -1;
7332 HalVersion hv = phone.getHalVersion();
7333 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7334 return hv.major * 100 + hv.minor;
7335 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007336
7337 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007338 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7339 * corresponding network requests on a subId.
7340 *
7341 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007342 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007343 * 2) APN is un-metered for this subscription, or
7344 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7345 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7346 *
7347 * @return whether data is allowed for a apn type.
7348 *
7349 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007350 */
7351 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007352 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007353 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7354 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007355
7356 // Now that all security checks passes, perform the operation as ourselves.
7357 final long identity = Binder.clearCallingIdentity();
7358 try {
7359 Phone phone = getPhone(subId);
7360 if (phone == null) return false;
7361
Jack Yu41407ee2019-05-13 16:54:09 -07007362 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007363 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7364 } finally {
7365 Binder.restoreCallingIdentity(identity);
7366 }
7367 }
7368
7369 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007370 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007371 enforceReadPrivilegedPermission("isApnMetered");
7372
7373 // Now that all security checks passes, perform the operation as ourselves.
7374 final long identity = Binder.clearCallingIdentity();
7375 try {
7376 Phone phone = getPhone(subId);
7377 if (phone == null) return true; // By default return true.
7378
Jack Yu41407ee2019-05-13 16:54:09 -07007379 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007380 } finally {
7381 Binder.restoreCallingIdentity(identity);
7382 }
7383 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007384
7385 @Override
7386 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7387 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7388 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7389 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7390 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7391 }
7392 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7393 Intent intent = new Intent();
7394 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7395 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7396 // Bring up choose default SMS subscription dialog right now
7397 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7398 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7399 mApp.startActivity(intent);
7400 }
chen xud5ca2d52019-05-28 15:20:57 -07007401
7402 @Override
7403 public String getMmsUAProfUrl(int subId) {
7404 //TODO investigate if this API should require proper permission check in R b/133791609
7405 final long identity = Binder.clearCallingIdentity();
7406 try {
7407 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7408 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7409 } finally {
7410 Binder.restoreCallingIdentity(identity);
7411 }
7412 }
7413
7414 @Override
7415 public String getMmsUserAgent(int subId) {
7416 //TODO investigate if this API should require proper permission check in R b/133791609
7417 final long identity = Binder.clearCallingIdentity();
7418 try {
7419 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7420 .getString(com.android.internal.R.string.config_mms_user_agent);
7421 } finally {
7422 Binder.restoreCallingIdentity(identity);
7423 }
7424 }
Jack Yub07d4972019-05-28 16:12:25 -07007425
7426 @Override
7427 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7428 enforceModifyPermission();
7429
7430 // Now that all security checks passes, perform the operation as ourselves.
7431 final long identity = Binder.clearCallingIdentity();
7432 try {
7433 Phone phone = getPhone(subId);
7434 if (phone == null) return false;
7435
7436 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7437 } finally {
7438 Binder.restoreCallingIdentity(identity);
7439 }
7440 }
7441
7442 @Override
7443 public boolean isDataAllowedInVoiceCall(int subId) {
7444 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7445
7446 // Now that all security checks passes, perform the operation as ourselves.
7447 final long identity = Binder.clearCallingIdentity();
7448 try {
7449 Phone phone = getPhone(subId);
7450 if (phone == null) return false;
7451
7452 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7453 } finally {
7454 Binder.restoreCallingIdentity(identity);
7455 }
7456 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007457
7458 /**
7459 * Updates whether conference event pacakge handling is enabled.
7460 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7461 * otherwise.
7462 */
7463 @Override
7464 public void setCepEnabled(boolean isCepEnabled) {
7465 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7466
7467 final long identity = Binder.clearCallingIdentity();
7468 try {
7469 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7470 for (Phone phone : PhoneFactory.getPhones()) {
7471 Phone defaultPhone = phone.getImsPhone();
7472 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7473 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7474 ImsPhoneCallTracker imsPhoneCallTracker =
7475 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7476 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7477 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7478 + imsPhone.getMsisdn());
7479 }
7480 }
7481 } finally {
7482 Binder.restoreCallingIdentity(identity);
7483 }
7484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007485}