blob: b679ba3623973f8e08a5ead00b4fea9a7f96b9cf [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;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070038import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080049import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070050import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070051import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070067import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080068import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070069import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080070import android.telephony.CellIdentityCdma;
71import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070073import android.telephony.CellInfoGsm;
74import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070075import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070076import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070077import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080078import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070079import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080080import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070081import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080082import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080083import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070084import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080085import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080087import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080088import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080089import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080090import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070091import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070092import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080093import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080094import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000095import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070096import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070097import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.data.ApnSetting;
99import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700100import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800101import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700102import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800104import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700105import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsMmTelFeature;
107import android.telephony.ims.aidl.IImsRcsFeature;
108import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700109import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700110import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800112import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800114import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800130import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700131import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800132import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800134import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700135import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700136import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700139import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800140import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700141import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700142import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700143import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700144import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700145import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700146import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700147import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800149import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800150import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700151import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800152import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700153import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800154import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700155import com.android.internal.telephony.imsphone.ImsPhone;
156import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800157import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800160import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800162import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700163import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000167import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800168import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700169import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800170import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700171import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700172import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800173import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700175import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800176import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800177
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700178import java.io.FileDescriptor;
179import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800181import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800182import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800183import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800184import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100185import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700187import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
190/**
191 * Implementation of the ITelephony interface.
192 */
Santos Cordon117fee72014-05-16 17:56:12 -0700193public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 private static final String LOG_TAG = "PhoneInterfaceManager";
195 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
196 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800197 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198
199 // Message codes used with mMainThreadHandler
200 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700201 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
202 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203 private static final int CMD_OPEN_CHANNEL = 9;
204 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
205 private static final int CMD_CLOSE_CHANNEL = 11;
206 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800207 private static final int CMD_NV_READ_ITEM = 13;
208 private static final int EVENT_NV_READ_ITEM_DONE = 14;
209 private static final int CMD_NV_WRITE_ITEM = 15;
210 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
211 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
212 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700213 private static final int CMD_RESET_MODEM_CONFIG = 19;
214 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800215 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
216 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
217 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
218 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800219 private static final int CMD_SEND_ENVELOPE = 25;
220 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000221 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
222 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700223 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
224 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
225 private static final int CMD_EXCHANGE_SIM_IO = 31;
226 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800227 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
228 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700229 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
230 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700231 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
232 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700233 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
234 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
235 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
236 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700237 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
238 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
239 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
240 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700241 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800242 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
243 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000244 private static final int CMD_SWITCH_SLOTS = 50;
245 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700246 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
247 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
248 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
249 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
250 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
251 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
252 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
253 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700254 private static final int CMD_GET_ALL_CELL_INFO = 60;
255 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
256 private static final int CMD_GET_CELL_LOCATION = 62;
257 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700258 private static final int CMD_MODEM_REBOOT = 64;
259 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700260 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
261 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800262 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
263 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700264 private static final int CMD_GET_MODEM_STATUS = 70;
265 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700266 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
267 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700268 private static final int CMD_ERASE_MODEM_CONFIG = 74;
269 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800271 // Parameters of select command.
272 private static final int SELECT_COMMAND = 0xA4;
273 private static final int SELECT_P1 = 0x04;
274 private static final int SELECT_P2 = 0;
275 private static final int SELECT_P3 = 0x10;
276
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277 /** The singleton instance. */
278 private static PhoneInterfaceManager sInstance;
279
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800282 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700283 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private AppOpsManager mAppOps;
285 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800286 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800287 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700288 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289
Derek Tan97ebb422014-09-05 16:55:38 -0700290 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
291 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800292 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800293 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700294
Michelecea4cf22018-12-21 15:00:11 -0800295 // String to store multi SIM allowed
296 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
297
Derek Tan740e1672017-06-27 14:56:27 -0700298 // The AID of ISD-R.
299 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
300
yinxub1bed742017-04-17 11:45:04 -0700301 private NetworkScanRequestTracker mNetworkScanRequestTracker;
302
David Kelly5e06a7f2018-03-12 14:10:59 +0000303 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
304 private static final int MANUFACTURER_CODE_LENGTH = 8;
305
Derek Tan89e89d42014-07-08 17:00:10 -0700306 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700307 * Experiment flag to enable erase modem config on reset network, default value is false
308 */
309 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
310 "reset_network_erase_modem_config_enabled";
311
312 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700313 * A request object to use for transmitting data to an ICC.
314 */
315 private static final class IccAPDUArgument {
316 public int channel, cla, command, p1, p2, p3;
317 public String data;
318
319 public IccAPDUArgument(int channel, int cla, int command,
320 int p1, int p2, int p3, String data) {
321 this.channel = channel;
322 this.cla = cla;
323 this.command = command;
324 this.p1 = p1;
325 this.p2 = p2;
326 this.p3 = p3;
327 this.data = data;
328 }
329 }
330
331 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700332 * A request object to use for transmitting data to an ICC.
333 */
334 private static final class ManualNetworkSelectionArgument {
335 public OperatorInfo operatorInfo;
336 public boolean persistSelection;
337
338 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
339 this.operatorInfo = operatorInfo;
340 this.persistSelection = persistSelection;
341 }
342 }
343
344 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
346 * request after sending. The main thread will notify the request when it is complete.
347 */
348 private static final class MainThreadRequest {
349 /** The argument to use for the request */
350 public Object argument;
351 /** The result of the request that is run on the main thread */
352 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800353 // The subscriber id that this request applies to. Defaults to
354 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
355 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356
Nathan Harold92bed182018-10-12 18:16:49 -0700357 // In cases where subId is unavailable, the caller needs to specify the phone.
358 public Phone phone;
359
vagdeviaf9a5b92018-08-15 16:01:53 -0700360 public WorkSource workSource;
361
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 public MainThreadRequest(Object argument) {
363 this.argument = argument;
364 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800365
Nathan Harold92bed182018-10-12 18:16:49 -0700366 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
367 this.argument = argument;
368 if (phone != null) {
369 this.phone = phone;
370 }
371 this.workSource = workSource;
372 }
373
vagdeviaf9a5b92018-08-15 16:01:53 -0700374 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800375 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800376 if (subId != null) {
377 this.subId = subId;
378 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700379 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 }
382
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800383 private static final class IncomingThirdPartyCallArgs {
384 public final ComponentName component;
385 public final String callId;
386 public final String callerDisplayName;
387
388 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
389 String callerDisplayName) {
390 this.component = component;
391 this.callId = callId;
392 this.callerDisplayName = callerDisplayName;
393 }
394 }
395
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 /**
397 * A handler that processes messages on the main thread in the phone process. Since many
398 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
399 * inbound binder threads to the main thread in the phone process. The Binder thread
400 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
401 * on, which will be notified when the operation completes and will contain the result of the
402 * request.
403 *
404 * <p>If a MainThreadRequest object is provided in the msg.obj field,
405 * note that request.result must be set to something non-null for the calling thread to
406 * unblock.
407 */
408 private final class MainThreadHandler extends Handler {
409 @Override
410 public void handleMessage(Message msg) {
411 MainThreadRequest request;
412 Message onCompleted;
413 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800414 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800416 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
418 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700419 case CMD_HANDLE_USSD_REQUEST: {
420 request = (MainThreadRequest) msg.obj;
421 final Phone phone = getPhoneFromRequest(request);
422 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
423 String ussdRequest = ussdObject.first;
424 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700425
Pengquan Menga1bb6272018-09-06 09:59:22 -0700426 if (!isUssdApiAllowed(request.subId)) {
427 // Carrier does not support use of this API, return failure.
428 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
429 UssdResponse response = new UssdResponse(ussdRequest, null);
430 Bundle returnData = new Bundle();
431 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
432 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700433
Pengquan Menga1bb6272018-09-06 09:59:22 -0700434 request.result = true;
435 notifyRequester(request);
436 return;
437 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700438
Pengquan Menga1bb6272018-09-06 09:59:22 -0700439 try {
440 request.result = phone != null
441 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
442 } catch (CallStateException cse) {
443 request.result = false;
444 }
445 // Wake up the requesting thread
446 notifyRequester(request);
447 break;
pkanwar32d516d2016-10-14 19:37:38 -0700448 }
449
Yorke Lee716f67e2015-06-17 15:39:16 -0700450 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700452 final Phone phone = getPhoneFromRequest(request);
453 request.result = phone != null ?
454 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
455 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700457 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800464 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700465 if (uiccCard == null) {
466 loge("iccTransmitApduLogicalChannel: No UICC");
467 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700468 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700469 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
471 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700472 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700473 iccArgument.channel, iccArgument.cla, iccArgument.command,
474 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700476 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 break;
478
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 ar = (AsyncResult) msg.obj;
481 request = (MainThreadRequest) ar.userObj;
482 if (ar.exception == null && ar.result != null) {
483 request.result = ar.result;
484 } else {
485 request.result = new IccIoResult(0x6F, 0, (byte[])null);
486 if (ar.result == null) {
487 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800488 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800490 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700491 } else {
492 loge("iccTransmitApduLogicalChannel: Unknown exception");
493 }
494 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700496 break;
497
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
499 request = (MainThreadRequest) msg.obj;
500 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800501 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 if (uiccCard == null) {
503 loge("iccTransmitApduBasicChannel: No UICC");
504 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700505 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700506 } else {
507 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
508 request);
509 uiccCard.iccTransmitApduBasicChannel(
510 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
511 iccArgument.p3, iccArgument.data, onCompleted);
512 }
513 break;
514
515 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
516 ar = (AsyncResult) msg.obj;
517 request = (MainThreadRequest) ar.userObj;
518 if (ar.exception == null && ar.result != null) {
519 request.result = ar.result;
520 } else {
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
522 if (ar.result == null) {
523 loge("iccTransmitApduBasicChannel: Empty response");
524 } else if (ar.exception instanceof CommandException) {
525 loge("iccTransmitApduBasicChannel: CommandException: " +
526 ar.exception);
527 } else {
528 loge("iccTransmitApduBasicChannel: Unknown exception");
529 }
530 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 break;
533
534 case CMD_EXCHANGE_SIM_IO:
535 request = (MainThreadRequest) msg.obj;
536 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800537 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 if (uiccCard == null) {
539 loge("iccExchangeSimIO: No UICC");
540 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700541 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 } else {
543 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
544 request);
545 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
546 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
547 iccArgument.data, onCompleted);
548 }
549 break;
550
551 case EVENT_EXCHANGE_SIM_IO_DONE:
552 ar = (AsyncResult) msg.obj;
553 request = (MainThreadRequest) ar.userObj;
554 if (ar.exception == null && ar.result != null) {
555 request.result = ar.result;
556 } else {
557 request.result = new IccIoResult(0x6f, 0, (byte[])null);
558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 break;
561
Derek Tan4d5e5c12014-02-04 11:54:58 -0800562 case CMD_SEND_ENVELOPE:
563 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800564 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 if (uiccCard == null) {
566 loge("sendEnvelopeWithStatus: No UICC");
567 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 } else {
570 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
571 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
572 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800573 break;
574
575 case EVENT_SEND_ENVELOPE_DONE:
576 ar = (AsyncResult) msg.obj;
577 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700578 if (ar.exception == null && ar.result != null) {
579 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800580 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700581 request.result = new IccIoResult(0x6F, 0, (byte[])null);
582 if (ar.result == null) {
583 loge("sendEnvelopeWithStatus: Empty response");
584 } else if (ar.exception instanceof CommandException) {
585 loge("sendEnvelopeWithStatus: CommandException: " +
586 ar.exception);
587 } else {
588 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
589 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800592 break;
593
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 case CMD_OPEN_CHANNEL:
595 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800596 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800597 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 if (uiccCard == null) {
599 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800600 request.result = new IccOpenLogicalChannelResponse(-1,
601 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700603 } else {
604 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800605 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
606 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700607 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 break;
609
610 case EVENT_OPEN_CHANNEL_DONE:
611 ar = (AsyncResult) msg.obj;
612 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 int[] result = (int[]) ar.result;
616 int channelId = result[0];
617 byte[] selectResponse = null;
618 if (result.length > 1) {
619 selectResponse = new byte[result.length - 1];
620 for (int i = 1; i < result.length; ++i) {
621 selectResponse[i - 1] = (byte) result[i];
622 }
623 }
624 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 if (ar.result == null) {
628 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 if (ar.exception != null) {
631 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
632 }
633
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700634 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700635 if (ar.exception instanceof CommandException) {
636 CommandException.Error error =
637 ((CommandException) (ar.exception)).getCommandError();
638 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700639 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700640 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700641 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 }
643 }
644 openChannelResp = new IccOpenLogicalChannelResponse(
645 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700647 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700648 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 break;
650
651 case CMD_CLOSE_CHANNEL:
652 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800653 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700654 if (uiccCard == null) {
655 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900656 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700658 } else {
659 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
660 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
661 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 break;
663
664 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800665 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
666 break;
667
668 case CMD_NV_READ_ITEM:
669 request = (MainThreadRequest) msg.obj;
670 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800671 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
672 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800673 break;
674
675 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 ar = (AsyncResult) msg.obj;
677 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800678 if (ar.exception == null && ar.result != null) {
679 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800681 request.result = "";
682 if (ar.result == null) {
683 loge("nvReadItem: Empty response");
684 } else if (ar.exception instanceof CommandException) {
685 loge("nvReadItem: CommandException: " +
686 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800688 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 }
690 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 break;
693
Jake Hambye994d462014-02-03 13:10:13 -0800694 case CMD_NV_WRITE_ITEM:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
697 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800698 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700699 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800700 break;
701
702 case EVENT_NV_WRITE_ITEM_DONE:
703 handleNullReturnEvent(msg, "nvWriteItem");
704 break;
705
706 case CMD_NV_WRITE_CDMA_PRL:
707 request = (MainThreadRequest) msg.obj;
708 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800709 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800710 break;
711
712 case EVENT_NV_WRITE_CDMA_PRL_DONE:
713 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
714 break;
715
chen xu6dac5ab2018-10-26 17:39:23 -0700716 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800717 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700718 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800719 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800720 break;
721
chen xu6dac5ab2018-10-26 17:39:23 -0700722 case EVENT_RESET_MODEM_CONFIG_DONE:
723 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800724 break;
725
Jake Hamby7c27be32014-03-03 13:25:59 -0800726 case CMD_GET_PREFERRED_NETWORK_TYPE:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700729 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800730 break;
731
732 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
733 ar = (AsyncResult) msg.obj;
734 request = (MainThreadRequest) ar.userObj;
735 if (ar.exception == null && ar.result != null) {
736 request.result = ar.result; // Integer
737 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800738 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800739 if (ar.result == null) {
740 loge("getPreferredNetworkType: Empty response");
741 } else if (ar.exception instanceof CommandException) {
742 loge("getPreferredNetworkType: CommandException: " +
743 ar.exception);
744 } else {
745 loge("getPreferredNetworkType: Unknown exception");
746 }
747 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700748 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800749 break;
750
751 case CMD_SET_PREFERRED_NETWORK_TYPE:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
754 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700755 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 break;
757
758 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
759 handleNullReturnEvent(msg, "setPreferredNetworkType");
760 break;
761
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000762 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
763 request = (MainThreadRequest)msg.obj;
764 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800765 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000766 break;
767
768 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
769 ar = (AsyncResult)msg.obj;
770 request = (MainThreadRequest)ar.userObj;
771 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700772 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000773 break;
774
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800775 case CMD_SET_VOICEMAIL_NUMBER:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
778 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800779 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
780 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800781 break;
782
783 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
784 handleNullReturnEvent(msg, "setVoicemailNumber");
785 break;
786
Stuart Scott54788802015-03-30 13:18:01 -0700787 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
790 request);
791 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
792 break;
793
794 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
795 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
796 break;
797
Shishir Agrawal302c8692015-06-19 13:49:39 -0700798 case CMD_PERFORM_NETWORK_SCAN:
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
801 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
802 break;
803
804 case EVENT_PERFORM_NETWORK_SCAN_DONE:
805 ar = (AsyncResult) msg.obj;
806 request = (MainThreadRequest) ar.userObj;
807 CellNetworkScanResult cellScanResult;
808 if (ar.exception == null && ar.result != null) {
809 cellScanResult = new CellNetworkScanResult(
810 CellNetworkScanResult.STATUS_SUCCESS,
811 (List<OperatorInfo>) ar.result);
812 } else {
813 if (ar.result == null) {
814 loge("getCellNetworkScanResults: Empty response");
815 }
816 if (ar.exception != null) {
817 loge("getCellNetworkScanResults: Exception: " + ar.exception);
818 }
819 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
820 if (ar.exception instanceof CommandException) {
821 CommandException.Error error =
822 ((CommandException) (ar.exception)).getCommandError();
823 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
824 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
825 } else if (error == CommandException.Error.GENERIC_FAILURE) {
826 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
827 }
828 }
829 cellScanResult = new CellNetworkScanResult(errorCode, null);
830 }
831 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700832 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700833 break;
834
835 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
836 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700837 ManualNetworkSelectionArgument selArg =
838 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700839 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
840 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700841 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
842 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700843 break;
844
845 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700846 ar = (AsyncResult) msg.obj;
847 request = (MainThreadRequest) ar.userObj;
848 if (ar.exception == null) {
849 request.result = true;
850 } else {
851 request.result = false;
852 loge("setNetworkSelectionModeManual " + ar.exception);
853 }
854 notifyRequester(request);
855 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700856 break;
857
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700858 case CMD_GET_MODEM_ACTIVITY_INFO:
859 request = (MainThreadRequest) msg.obj;
860 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700861 if (defaultPhone != null) {
862 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
863 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700864 break;
865
866 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
867 ar = (AsyncResult) msg.obj;
868 request = (MainThreadRequest) ar.userObj;
869 if (ar.exception == null && ar.result != null) {
870 request.result = ar.result;
871 } else {
872 if (ar.result == null) {
873 loge("queryModemActivityInfo: Empty response");
874 } else if (ar.exception instanceof CommandException) {
875 loge("queryModemActivityInfo: CommandException: " +
876 ar.exception);
877 } else {
878 loge("queryModemActivityInfo: Unknown exception");
879 }
880 }
Amit Mahajand4766222016-01-28 15:28:28 -0800881 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
882 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800883 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800884 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700885 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700886 break;
887
Meng Wang1a7c35a2016-05-05 20:56:15 -0700888 case CMD_SET_ALLOWED_CARRIERS:
889 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800890 CarrierRestrictionRules argument =
891 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700892 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800893 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700894 break;
895
896 case EVENT_SET_ALLOWED_CARRIERS_DONE:
897 ar = (AsyncResult) msg.obj;
898 request = (MainThreadRequest) ar.userObj;
899 if (ar.exception == null && ar.result != null) {
900 request.result = ar.result;
901 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800902 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
903 if (ar.exception instanceof CommandException) {
904 loge("setAllowedCarriers: CommandException: " + ar.exception);
905 CommandException.Error error =
906 ((CommandException) (ar.exception)).getCommandError();
907 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
908 request.result =
909 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
910 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700911 } else {
912 loge("setAllowedCarriers: Unknown exception");
913 }
914 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700915 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700916 break;
917
918 case CMD_GET_ALLOWED_CARRIERS:
919 request = (MainThreadRequest) msg.obj;
920 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800921 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700922 break;
923
924 case EVENT_GET_ALLOWED_CARRIERS_DONE:
925 ar = (AsyncResult) msg.obj;
926 request = (MainThreadRequest) ar.userObj;
927 if (ar.exception == null && ar.result != null) {
928 request.result = ar.result;
929 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800930 request.result = new IllegalStateException(
931 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700932 if (ar.result == null) {
933 loge("getAllowedCarriers: Empty response");
934 } else if (ar.exception instanceof CommandException) {
935 loge("getAllowedCarriers: CommandException: " +
936 ar.exception);
937 } else {
938 loge("getAllowedCarriers: Unknown exception");
939 }
940 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700941 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700942 break;
943
Nathan Haroldb3014052017-01-25 15:57:32 -0800944 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
945 ar = (AsyncResult) msg.obj;
946 request = (MainThreadRequest) ar.userObj;
947 if (ar.exception == null && ar.result != null) {
948 request.result = ar.result;
949 } else {
950 request.result = new IllegalArgumentException(
951 "Failed to retrieve Forbidden Plmns");
952 if (ar.result == null) {
953 loge("getForbiddenPlmns: Empty response");
954 } else {
955 loge("getForbiddenPlmns: Unknown exception");
956 }
957 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700958 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800959 break;
960
961 case CMD_GET_FORBIDDEN_PLMNS:
962 request = (MainThreadRequest) msg.obj;
963 uiccCard = getUiccCardFromRequest(request);
964 if (uiccCard == null) {
965 loge("getForbiddenPlmns() UiccCard is null");
966 request.result = new IllegalArgumentException(
967 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700968 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800969 break;
970 }
971 Integer appType = (Integer) request.argument;
972 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
973 if (uiccApp == null) {
974 loge("getForbiddenPlmns() no app with specified type -- "
975 + appType);
976 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700977 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800978 break;
979 } else {
980 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
981 + " specified type -- " + appType);
982 }
983 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
984 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
985 onCompleted);
986 break;
987
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000988 case CMD_SWITCH_SLOTS:
989 request = (MainThreadRequest) msg.obj;
990 int[] physicalSlots = (int[]) request.argument;
991 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
992 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
993 break;
994
995 case EVENT_SWITCH_SLOTS_DONE:
996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
998 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700999 notifyRequester(request);
1000 break;
1001 case CMD_GET_NETWORK_SELECTION_MODE:
1002 request = (MainThreadRequest) msg.obj;
1003 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1004 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1005 break;
1006
1007 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1008 ar = (AsyncResult) msg.obj;
1009 request = (MainThreadRequest) ar.userObj;
1010 if (ar.exception != null) {
1011 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1012 } else {
1013 int mode = ((int[]) ar.result)[0];
1014 if (mode == 0) {
1015 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1016 } else {
1017 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1018 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001019 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001020 notifyRequester(request);
1021 break;
1022 case CMD_GET_CDMA_ROAMING_MODE:
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1025 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1026 break;
1027 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1028 ar = (AsyncResult) msg.obj;
1029 request = (MainThreadRequest) ar.userObj;
1030 if (ar.exception != null) {
1031 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1032 } else {
1033 request.result = ((int[]) ar.result)[0];
1034 }
1035 notifyRequester(request);
1036 break;
1037 case CMD_SET_CDMA_ROAMING_MODE:
1038 request = (MainThreadRequest) msg.obj;
1039 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1040 int mode = (int) request.argument;
1041 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1042 break;
1043 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
1046 request.result = ar.exception == null;
1047 notifyRequester(request);
1048 break;
1049 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1050 request = (MainThreadRequest) msg.obj;
1051 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1052 int subscriptionMode = (int) request.argument;
1053 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1054 break;
1055 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1056 ar = (AsyncResult) msg.obj;
1057 request = (MainThreadRequest) ar.userObj;
1058 request.result = ar.exception == null;
1059 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001060 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 case CMD_GET_ALL_CELL_INFO:
1062 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001064 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001065 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 case EVENT_GET_ALL_CELL_INFO_DONE:
1067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001069 // If a timeout occurs, the response will be null
1070 request.result = (ar.exception == null && ar.result != null)
1071 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001072 synchronized (request) {
1073 request.notifyAll();
1074 }
1075 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 case CMD_REQUEST_CELL_INFO_UPDATE:
1077 request = (MainThreadRequest) msg.obj;
1078 request.phone.requestCellInfoUpdate(request.workSource,
1079 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1080 break;
1081 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1082 ar = (AsyncResult) msg.obj;
1083 request = (MainThreadRequest) ar.userObj;
1084 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1085 try {
1086 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001087 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001088 cb.onError(
1089 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1090 ar.exception.getClass().getName(),
1091 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001094 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001095 } else {
1096 // use the result as returned
1097 cb.onCellInfo((List<CellInfo>) ar.result);
1098 }
1099 } catch (RemoteException re) {
1100 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1101 }
1102 break;
1103 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001104 request = (MainThreadRequest) msg.obj;
1105 WorkSource ws = (WorkSource) request.argument;
1106 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001107 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001108 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001109 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001110 ar = (AsyncResult) msg.obj;
1111 request = (MainThreadRequest) ar.userObj;
1112 if (ar.exception == null) {
1113 request.result = ar.result;
1114 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001115 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001116 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001117 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001118 }
1119
1120 synchronized (request) {
1121 request.notifyAll();
1122 }
1123 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001124 case CMD_MODEM_REBOOT:
1125 request = (MainThreadRequest) msg.obj;
1126 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001127 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001128 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001129 case EVENT_CMD_MODEM_REBOOT_DONE:
1130 handleNullReturnEvent(msg, "rebootModem");
1131 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001132 case CMD_REQUEST_ENABLE_MODEM:
1133 request = (MainThreadRequest) msg.obj;
1134 boolean enable = (boolean) request.argument;
1135 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001136 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001137 PhoneConfigurationManager.getInstance()
1138 .enablePhone(request.phone, enable, onCompleted);
1139 break;
1140 case EVENT_ENABLE_MODEM_DONE:
1141 ar = (AsyncResult) msg.obj;
1142 request = (MainThreadRequest) ar.userObj;
1143 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001144 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001145 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001146 if ((boolean) request.result) {
1147 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1148 updateModemStateMetrics();
1149 } else {
1150 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1151 + ar.exception);
1152 }
1153 notifyRequester(request);
1154 break;
1155 case CMD_GET_MODEM_STATUS:
1156 request = (MainThreadRequest) msg.obj;
1157 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1158 PhoneConfigurationManager.getInstance()
1159 .getPhoneStatusFromModem(request.phone, onCompleted);
1160 break;
1161 case EVENT_GET_MODEM_STATUS_DONE:
1162 ar = (AsyncResult) msg.obj;
1163 request = (MainThreadRequest) ar.userObj;
1164 int id = request.phone.getPhoneId();
1165 if (ar.exception == null && ar.result != null) {
1166 request.result = ar.result;
1167 //update the cache as modem status has changed
1168 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1169 (boolean) request.result);
1170 } else {
1171 // Return true if modem status cannot be retrieved. For most cases,
1172 // modem status is on. And for older version modems, GET_MODEM_STATUS
1173 // and disable modem are not supported. Modem is always on.
1174 // TODO: this should be fixed in R to support a third
1175 // status UNKNOWN b/131631629
1176 request.result = true;
1177 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1178 + ar.exception);
1179 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001180 notifyRequester(request);
1181 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001182 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1183 ar = (AsyncResult) msg.obj;
1184 request = (MainThreadRequest) ar.userObj;
1185 if (ar.exception == null && ar.result != null) {
1186 request.result = ar.result;
1187 } else {
1188 request.result = -1;
1189 loge("Failed to set Forbidden Plmns");
1190 if (ar.result == null) {
1191 loge("setForbidenPlmns: Empty response");
1192 } else if (ar.exception != null) {
1193 loge("setForbiddenPlmns: Exception: " + ar.exception);
1194 request.result = -1;
1195 } else {
1196 loge("setForbiddenPlmns: Unknown exception");
1197 }
1198 }
1199 notifyRequester(request);
1200 break;
1201 case CMD_SET_FORBIDDEN_PLMNS:
1202 request = (MainThreadRequest) msg.obj;
1203 uiccCard = getUiccCardFromRequest(request);
1204 if (uiccCard == null) {
1205 loge("setForbiddenPlmns: UiccCard is null");
1206 request.result = -1;
1207 notifyRequester(request);
1208 break;
1209 }
1210 Pair<Integer, List<String>> setFplmnsArgs =
1211 (Pair<Integer, List<String>>) request.argument;
1212 appType = setFplmnsArgs.first;
1213 List<String> fplmns = setFplmnsArgs.second;
1214 uiccApp = uiccCard.getApplicationByType(appType);
1215 if (uiccApp == null) {
1216 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1217 request.result = -1;
1218 loge("Failed to get UICC App");
1219 notifyRequester(request);
1220 } else {
1221 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1222 ((SIMRecords) uiccApp.getIccRecords())
1223 .setForbiddenPlmns(onCompleted, fplmns);
1224 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001225 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001226 case CMD_ERASE_MODEM_CONFIG:
1227 request = (MainThreadRequest) msg.obj;
1228 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1229 defaultPhone.eraseModemConfig(onCompleted);
1230 break;
1231 case EVENT_ERASE_MODEM_CONFIG_DONE:
1232 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001233 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 default:
1235 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1236 break;
1237 }
1238 }
Jake Hambye994d462014-02-03 13:10:13 -08001239
Pengquan Menga1bb6272018-09-06 09:59:22 -07001240 private void notifyRequester(MainThreadRequest request) {
1241 synchronized (request) {
1242 request.notifyAll();
1243 }
1244 }
1245
Jake Hambye994d462014-02-03 13:10:13 -08001246 private void handleNullReturnEvent(Message msg, String command) {
1247 AsyncResult ar = (AsyncResult) msg.obj;
1248 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1249 if (ar.exception == null) {
1250 request.result = true;
1251 } else {
1252 request.result = false;
1253 if (ar.exception instanceof CommandException) {
1254 loge(command + ": CommandException: " + ar.exception);
1255 } else {
1256 loge(command + ": Unknown exception");
1257 }
1258 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001259 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 }
1262
1263 /**
1264 * Posts the specified command to be executed on the main thread,
1265 * waits for the request to complete, and returns the result.
1266 * @see #sendRequestAsync
1267 */
1268 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001269 return sendRequest(
1270 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001271 }
1272
1273 /**
1274 * Posts the specified command to be executed on the main thread,
1275 * waits for the request to complete, and returns the result.
1276 * @see #sendRequestAsync
1277 */
1278 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1279 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001280 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001281 }
1282
1283 /**
1284 * Posts the specified command to be executed on the main thread,
1285 * waits for the request to complete, and returns the result.
1286 * @see #sendRequestAsync
1287 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001288 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001289 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001290 }
1291
1292 /**
1293 * Posts the specified command to be executed on the main thread,
1294 * waits for the request to complete, and returns the result.
1295 * @see #sendRequestAsync
1296 */
Nathan Harold92bed182018-10-12 18:16:49 -07001297 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1298 return sendRequest(command, argument, subId, null, workSource);
1299 }
1300
1301 /**
1302 * Posts the specified command to be executed on the main thread,
1303 * waits for the request to complete, and returns the result.
1304 * @see #sendRequestAsync
1305 */
1306 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1307 return sendRequest(
1308 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1309 }
1310
1311 /**
1312 * Posts the specified command to be executed on the main thread,
1313 * waits for the request to complete, and returns the result.
1314 * @see #sendRequestAsync
1315 */
1316 private Object sendRequest(
1317 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1319 throw new RuntimeException("This method will deadlock if called from the main thread.");
1320 }
1321
Nathan Harold92bed182018-10-12 18:16:49 -07001322 MainThreadRequest request = null;
1323 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1324 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1325 } else if (phone != null) {
1326 request = new MainThreadRequest(argument, phone, workSource);
1327 } else {
1328 request = new MainThreadRequest(argument, subId, workSource);
1329 }
1330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 Message msg = mMainThreadHandler.obtainMessage(command, request);
1332 msg.sendToTarget();
1333
1334 // Wait for the request to complete
1335 synchronized (request) {
1336 while (request.result == null) {
1337 try {
1338 request.wait();
1339 } catch (InterruptedException e) {
1340 // Do nothing, go back and wait until the request is complete
1341 }
1342 }
1343 }
1344 return request.result;
1345 }
1346
1347 /**
1348 * Asynchronous ("fire and forget") version of sendRequest():
1349 * Posts the specified command to be executed on the main thread, and
1350 * returns immediately.
1351 * @see #sendRequest
1352 */
1353 private void sendRequestAsync(int command) {
1354 mMainThreadHandler.sendEmptyMessage(command);
1355 }
1356
1357 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001358 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001360 */
1361 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001362 sendRequestAsync(command, argument, null, null);
1363 }
1364
1365 /**
1366 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1367 * @see {@link #sendRequest(int,Object)}
1368 */
1369 private void sendRequestAsync(
1370 int command, Object argument, Phone phone, WorkSource workSource) {
1371 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001372 Message msg = mMainThreadHandler.obtainMessage(command, request);
1373 msg.sendToTarget();
1374 }
1375
1376 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 * Initialize the singleton PhoneInterfaceManager instance.
1378 * This is only done once, at startup, from PhoneApp.onCreate().
1379 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001380 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 synchronized (PhoneInterfaceManager.class) {
1382 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001383 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 } else {
1385 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1386 }
1387 return sInstance;
1388 }
1389 }
1390
1391 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001392 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001395 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001396 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001397 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1398 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001399 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001400 mTelephonySharedPreferences =
1401 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001402 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001403 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001404
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001405 publish();
1406 }
1407
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001408 private Phone getDefaultPhone() {
1409 Phone thePhone = getPhone(getDefaultSubscription());
1410 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1411 }
1412
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413 private void publish() {
1414 if (DBG) log("publish: " + this);
1415
Peter Wangc035ce42020-01-08 21:00:22 -08001416 TelephonyFrameworkInitializer
1417 .getTelephonyServiceManager()
1418 .getTelephonyServiceRegisterer()
1419 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420 }
1421
Stuart Scott584921c2015-01-15 17:10:34 -08001422 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001423 if (request.phone != null) {
1424 return request.phone;
1425 } else {
1426 return getPhoneFromSubId(request.subId);
1427 }
1428 }
1429
1430 private Phone getPhoneFromSubId(int subId) {
1431 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1432 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001433 }
1434
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001435 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1436 Phone phone = getPhoneFromRequest(request);
1437 return phone == null ? null :
1438 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1439 }
1440
Wink Saville36469e72014-06-11 15:17:00 -07001441 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001442 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001443 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001445
Naina Nallurid63128d2019-09-17 14:10:30 -07001446 private void sendEraseModemConfig(Phone phone) {
1447 if (phone != null) {
1448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1449 mApp, phone.getSubId(), "eraseModemConfig");
1450 final long identity = Binder.clearCallingIdentity();
1451 try {
1452 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1453 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1454 } finally {
1455 Binder.restoreCallingIdentity(identity);
1456 }
1457 }
1458 }
1459
Peter Wang44b186e2020-01-13 23:33:09 -08001460 private boolean isImsAvailableOnDevice() {
1461 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1462 if (pm == null) {
1463 // For some reason package manger is not available.. This will fail internally anyway,
1464 // so do not throw error and allow.
1465 return true;
1466 }
1467 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1468 }
1469
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001470 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001471 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001472 }
1473
Wink Savilleb564aae2014-10-23 10:18:09 -07001474 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475 if (DBG) log("dial: " + number);
1476 // No permission check needed here: This is just a wrapper around the
1477 // ACTION_DIAL intent, which is available to any app since it puts up
1478 // the UI before it does anything.
1479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001480 final long identity = Binder.clearCallingIdentity();
1481 try {
1482 String url = createTelUrl(number);
1483 if (url == null) {
1484 return;
1485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001487 // PENDING: should we just silently fail if phone is offhook or ringing?
1488 PhoneConstants.State state = mCM.getState(subId);
1489 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1490 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1491 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1492 mApp.startActivity(intent);
1493 }
1494 } finally {
1495 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 }
1497 }
1498
1499 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001500 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001501 }
1502
Wink Savilleb564aae2014-10-23 10:18:09 -07001503 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504 if (DBG) log("call: " + number);
1505
1506 // This is just a wrapper around the ACTION_CALL intent, but we still
1507 // need to do a permission check since we're calling startActivity()
1508 // from the context of the phone app.
1509 enforceCallPermission();
1510
Jordan Liu1617b712019-07-10 15:06:26 -07001511 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001512 != AppOpsManager.MODE_ALLOWED) {
1513 return;
1514 }
1515
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001516 final long identity = Binder.clearCallingIdentity();
1517 try {
1518 String url = createTelUrl(number);
1519 if (url == null) {
1520 return;
1521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001523 boolean isValid = false;
1524 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1525 if (slist != null) {
1526 for (SubscriptionInfo subInfoRecord : slist) {
1527 if (subInfoRecord.getSubscriptionId() == subId) {
1528 isValid = true;
1529 break;
1530 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001531 }
Wink Saville08874612014-08-31 19:19:58 -07001532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001533 if (!isValid) {
1534 return;
1535 }
Wink Saville08874612014-08-31 19:19:58 -07001536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001537 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1538 intent.putExtra(SUBSCRIPTION_KEY, subId);
1539 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1540 mApp.startActivity(intent);
1541 } finally {
1542 Binder.restoreCallingIdentity(identity);
1543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 }
1545
Wink Savilleb564aae2014-10-23 10:18:09 -07001546 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001547 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001548 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1549 }
1550
Wink Savilleb564aae2014-10-23 10:18:09 -07001551 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001552 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001553 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1554 }
1555
Wink Savilleb564aae2014-10-23 10:18:09 -07001556 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001558
1559 final long identity = Binder.clearCallingIdentity();
1560 try {
1561 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1562 checkSimPin.start();
1563 return checkSimPin.unlockSim(null, pin);
1564 } finally {
1565 Binder.restoreCallingIdentity(identity);
1566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 }
1568
Wink Savilleb564aae2014-10-23 10:18:09 -07001569 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001571
1572 final long identity = Binder.clearCallingIdentity();
1573 try {
1574 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1575 checkSimPuk.start();
1576 return checkSimPuk.unlockSim(puk, pin);
1577 } finally {
1578 Binder.restoreCallingIdentity(identity);
1579 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 }
1581
1582 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001583 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001584 * a synchronous one.
1585 */
1586 private static class UnlockSim extends Thread {
1587
1588 private final IccCard mSimCard;
1589
1590 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001591 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1592 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593
1594 // For replies from SimCard interface
1595 private Handler mHandler;
1596
1597 // For async handler to identify request type
1598 private static final int SUPPLY_PIN_COMPLETE = 100;
1599
1600 public UnlockSim(IccCard simCard) {
1601 mSimCard = simCard;
1602 }
1603
1604 @Override
1605 public void run() {
1606 Looper.prepare();
1607 synchronized (UnlockSim.this) {
1608 mHandler = new Handler() {
1609 @Override
1610 public void handleMessage(Message msg) {
1611 AsyncResult ar = (AsyncResult) msg.obj;
1612 switch (msg.what) {
1613 case SUPPLY_PIN_COMPLETE:
1614 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1615 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001616 mRetryCount = msg.arg1;
1617 if (ar.exception != null) {
1618 if (ar.exception instanceof CommandException &&
1619 ((CommandException)(ar.exception)).getCommandError()
1620 == CommandException.Error.PASSWORD_INCORRECT) {
1621 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1622 } else {
1623 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1624 }
1625 } else {
1626 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001628 mDone = true;
1629 UnlockSim.this.notifyAll();
1630 }
1631 break;
1632 }
1633 }
1634 };
1635 UnlockSim.this.notifyAll();
1636 }
1637 Looper.loop();
1638 }
1639
1640 /*
1641 * Use PIN or PUK to unlock SIM card
1642 *
1643 * If PUK is null, unlock SIM card with PIN
1644 *
1645 * If PUK is not null, unlock SIM card with PUK and set PIN code
1646 */
Wink Saville9de0f752013-10-22 19:04:03 -07001647 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648
1649 while (mHandler == null) {
1650 try {
1651 wait();
1652 } catch (InterruptedException e) {
1653 Thread.currentThread().interrupt();
1654 }
1655 }
1656 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1657
1658 if (puk == null) {
1659 mSimCard.supplyPin(pin, callback);
1660 } else {
1661 mSimCard.supplyPuk(puk, pin, callback);
1662 }
1663
1664 while (!mDone) {
1665 try {
1666 Log.d(LOG_TAG, "wait for done");
1667 wait();
1668 } catch (InterruptedException e) {
1669 // Restore the interrupted status
1670 Thread.currentThread().interrupt();
1671 }
1672 }
1673 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001674 int[] resultArray = new int[2];
1675 resultArray[0] = mResult;
1676 resultArray[1] = mRetryCount;
1677 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 }
1679 }
1680
1681 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001682 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001683
1684 }
1685
Wink Savilleb564aae2014-10-23 10:18:09 -07001686 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 // No permission check needed here: this call is harmless, and it's
1688 // needed for the ServiceState.requestStateUpdate() call (which is
1689 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001690 final long identity = Binder.clearCallingIdentity();
1691 try {
1692 final Phone phone = getPhone(subId);
1693 if (phone != null) {
1694 phone.updateServiceLocation();
1695 }
1696 } finally {
1697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 }
1700
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001701 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001702 @Override
1703 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001704 return isRadioOnWithFeature(callingPackage, null);
1705 }
1706
1707
1708 @Override
1709 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1710 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1711 callingFeatureId);
1712 }
1713
1714 @Deprecated
1715 @Override
1716 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1717 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001718 }
1719
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001720 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001721 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1722 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001724 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001725 return false;
1726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001727
1728 final long identity = Binder.clearCallingIdentity();
1729 try {
1730 return isRadioOnForSubscriber(subId);
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
1733 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001734 }
1735
1736 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001737 final long identity = Binder.clearCallingIdentity();
1738 try {
1739 final Phone phone = getPhone(subId);
1740 if (phone != null) {
1741 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1742 } else {
1743 return false;
1744 }
1745 } finally {
1746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 }
1749
1750 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001751 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 }
Wink Saville36469e72014-06-11 15:17:00 -07001753
Wink Savilleb564aae2014-10-23 10:18:09 -07001754 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001756
1757 final long identity = Binder.clearCallingIdentity();
1758 try {
1759 final Phone phone = getPhone(subId);
1760 if (phone != null) {
1761 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1762 }
1763 } finally {
1764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001765 }
Wink Saville36469e72014-06-11 15:17:00 -07001766 }
1767
1768 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001769 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001770 }
1771
Wink Savilleb564aae2014-10-23 10:18:09 -07001772 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001773 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001774
1775 final long identity = Binder.clearCallingIdentity();
1776 try {
1777 final Phone phone = getPhone(subId);
1778 if (phone == null) {
1779 return false;
1780 }
1781 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1782 toggleRadioOnOffForSubscriber(subId);
1783 }
1784 return true;
1785 } finally {
1786 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
Wink Saville36469e72014-06-11 15:17:00 -07001789
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001790 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001791 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001792 /*
1793 * If any of the Radios are available, it will need to be
1794 * shutdown. So return true if any Radio is available.
1795 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001796 final long identity = Binder.clearCallingIdentity();
1797 try {
1798 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1799 Phone phone = PhoneFactory.getPhone(i);
1800 if (phone != null && phone.isRadioAvailable()) return true;
1801 }
1802 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1803 return false;
1804 } finally {
1805 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001806 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001807 }
1808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001809 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001810 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001811 enforceModifyPermission();
1812
1813 final long identity = Binder.clearCallingIdentity();
1814 try {
1815 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1816 logv("Shutting down Phone " + i);
1817 shutdownRadioUsingPhoneId(i);
1818 }
1819 } finally {
1820 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001821 }
1822 }
1823
1824 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001825 Phone phone = PhoneFactory.getPhone(phoneId);
1826 if (phone != null && phone.isRadioAvailable()) {
1827 phone.shutdownRadio();
1828 }
1829 }
1830
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001832 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001833
1834 final long identity = Binder.clearCallingIdentity();
1835 try {
1836 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1837 if (defaultPhone != null) {
1838 defaultPhone.setRadioPower(turnOn);
1839 return true;
1840 } else {
1841 loge("There's no default phone.");
1842 return false;
1843 }
1844 } finally {
1845 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001846 }
Wink Saville36469e72014-06-11 15:17:00 -07001847 }
1848
Wink Savilleb564aae2014-10-23 10:18:09 -07001849 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001851
1852 final long identity = Binder.clearCallingIdentity();
1853 try {
1854 final Phone phone = getPhone(subId);
1855 if (phone != null) {
1856 phone.setRadioPower(turnOn);
1857 return true;
1858 } else {
1859 return false;
1860 }
1861 } finally {
1862 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001863 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001864 }
1865
Wink Saville36469e72014-06-11 15:17:00 -07001866 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001867 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 public boolean enableDataConnectivity() {
1869 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001870
1871 final long identity = Binder.clearCallingIdentity();
1872 try {
1873 int subId = mSubscriptionController.getDefaultDataSubId();
1874 final Phone phone = getPhone(subId);
1875 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001876 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001877 return true;
1878 } else {
1879 return false;
1880 }
1881 } finally {
1882 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 }
1885
Wink Saville36469e72014-06-11 15:17:00 -07001886 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001887 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 public boolean disableDataConnectivity() {
1889 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001890
1891 final long identity = Binder.clearCallingIdentity();
1892 try {
1893 int subId = mSubscriptionController.getDefaultDataSubId();
1894 final Phone phone = getPhone(subId);
1895 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001896 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001897 return true;
1898 } else {
1899 return false;
1900 }
1901 } finally {
1902 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001903 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 }
1905
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001907 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001908 final long identity = Binder.clearCallingIdentity();
1909 try {
1910 final Phone phone = getPhone(subId);
1911 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001912 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001913 } else {
1914 return false;
1915 }
1916 } finally {
1917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 }
1920
1921 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001922 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001923 }
1924
pkanwarae03a6b2016-11-06 20:37:09 -08001925 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001926 enforceCallPermission();
1927
1928 final long identity = Binder.clearCallingIdentity();
1929 try {
1930 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1931 return;
1932 }
1933 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1934 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1935 } finally {
1936 Binder.restoreCallingIdentity(identity);
1937 }
pkanwar32d516d2016-10-14 19:37:38 -07001938 };
1939
Wink Savilleb564aae2014-10-23 10:18:09 -07001940 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001942
1943 final long identity = Binder.clearCallingIdentity();
1944 try {
1945 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1946 return false;
1947 }
1948 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1949 } finally {
1950 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 }
1953
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001955 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001956 }
1957
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001958 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001959 final long identity = Binder.clearCallingIdentity();
1960 try {
1961 Phone phone = PhoneFactory.getPhone(slotIndex);
1962 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1963 PhoneConstantConversions.convertCallState(phone.getState());
1964 } finally {
1965 Binder.restoreCallingIdentity(identity);
1966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 }
1968
Sanket Padawe356d7632015-06-22 14:03:32 -07001969 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001970 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001971 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1972 }
1973
1974 @Override
1975 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001976 final long identity = Binder.clearCallingIdentity();
1977 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001978 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001979 if (phone != null) {
1980 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1981 } else {
1982 return PhoneConstantConversions.convertDataState(
1983 PhoneConstants.DataState.DISCONNECTED);
1984 }
1985 } finally {
1986 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001987 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988 }
1989
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001991 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001992 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1993 }
1994
1995 @Override
1996 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001997 final long identity = Binder.clearCallingIdentity();
1998 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001999 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000 if (phone != null) {
2001 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2002 } else {
2003 return TelephonyManager.DATA_ACTIVITY_NONE;
2004 }
2005 } finally {
2006 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002007 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002008 }
2009
2010 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002011 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002012 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002013 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002014
2015 LocationAccessPolicy.LocationPermissionResult locationResult =
2016 LocationAccessPolicy.checkLocationPermission(mApp,
2017 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2018 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002019 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002020 .setCallingPid(Binder.getCallingPid())
2021 .setCallingUid(Binder.getCallingUid())
2022 .setMethod("getCellLocation")
2023 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2024 .build());
2025 switch (locationResult) {
2026 case DENIED_HARD:
2027 throw new SecurityException("Not allowed to access cell location");
2028 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002029 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2030 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 }
2032
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002033 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002034 final long identity = Binder.clearCallingIdentity();
2035 try {
2036 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002037 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002038 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002039 } finally {
2040 Binder.restoreCallingIdentity(identity);
2041 }
Svetoslav64fad262015-04-14 14:35:21 -07002042 }
2043
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002045 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2046 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002047 if (!TextUtils.isEmpty(callingPackage)) {
2048 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2050 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002051 return "";
2052 }
2053 }
2054
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002055 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2056 // registered cell info, so return a NULL country instead.
2057 final long identity = Binder.clearCallingIdentity();
2058 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002059 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2060 // Get default phone in this case.
2061 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2062 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002063 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002064 // Todo: fix this when we can get the actual cellular network info when the device
2065 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002066 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002067 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2068 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002069 return "";
2070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002071 Phone phone = PhoneFactory.getPhone(phoneId);
2072 if (phone != null) {
2073 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002074 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002075 if (sst != null) {
2076 LocaleTracker lt = sst.getLocaleTracker();
2077 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002078 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2079 return lt.getCurrentCountry();
2080 } else if (emergencyNumberTracker != null) {
2081 return emergencyNumberTracker.getEmergencyCountryIso();
2082 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002083 }
2084 }
2085 }
2086 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002087 } finally {
2088 Binder.restoreCallingIdentity(identity);
2089 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002090 }
2091
2092 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002094 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002095 }
2096
Sanket Padawe356d7632015-06-22 14:03:32 -07002097 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002098 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 mApp.enforceCallingOrSelfPermission(
2100 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002101
2102 final long identity = Binder.clearCallingIdentity();
2103 try {
2104 final Phone phone = getPhone(subId);
2105 if (phone != null) {
2106 phone.enableLocationUpdates();
2107 }
2108 } finally {
2109 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002110 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 }
2112
2113 @Override
2114 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002115 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002116 }
2117
Sanket Padawe356d7632015-06-22 14:03:32 -07002118 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002119 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 mApp.enforceCallingOrSelfPermission(
2121 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002122
2123 final long identity = Binder.clearCallingIdentity();
2124 try {
2125 final Phone phone = getPhone(subId);
2126 if (phone != null) {
2127 phone.disableLocationUpdates();
2128 }
2129 } finally {
2130 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 }
2133
Nathan Harold31d7ff32018-10-15 20:20:30 -07002134 /**
2135 * Returns the target SDK version number for a given package name.
2136 *
Nathan Haroldec184742019-07-10 17:04:16 -07002137 * This call MUST be invoked before clearing the calling UID.
2138 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002139 * @return target SDK if the package is found or INT_MAX.
2140 */
2141 private int getTargetSdk(String packageName) {
2142 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002143 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002144 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002145 if (ai != null) return ai.targetSdkVersion;
2146 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002147 loge("Failed to get package info for pkg="
2148 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002149 }
2150 return Integer.MAX_VALUE;
2151 }
2152
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 @Override
2154 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002155 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2156 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002157 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002158 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2159 throw new SecurityException(
2160 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2161 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002162
Jordan Liu1617b712019-07-10 15:06:26 -07002163 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002164 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2165 return null;
2166 }
Svetoslav64fad262015-04-14 14:35:21 -07002167
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002168 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002170 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002171 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172
Nathan Haroldf180aac2018-06-01 18:43:55 -07002173 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2174 for (CellInfo ci : info) {
2175 if (ci instanceof CellInfoGsm) {
2176 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2177 } else if (ci instanceof CellInfoWcdma) {
2178 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2179 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002181 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 }
2183
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002184 private List<CellInfo> getCachedCellInfo() {
2185 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2186 for (Phone phone : PhoneFactory.getPhones()) {
2187 List<CellInfo> info = phone.getAllCellInfo();
2188 if (info != null) cellInfos.addAll(info);
2189 }
2190 return cellInfos;
2191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192
2193 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002194 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002195 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002196 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002197
2198 LocationAccessPolicy.LocationPermissionResult locationResult =
2199 LocationAccessPolicy.checkLocationPermission(mApp,
2200 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2201 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002202 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002203 .setCallingPid(Binder.getCallingPid())
2204 .setCallingUid(Binder.getCallingUid())
2205 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002206 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002207 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2208 .build());
2209 switch (locationResult) {
2210 case DENIED_HARD:
2211 throw new SecurityException("Not allowed to access cell info");
2212 case DENIED_SOFT:
2213 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002214 }
2215
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002216 final int targetSdk = getTargetSdk(callingPackage);
2217 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2218 return getCachedCellInfo();
2219 }
2220
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002221 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002222 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002223 final long identity = Binder.clearCallingIdentity();
2224 try {
2225 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2226 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002227 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002228 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002229 if (info != null) cellInfos.addAll(info);
2230 }
2231 return cellInfos;
2232 } finally {
2233 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 }
2235 }
2236
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002237 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002238 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2239 String callingFeatureId) {
2240 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2241 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002242 }
2243
2244 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002245 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2246 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002247 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002248 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002249 }
2250
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002251 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2252 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002253 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002254 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002255
2256 LocationAccessPolicy.LocationPermissionResult locationResult =
2257 LocationAccessPolicy.checkLocationPermission(mApp,
2258 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2259 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002260 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002261 .setCallingPid(Binder.getCallingPid())
2262 .setCallingUid(Binder.getCallingUid())
2263 .setMethod("requestCellInfoUpdate")
2264 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2265 .build());
2266 switch (locationResult) {
2267 case DENIED_HARD:
2268 throw new SecurityException("Not allowed to access cell info");
2269 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002270 try {
2271 cb.onCellInfo(new ArrayList<CellInfo>());
2272 } catch (RemoteException re) {
2273 // Drop without consequences
2274 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002275 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002276 }
2277
Nathan Harolda939a962019-05-09 10:13:47 -07002278
2279 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002280 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2281
2282 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2283 }
2284
2285 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002287 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002288 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002289
2290 final long identity = Binder.clearCallingIdentity();
2291 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002292 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002293 } finally {
2294 Binder.restoreCallingIdentity(identity);
2295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296 }
2297
Shishir Agrawala9f32182016-04-12 12:00:16 -07002298 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002299 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002300 Phone phone = PhoneFactory.getPhone(slotIndex);
2301 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002302 return null;
2303 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002304 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002305 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002306 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002307 return null;
2308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002309
2310 final long identity = Binder.clearCallingIdentity();
2311 try {
2312 return phone.getImei();
2313 } finally {
2314 Binder.restoreCallingIdentity(identity);
2315 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002316 }
2317
2318 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002319 public String getTypeAllocationCodeForSlot(int slotIndex) {
2320 Phone phone = PhoneFactory.getPhone(slotIndex);
2321 String tac = null;
2322 if (phone != null) {
2323 String imei = phone.getImei();
2324 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2325 }
2326 return tac;
2327 }
2328
2329 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002330 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002331 Phone phone = PhoneFactory.getPhone(slotIndex);
2332 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002333 return null;
2334 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002335
Jeff Davidson913390f2018-02-23 17:11:49 -08002336 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002337 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002338 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002339 return null;
2340 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341
2342 final long identity = Binder.clearCallingIdentity();
2343 try {
2344 return phone.getMeid();
2345 } finally {
2346 Binder.restoreCallingIdentity(identity);
2347 }
Jack Yu2af8d712017-03-15 17:14:14 -07002348 }
2349
2350 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002351 public String getManufacturerCodeForSlot(int slotIndex) {
2352 Phone phone = PhoneFactory.getPhone(slotIndex);
2353 String manufacturerCode = null;
2354 if (phone != null) {
2355 String meid = phone.getMeid();
2356 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2357 }
2358 return manufacturerCode;
2359 }
2360
2361 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002362 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2363 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002364 Phone phone = PhoneFactory.getPhone(slotIndex);
2365 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002366 return null;
2367 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002368 int subId = phone.getSubId();
2369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002370 mApp, subId, callingPackage, callingFeatureId,
2371 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002372 return null;
2373 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002374
2375 final long identity = Binder.clearCallingIdentity();
2376 try {
2377 return phone.getDeviceSvn();
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
2380 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002381 }
2382
fionaxu43304da2017-11-27 22:51:16 -08002383 @Override
2384 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002385 final long identity = Binder.clearCallingIdentity();
2386 try {
2387 final Phone phone = getPhone(subId);
2388 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2389 } finally {
2390 Binder.restoreCallingIdentity(identity);
2391 }
fionaxu43304da2017-11-27 22:51:16 -08002392 }
2393
2394 @Override
2395 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002396 final long identity = Binder.clearCallingIdentity();
2397 try {
2398 final Phone phone = getPhone(subId);
2399 return phone == null ? null : phone.getCarrierName();
2400 } finally {
2401 Binder.restoreCallingIdentity(identity);
2402 }
fionaxu43304da2017-11-27 22:51:16 -08002403 }
2404
calvinpanffe225e2018-11-01 19:43:06 +08002405 @Override
chen xu0026ca62019-03-06 15:28:50 -08002406 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002407 final long identity = Binder.clearCallingIdentity();
2408 try {
2409 final Phone phone = getPhone(subId);
2410 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002411 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002412 } finally {
2413 Binder.restoreCallingIdentity(identity);
2414 }
2415 }
2416
2417 @Override
chen xu0026ca62019-03-06 15:28:50 -08002418 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002419 final long identity = Binder.clearCallingIdentity();
2420 try {
2421 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002422 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002423 } finally {
2424 Binder.restoreCallingIdentity(identity);
2425 }
2426 }
2427
chen xu651eec72018-11-11 19:03:44 -08002428 @Override
chen xu864e11c2018-12-06 22:10:03 -08002429 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2430 if (!isSubscriptionMccMnc) {
2431 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2432 }
chen xu651eec72018-11-11 19:03:44 -08002433 final Phone phone = PhoneFactory.getPhone(slotIndex);
2434 if (phone == null) {
2435 return TelephonyManager.UNKNOWN_CARRIER_ID;
2436 }
2437 final long identity = Binder.clearCallingIdentity();
2438 try {
2439 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2440 } finally {
2441 Binder.restoreCallingIdentity(identity);
2442 }
2443 }
2444
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 //
2446 // Internal helper methods.
2447 //
2448
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002449 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2451 *
2452 * @throws SecurityException if the caller does not have the required permission
2453 */
2454 private void enforceModifyPermission() {
2455 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2456 }
2457
Shuo Qian3b6ee772019-11-13 17:43:31 -08002458 private void enforceActiveEmergencySessionPermission() {
2459 mApp.enforceCallingOrSelfPermission(
2460 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2461 }
2462
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 /**
2464 * Make sure the caller has the CALL_PHONE permission.
2465 *
2466 * @throws SecurityException if the caller does not have the required permission
2467 */
2468 private void enforceCallPermission() {
2469 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2470 }
2471
paulhu5a773602019-08-23 19:17:33 +08002472 private void enforceSettingsPermission() {
2473 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002474 }
2475
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 private String createTelUrl(String number) {
2477 if (TextUtils.isEmpty(number)) {
2478 return null;
2479 }
2480
Jake Hambye994d462014-02-03 13:10:13 -08002481 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 }
2483
Ihab Awadf9e92732013-12-05 18:02:52 -08002484 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2486 }
2487
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002488 private static void logv(String msg) {
2489 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2490 }
2491
Ihab Awadf9e92732013-12-05 18:02:52 -08002492 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2494 }
2495
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002496 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002498 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002499 }
2500
Sanket Padawe356d7632015-06-22 14:03:32 -07002501 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002502 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503 final long identity = Binder.clearCallingIdentity();
2504 try {
2505 final Phone phone = PhoneFactory.getPhone(slotIndex);
2506 if (phone == null) {
2507 return PhoneConstants.PHONE_TYPE_NONE;
2508 } else {
2509 return phone.getPhoneType();
2510 }
2511 } finally {
2512 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002513 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002514 }
2515
2516 /**
2517 * Returns the CDMA ERI icon index to display
2518 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002519 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002520 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2521 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2522 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002523 }
2524
Sanket Padawe356d7632015-06-22 14:03:32 -07002525 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002526 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2527 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002528 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002529 mApp, subId, callingPackage, callingFeatureId,
2530 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002531 return -1;
2532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533
2534 final long identity = Binder.clearCallingIdentity();
2535 try {
2536 final Phone phone = getPhone(subId);
2537 if (phone != null) {
2538 return phone.getCdmaEriIconIndex();
2539 } else {
2540 return -1;
2541 }
2542 } finally {
2543 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002545 }
2546
2547 /**
2548 * Returns the CDMA ERI icon mode,
2549 * 0 - ON
2550 * 1 - FLASHING
2551 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002552 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002553 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2554 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2555 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002556 }
2557
Sanket Padawe356d7632015-06-22 14:03:32 -07002558 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002559 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2560 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002561 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002562 mApp, subId, callingPackage, callingFeatureId,
2563 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002564 return -1;
2565 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566
2567 final long identity = Binder.clearCallingIdentity();
2568 try {
2569 final Phone phone = getPhone(subId);
2570 if (phone != null) {
2571 return phone.getCdmaEriIconMode();
2572 } else {
2573 return -1;
2574 }
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578 }
2579
2580 /**
2581 * Returns the CDMA ERI text,
2582 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002583 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002584 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2585 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2586 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002587 }
2588
Sanket Padawe356d7632015-06-22 14:03:32 -07002589 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002590 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2591 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002593 mApp, subId, callingPackage, callingFeatureId,
2594 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002595 return null;
2596 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597
2598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 final Phone phone = getPhone(subId);
2601 if (phone != null) {
2602 return phone.getCdmaEriText();
2603 } else {
2604 return null;
2605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 }
2610
2611 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002612 * Returns the CDMA MDN.
2613 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002614 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002615 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2617 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618
2619 final long identity = Binder.clearCallingIdentity();
2620 try {
2621 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002622 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 return phone.getLine1Number();
2624 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002625 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 return null;
2627 }
2628 } finally {
2629 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002630 }
2631 }
2632
2633 /**
2634 * Returns the CDMA MIN.
2635 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002636 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002637 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2639 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640
2641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 final Phone phone = getPhone(subId);
2644 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2645 return phone.getCdmaMin();
2646 } else {
2647 return null;
2648 }
2649 } finally {
2650 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002651 }
2652 }
2653
Hall Liud892bec2018-11-30 14:51:45 -08002654 @Override
2655 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2656 INumberVerificationCallback callback, String callingPackage) {
2657 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2658 != PERMISSION_GRANTED) {
2659 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2660 }
2661 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2662
2663 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2664 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2665 throw new SecurityException("Calling package must be configured in the device config");
2666 }
2667
2668 if (range == null) {
2669 throw new NullPointerException("Range must be non-null");
2670 }
2671
2672 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002673 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002674
2675 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2676 }
2677
Junda Liuca05d5d2014-08-14 22:36:34 -07002678 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 * Returns true if CDMA provisioning needs to run.
2680 */
2681 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682 final long identity = Binder.clearCallingIdentity();
2683 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002684 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685 } finally {
2686 Binder.restoreCallingIdentity(identity);
2687 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 }
2689
2690 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002691 * Sets the voice mail number of a given subId.
2692 */
2693 @Override
2694 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002695 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2696 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697
2698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2701 new Pair<String, String>(alphaTag, number), new Integer(subId));
2702 return success;
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
2705 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002706 }
2707
Ta-wei Yen87c49842016-05-13 21:19:52 -07002708 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002709 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2710 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002711 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2712 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002713 if (!TextUtils.equals(callingPackage, systemDialer)) {
2714 throw new SecurityException("caller must be system dialer");
2715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716
2717 final long identity = Binder.clearCallingIdentity();
2718 try {
2719 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2720 if (phoneAccountHandle == null) {
2721 return null;
2722 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002723 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724 } finally {
2725 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002726 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002727 }
2728
2729 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002730 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2731 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002732 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002733 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002734 mApp, subId, callingPackage, callingFeatureId,
2735 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002736 return null;
2737 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002739 final long identity = Binder.clearCallingIdentity();
2740 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002741 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002742 } finally {
2743 Binder.restoreCallingIdentity(identity);
2744 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002745 }
2746
2747 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002748 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2749 VisualVoicemailSmsFilterSettings settings) {
2750 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002751
2752 final long identity = Binder.clearCallingIdentity();
2753 try {
2754 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002755 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756 } finally {
2757 Binder.restoreCallingIdentity(identity);
2758 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002759 }
2760
2761 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002762 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2763 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002768 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769 } finally {
2770 Binder.restoreCallingIdentity(identity);
2771 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002772 }
2773
2774 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002775 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2776 String callingPackage, int subId) {
2777 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778
2779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002782 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783 } finally {
2784 Binder.restoreCallingIdentity(identity);
2785 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002786 }
2787
2788 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002789 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002790 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791
2792 final long identity = Binder.clearCallingIdentity();
2793 try {
2794 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002795 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796 } finally {
2797 Binder.restoreCallingIdentity(identity);
2798 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002799 }
2800
2801 @Override
2802 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2803 String number, int port, String text, PendingIntent sentIntent) {
2804 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002805 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002806 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002807 SmsController smsController = PhoneFactory.getSmsController();
2808 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2809 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002810 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002811
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002812 /**
fionaxu0152e512016-11-14 13:36:14 -08002813 * Sets the voice activation state of a given subId.
2814 */
2815 @Override
2816 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2818 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 final Phone phone = getPhone(subId);
2823 if (phone != null) {
2824 phone.setVoiceActivationState(activationState);
2825 } else {
2826 loge("setVoiceActivationState fails with invalid subId: " + subId);
2827 }
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002830 }
2831 }
2832
2833 /**
2834 * Sets the data activation state of a given subId.
2835 */
2836 @Override
2837 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2839 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 final Phone phone = getPhone(subId);
2844 if (phone != null) {
2845 phone.setDataActivationState(activationState);
2846 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002847 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 }
2849 } finally {
2850 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002851 }
2852 }
2853
2854 /**
2855 * Returns the voice activation state of a given subId.
2856 */
2857 @Override
2858 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002859 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860
fionaxu0152e512016-11-14 13:36:14 -08002861 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 if (phone != null) {
2865 return phone.getVoiceActivationState();
2866 } else {
2867 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2868 }
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002871 }
2872 }
2873
2874 /**
2875 * Returns the data activation state of a given subId.
2876 */
2877 @Override
2878 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002879 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880
fionaxu0152e512016-11-14 13:36:14 -08002881 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 if (phone != null) {
2885 return phone.getDataActivationState();
2886 } else {
2887 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2888 }
2889 } finally {
2890 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002891 }
2892 }
2893
2894 /**
Wink Saville36469e72014-06-11 15:17:00 -07002895 * Returns the unread count of voicemails for a subId
2896 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002897 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002898 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2899 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002900 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002901 mApp, subId, callingPackage, callingFeatureId,
2902 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002903 return 0;
2904 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 final Phone phone = getPhone(subId);
2908 if (phone != null) {
2909 return phone.getVoiceMessageCount();
2910 } else {
2911 return 0;
2912 }
2913 } finally {
2914 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002916 }
2917
2918 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002919 * returns true, if the device is in a state where both voice and data
2920 * are supported simultaneously. This can change based on location or network condition.
2921 */
2922 @Override
2923 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 final long identity = Binder.clearCallingIdentity();
2925 try {
2926 final Phone phone = getPhone(subId);
2927 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
2930 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002931 }
2932
2933 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002934 * Send the dialer code if called from the current default dialer or the caller has
2935 * carrier privilege.
2936 * @param inputCode The dialer code to send
2937 */
2938 @Override
2939 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002940 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002941 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002942 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2943 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002944 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002945 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002946 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948
2949 final long identity = Binder.clearCallingIdentity();
2950 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002951 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002952 } finally {
2953 Binder.restoreCallingIdentity(identity);
2954 }
fionaxu235cc5e2017-03-06 22:25:57 -08002955 }
2956
Pengquan Menga1bb6272018-09-06 09:59:22 -07002957 @Override
2958 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002959 if (!isActiveSubscription(subId)) {
2960 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2961 }
2962
Pengquan Menga1bb6272018-09-06 09:59:22 -07002963 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2964 }
2965
Brad Ebinger35c841c2018-10-01 10:40:55 -07002966 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002967 public boolean isInEmergencySmsMode() {
2968 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2969 final long identity = Binder.clearCallingIdentity();
2970 try {
2971 for (Phone phone : PhoneFactory.getPhones()) {
2972 if (phone.isInEmergencySmsMode()) {
2973 return true;
2974 }
2975 }
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
2978 }
2979 return false;
2980 }
2981
2982 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002983 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2984 throws RemoteException {
2985 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002986 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2987 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2988 "IMS not available on device.");
2989 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002990 final long token = Binder.clearCallingIdentity();
2991 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002992 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002993 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002994 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002995 } catch (ImsException e) {
2996 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002997 } finally {
2998 Binder.restoreCallingIdentity(token);
2999 }
3000 }
3001
3002 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003003 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
3004 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003005 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3006 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3007 }
Meng Wangafbc5852019-09-19 17:37:13 -07003008 final long token = Binder.clearCallingIdentity();
3009 try {
3010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3011 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3012 .removeRegistrationCallbackForSubscription(c, subId);
3013 } catch (ImsException e) {
3014 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3015 + "is inactive, ignoring unregister.");
3016 // If the subscription is no longer active, just return, since the callback
3017 // will already have been removed internally.
3018 } finally {
3019 Binder.restoreCallingIdentity(token);
3020 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003021 }
3022
Brad Ebingera34a6c22019-10-22 17:36:18 -07003023 /**
3024 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3025 */
3026 @Override
3027 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3028 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3029 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3030 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3031 "IMS not available on device.");
3032 }
3033 final long token = Binder.clearCallingIdentity();
3034 try {
3035 Phone phone = getPhone(subId);
3036 if (phone == null) {
3037 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3038 + subId + "'");
3039 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3040 }
3041 phone.getImsRegistrationState(regState -> {
3042 try {
3043 consumer.accept((regState == null)
3044 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3045 } catch (RemoteException e) {
3046 // Ignore if the remote process is no longer available to call back.
3047 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3048 }
3049 });
3050 } finally {
3051 Binder.restoreCallingIdentity(token);
3052 }
3053 }
3054
3055 /**
3056 * Get the transport type for the IMS service registration state.
3057 */
3058 @Override
3059 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3060 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3061 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3062 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3063 "IMS not available on device.");
3064 }
3065 final long token = Binder.clearCallingIdentity();
3066 try {
3067 Phone phone = getPhone(subId);
3068 if (phone == null) {
3069 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3070 + subId + "'");
3071 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3072 }
3073 phone.getImsRegistrationTech(regTech -> {
3074 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3075 int regTechConverted = (regTech == null)
3076 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3077 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3078 regTechConverted);
3079 try {
3080 consumer.accept(regTechConverted);
3081 } catch (RemoteException e) {
3082 // Ignore if the remote process is no longer available to call back.
3083 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3084 }
3085 });
3086 } finally {
3087 Binder.restoreCallingIdentity(token);
3088 }
3089 }
3090
Brad Ebinger35c841c2018-10-01 10:40:55 -07003091 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003092 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3093 throws RemoteException {
3094 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003095 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3096 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3097 "IMS not available on device.");
3098 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003099 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3100 final long token = Binder.clearCallingIdentity();
3101 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003102 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003103 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003104 } catch (ImsException e) {
3105 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003106 } finally {
3107 Binder.restoreCallingIdentity(token);
3108 }
3109 }
3110
3111 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003112 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3113 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003114 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3115 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3116 }
Meng Wangafbc5852019-09-19 17:37:13 -07003117
3118 final long token = Binder.clearCallingIdentity();
3119 try {
3120 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3121 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003122 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003123 } catch (ImsException e) {
3124 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3125 + "is inactive, ignoring unregister.");
3126 // If the subscription is no longer active, just return, since the callback
3127 // will already have been removed internally.
3128 } finally {
3129 Binder.restoreCallingIdentity(token);
3130 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003131 }
3132
3133 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003134 public boolean isCapable(int subId, int capability, int regTech) {
3135 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003136 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3137 final long token = Binder.clearCallingIdentity();
3138 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003139 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003140 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003141 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003142 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3143 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003144 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003145 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3146 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003147 } finally {
3148 Binder.restoreCallingIdentity(token);
3149 }
3150 }
3151
3152 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003153 public boolean isAvailable(int subId, int capability, int regTech) {
3154 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003155 final long token = Binder.clearCallingIdentity();
3156 try {
3157 Phone phone = getPhone(subId);
3158 if (phone == null) return false;
3159 return phone.isImsCapabilityAvailable(capability, regTech);
3160 } finally {
3161 Binder.restoreCallingIdentity(token);
3162 }
3163 }
3164
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003165 /**
3166 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3167 * subscription.
3168 * @param subId The subscription to use to check the configuration.
3169 * @param callback The callback that will be used to send the result.
3170 * @param capability The MmTelFeature capability that will be used to send the result.
3171 * @param transportType The transport type of the MmTelFeature capability.
3172 */
3173 @Override
3174 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3175 int transportType) {
3176 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3177 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3178 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3179 "IMS not available on device.");
3180 }
3181 final long token = Binder.clearCallingIdentity();
3182 try {
3183 int slotId = getSlotIndex(subId);
3184 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3185 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3186 + subId + "'");
3187 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3188 }
3189 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3190 transportType, aBoolean -> {
3191 try {
3192 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3193 } catch (RemoteException e) {
3194 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3195 + "running. Ignore");
3196 }
3197 });
3198 } finally {
3199 Binder.restoreCallingIdentity(token);
3200 }
3201 }
3202
Brad Ebinger35c841c2018-10-01 10:40:55 -07003203 @Override
3204 public boolean isAdvancedCallingSettingEnabled(int subId) {
3205 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3206 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3207 final long token = Binder.clearCallingIdentity();
3208 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003209 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003210 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003211 } catch (ImsException e) {
3212 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003213 } finally {
3214 Binder.restoreCallingIdentity(token);
3215 }
3216 }
3217
3218 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003219 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003221 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003225 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003226 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003227 } catch (ImsException e) {
3228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
3232 }
3233
3234 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003235 public boolean isVtSettingEnabled(int subId) {
3236 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003240 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3241 } 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
Brad Ebinger1c162042019-02-21 14:49:10 -08003249 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003251 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003252 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, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003256 } catch (ImsException e) {
3257 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
3261 }
3262
3263 @Override
3264 public boolean isVoWiFiSettingEnabled(int subId) {
3265 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3266 final long identity = Binder.clearCallingIdentity();
3267 try {
3268 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003269 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003271 } catch (ImsException e) {
3272 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 } finally {
3274 Binder.restoreCallingIdentity(identity);
3275 }
3276 }
3277
3278 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003279 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003281 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003285 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003286 } catch (ImsException e) {
3287 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003288 } finally {
3289 Binder.restoreCallingIdentity(identity);
3290 }
3291 }
3292
3293 @Override
3294 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3295 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003299 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003300 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003301 } catch (ImsException e) {
3302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003303 } finally {
3304 Binder.restoreCallingIdentity(identity);
3305 }
3306 }
3307
3308 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003309 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003311 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003312 final long identity = Binder.clearCallingIdentity();
3313 try {
3314 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003315 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003316 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003317 } catch (ImsException e) {
3318 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003319 } finally {
3320 Binder.restoreCallingIdentity(identity);
3321 }
3322 }
3323
3324 @Override
3325 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3327 "setVoWiFiNonPersistent");
3328 final long identity = Binder.clearCallingIdentity();
3329 try {
3330 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003331 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003332 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003333 } catch (ImsException e) {
3334 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
3338 }
3339
3340 @Override
3341 public int getVoWiFiModeSetting(int subId) {
3342 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003346 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003347 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003348 } catch (ImsException e) {
3349 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003350 } finally {
3351 Binder.restoreCallingIdentity(identity);
3352 }
3353 }
3354
3355 @Override
3356 public void setVoWiFiModeSetting(int subId, int mode) {
3357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3358 "setVoWiFiModeSetting");
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,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003364 } catch (ImsException e) {
3365 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 } finally {
3367 Binder.restoreCallingIdentity(identity);
3368 }
3369 }
3370
3371 @Override
3372 public int getVoWiFiRoamingModeSetting(int subId) {
3373 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003377 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003378 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003379 } catch (ImsException e) {
3380 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 } finally {
3382 Binder.restoreCallingIdentity(identity);
3383 }
3384 }
3385
3386 @Override
3387 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3389 "setVoWiFiRoamingModeSetting");
3390 final long identity = Binder.clearCallingIdentity();
3391 try {
3392 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003393 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003394 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003395 } catch (ImsException e) {
3396 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
3400 }
3401
3402 @Override
3403 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3405 "setRttCapabilityEnabled");
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003409 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3410 } catch (ImsException e) {
3411 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003412 } finally {
3413 Binder.restoreCallingIdentity(identity);
3414 }
3415 }
3416
3417 @Override
3418 public boolean isTtyOverVolteEnabled(int subId) {
3419 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003423 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003424 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003425 } catch (ImsException e) {
3426 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
3430 }
3431
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003432 @Override
3433 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3434 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3435 final long identity = Binder.clearCallingIdentity();
3436 try {
Peter Wang44b186e2020-01-13 23:33:09 -08003437 if (isImsAvailableOnDevice()) {
3438 throw new ImsException("IMS not available on device.",
3439 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
3440 }
3441
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003442 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003443 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003444 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003445 } catch (ImsException e) {
3446 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003447 } finally {
3448 Binder.restoreCallingIdentity(identity);
3449 }
3450 }
3451
3452 @Override
3453 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3454 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3455 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003456 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3457 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3458 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003459 try {
3460 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003461 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003462 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003463 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003464 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3465 + "is inactive, ignoring unregister.");
3466 // If the subscription is no longer active, just return, since the callback will already
3467 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003468 } finally {
3469 Binder.restoreCallingIdentity(identity);
3470 }
3471 }
3472
allenwtsu99c623b2020-01-03 18:24:23 +08003473
3474 private void checkModifyPhoneStatePermission(int subId, String message) {
3475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3476 message);
3477 }
3478
3479 private boolean isImsProvisioningRequired(int subId, int capability,
3480 boolean isMmtelCapability) {
3481 Phone phone = getPhone(subId);
3482 if (phone == null) {
3483 loge("phone instance null for subid " + subId);
3484 return false;
3485 }
3486 if (isMmtelCapability) {
3487 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3488 return false;
3489 }
3490 } else {
3491 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3492 return false;
3493 }
3494 }
3495 return true;
3496 }
3497
3498 @Override
3499 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3500 boolean isProvisioned) {
3501 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3502
3503 final long identity = Binder.clearCallingIdentity();
3504 try {
3505 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3506 if (!isImsProvisioningRequired(subId, capability, false)) {
3507 return;
3508 }
3509
3510 // this capability requires provisioning, route to the correct API.
3511 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3512 switch (capability) {
3513 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3514 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3515 ims.setEabProvisioned(isProvisioned);
3516 break;
3517 default: {
3518 throw new IllegalArgumentException("Tried to set provisioning for "
3519 + "rcs capability '" + capability + "', which does not require "
3520 + "provisioning.");
3521 }
3522 }
3523 } finally {
3524 Binder.restoreCallingIdentity(identity);
3525 }
3526
3527 }
3528
3529
3530 @Override
3531 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3532 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3536 if (!isImsProvisioningRequired(subId, capability, false)) {
3537 return true;
3538 }
3539
3540 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3541 switch (capability) {
3542 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3543 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3544 return ims.isEabProvisionedOnDevice();
3545
3546 default: {
3547 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3548 + "capability '" + capability + "', which does not require "
3549 + "provisioning.");
3550 }
3551 }
3552
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
3556 }
3557
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003558 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003559 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3560 boolean isProvisioned) {
3561 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3562 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3563 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3564 }
allenwtsu99c623b2020-01-03 18:24:23 +08003565 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003569 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003570 return;
3571 }
3572
3573 // this capability requires provisioning, route to the correct API.
3574 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3575 switch (capability) {
3576 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3577 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3578 ims.setVolteProvisioned(isProvisioned);
3579 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3580 ims.setWfcProvisioned(isProvisioned);
3581 }
3582 break;
3583 }
3584 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3585 // There is currently no difference in VT provisioning type.
3586 ims.setVtProvisioned(isProvisioned);
3587 break;
3588 }
3589 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3590 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3591 // change the capability of the feature instead if needed.
3592 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3593 == isProvisioned) {
3594 // No change in provisioning.
3595 return;
3596 }
3597 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3598 try {
3599 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003600 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003601 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3602 + ", Exception" + e.getMessage());
3603 }
3604 break;
3605 }
3606 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003607 throw new IllegalArgumentException("Tried to set provisioning for "
3608 + "MmTel capability '" + capability + "', which does not require "
3609 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003610 }
3611 }
3612
3613 } finally {
3614 Binder.restoreCallingIdentity(identity);
3615 }
3616 }
3617
3618 @Override
3619 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3620 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3621 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3622 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3623 }
3624 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3625 final long identity = Binder.clearCallingIdentity();
3626 try {
3627 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003628 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003629 return true;
3630 }
3631
3632 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3633 switch (capability) {
3634 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3635 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3636 return ims.isVolteProvisionedOnDevice();
3637 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3638 return ims.isWfcProvisionedOnDevice();
3639 }
3640 // This should never happen, since we are checking tech above to make sure it
3641 // is either LTE or IWLAN.
3642 throw new IllegalArgumentException("Invalid radio technology for voice "
3643 + "capability.");
3644 }
3645 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3646 // There is currently no difference in VT provisioning type.
3647 return ims.isVtProvisionedOnDevice();
3648 }
3649 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3650 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3651 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3652 }
3653 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003654 throw new IllegalArgumentException(
3655 "Tried to get provisioning for MmTel capability '" + capability
3656 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003657 }
3658 }
3659
3660 } finally {
3661 Binder.restoreCallingIdentity(identity);
3662 }
3663 }
3664
3665 @Override
3666 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3667 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3668 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3669 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3670 }
3671 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3672 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3673 return (provisionedBits & capability) > 0;
3674 }
3675
3676 @Override
3677 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3678 boolean isProvisioned) {
3679 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3680 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3681 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3682 }
3683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3684 "setProvisioningStatusForCapability");
3685 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3686 // If the current provisioning status for capability already matches isProvisioned,
3687 // do nothing.
3688 if (((provisionedBits & capability) > 0) == isProvisioned) {
3689 return;
3690 }
3691 if (isProvisioned) {
3692 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3693 } else {
3694 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3695 }
3696 }
3697
3698 /**
3699 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3700 * technology. The bitfield should mirror the bitfield defined by
3701 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3702 */
3703 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3704 String key = getMmTelProvisioningKey(subId, tech);
3705 // Default is no capabilities are provisioned.
3706 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3707 }
3708
3709 /**
3710 * Sets the MmTel capability provisioning bitfield (defined by
3711 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3712 * technology specified.
3713 *
3714 * Note: This is a synchronous command and should not be called on UI thread.
3715 */
3716 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3717 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3718 String key = getMmTelProvisioningKey(subId, tech);
3719 editor.putInt(key, newField);
3720 editor.commit();
3721 }
3722
3723 private static String getMmTelProvisioningKey(int subId, int tech) {
3724 // resulting key is provision_ims_mmtel_{subId}_{tech}
3725 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3726 }
3727
3728 /**
3729 * Query CarrierConfig to see if the specified capability requires provisioning for the
3730 * carrier associated with the subscription id.
3731 */
3732 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3733 int capability) {
3734 CarrierConfigManager configManager = new CarrierConfigManager(context);
3735 PersistableBundle c = configManager.getConfigForSubId(subId);
3736 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003737 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003738 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3739 false);
3740 boolean requireVoiceVtProvisioning = c.getBoolean(
3741 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3742
3743 // First check to make sure that the capability requires provisioning.
3744 switch (capability) {
3745 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3746 // intentional fallthrough
3747 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3748 if (requireVoiceVtProvisioning) {
3749 // Voice and Video requires provisioning
3750 return true;
3751 }
3752 break;
3753 }
3754 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3755 if (requireUtProvisioning) {
3756 // UT requires provisioning
3757 return true;
3758 }
3759 break;
3760 }
3761 }
3762 return false;
3763 }
3764
allenwtsu99c623b2020-01-03 18:24:23 +08003765 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3766 int capability) {
3767 CarrierConfigManager configManager = new CarrierConfigManager(context);
3768 PersistableBundle c = configManager.getConfigForSubId(subId);
3769
3770 boolean requireRcsProvisioning = c.getBoolean(
3771 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3772
3773 // First check to make sure that the capability requires provisioning.
3774 switch (capability) {
3775 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3776 // intentional fallthrough
3777 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3778 if (requireRcsProvisioning) {
3779 // OPTION or PRESENCE requires provisioning
3780 return true;
3781 }
3782 break;
3783 }
3784 }
3785 return false;
3786 }
3787
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003788 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003789 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003790 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3791 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3792 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003793 enforceReadPrivilegedPermission("getImsProvisioningInt");
3794 final long identity = Binder.clearCallingIdentity();
3795 try {
3796 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003797 int slotId = getSlotIndex(subId);
3798 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3799 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3800 + subId + "' for key:" + key);
3801 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3802 }
3803 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003804 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003805 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3806 + subId + "' for key:" + key);
3807 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003808 } finally {
3809 Binder.restoreCallingIdentity(identity);
3810 }
3811 }
3812
3813 @Override
3814 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003815 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3816 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3817 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003818 enforceReadPrivilegedPermission("getImsProvisioningString");
3819 final long identity = Binder.clearCallingIdentity();
3820 try {
3821 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003822 int slotId = getSlotIndex(subId);
3823 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3824 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3825 + subId + "' for key:" + key);
3826 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3827 }
3828 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003829 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003830 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3831 + subId + "' for key:" + key);
3832 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003833 } finally {
3834 Binder.restoreCallingIdentity(identity);
3835 }
3836 }
3837
3838 @Override
3839 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003840 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3841 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3842 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3844 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003845 final long identity = Binder.clearCallingIdentity();
3846 try {
3847 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003848 int slotId = getSlotIndex(subId);
3849 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3850 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3851 + subId + "' for key:" + key);
3852 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3853 }
3854 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003855 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003856 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3857 + "' for key:" + key);
3858 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003859 } finally {
3860 Binder.restoreCallingIdentity(identity);
3861 }
3862 }
3863
3864 @Override
3865 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003866 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3867 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3868 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3870 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003871 final long identity = Binder.clearCallingIdentity();
3872 try {
3873 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003874 int slotId = getSlotIndex(subId);
3875 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3876 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3877 + subId + "' for key:" + key);
3878 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3879 }
3880 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003881 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003882 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3883 + "' for key:" + key);
3884 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003885 } finally {
3886 Binder.restoreCallingIdentity(identity);
3887 }
3888 }
3889
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003890 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003891 int slotId = SubscriptionManager.getSlotIndex(subId);
3892 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003893 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3894 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003895 }
3896 return slotId;
3897 }
3898
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003899 private int getSlotIndex(int subId) {
3900 int slotId = SubscriptionManager.getSlotIndex(subId);
3901 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3902 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3903 }
3904 return slotId;
3905 }
3906
Wink Saville36469e72014-06-11 15:17:00 -07003907 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003908 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003909 */
3910 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003911 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3912 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003913 final int targetSdk = getTargetSdk(callingPackage);
3914 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003915 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003916 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003917 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003918 mApp, subId, callingPackage, callingFeatureId,
3919 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003920 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3921 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003923 final long identity = Binder.clearCallingIdentity();
3924 try {
3925 final Phone phone = getPhone(subId);
3926 if (phone != null) {
3927 return phone.getServiceState().getDataNetworkType();
3928 } else {
3929 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3930 }
3931 } finally {
3932 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003934 }
3935
3936 /**
3937 * Returns the data network type
3938 */
3939 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003940 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3941 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3942 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003943 }
3944
3945 /**
3946 * Returns the data network type for a subId
3947 */
3948 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003949 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3950 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003951 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003952 mApp, subId, callingPackage, callingFeatureId,
3953 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003954 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3955 }
3956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957 final long identity = Binder.clearCallingIdentity();
3958 try {
3959 final Phone phone = getPhone(subId);
3960 if (phone != null) {
3961 return phone.getServiceState().getDataNetworkType();
3962 } else {
3963 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3964 }
3965 } finally {
3966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003968 }
3969
3970 /**
Wink Saville36469e72014-06-11 15:17:00 -07003971 * Returns the Voice network type for a subId
3972 */
3973 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003974 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3975 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003976 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003977 mApp, subId, callingPackage, callingFeatureId,
3978 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003979 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3980 }
3981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003982 final long identity = Binder.clearCallingIdentity();
3983 try {
3984 final Phone phone = getPhone(subId);
3985 if (phone != null) {
3986 return phone.getServiceState().getVoiceNetworkType();
3987 } else {
3988 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3989 }
3990 } finally {
3991 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003993 }
3994
3995 /**
3996 * @return true if a ICC card is present
3997 */
3998 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003999 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004000 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4001 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004002 }
4003
4004 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004005 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004006 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004007 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004008 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 final Phone phone = PhoneFactory.getPhone(slotIndex);
4012 if (phone != null) {
4013 return phone.getIccCard().hasIccCard();
4014 } else {
4015 return false;
4016 }
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004019 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004020 }
4021
4022 /**
4023 * Return if the current radio is LTE on CDMA. This
4024 * is a tri-state return value as for a period of time
4025 * the mode may be unknown.
4026 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004027 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004028 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004029 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004030 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004031 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004032 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4033 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4034 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004035 }
4036
Sanket Padawe356d7632015-06-22 14:03:32 -07004037 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004038 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4039 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004040 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004041 mApp, subId, callingPackage, callingFeatureId,
4042 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004043 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4044 }
4045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004046 final long identity = Binder.clearCallingIdentity();
4047 try {
4048 final Phone phone = getPhone(subId);
4049 if (phone == null) {
4050 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4051 } else {
4052 return phone.getLteOnCdmaMode();
4053 }
4054 } finally {
4055 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004056 }
Wink Saville36469e72014-06-11 15:17:00 -07004057 }
4058
Wink Saville36469e72014-06-11 15:17:00 -07004059 /**
4060 * {@hide}
4061 * Returns Default subId, 0 in the case of single standby.
4062 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004063 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004064 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004065 }
4066
Shishir Agrawala9f32182016-04-12 12:00:16 -07004067 private int getSlotForDefaultSubscription() {
4068 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4069 }
4070
Wink Savilleb564aae2014-10-23 10:18:09 -07004071 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004072 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004073 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004074
Pengquan Menge92a50d2018-09-21 15:54:48 -07004075 private boolean isActiveSubscription(int subId) {
4076 return mSubscriptionController.isActiveSubId(subId);
4077 }
4078
Ihab Awadf2177b72013-11-25 13:33:23 -08004079 /**
4080 * @see android.telephony.TelephonyManager.WifiCallingChoices
4081 */
4082 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004083 final long identity = Binder.clearCallingIdentity();
4084 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004085 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4087 getWhenToMakeWifiCallsDefaultPreference());
4088 } finally {
4089 Binder.restoreCallingIdentity(identity);
4090 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004091 }
4092
4093 /**
4094 * @see android.telephony.TelephonyManager.WifiCallingChoices
4095 */
4096 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004097 final long identity = Binder.clearCallingIdentity();
4098 try {
4099 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004100 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4102 } finally {
4103 Binder.restoreCallingIdentity(identity);
4104 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004105 }
4106
Sailesh Nepald1e68152013-12-12 19:08:02 -08004107 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004108 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004109 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004110 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004111
Jordan Liu4c733742019-02-28 12:03:40 -08004112 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4113 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4114 if (phoneId == -1) {
4115 throw new IllegalArgumentException("Given slot index: " + slotIndex
4116 + " does not correspond to an active phone");
4117 }
4118 return PhoneFactory.getPhone(phoneId);
4119 }
4120
Shishir Agrawal566b7612013-10-28 14:41:00 -07004121 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004122 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4123 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4125 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004126 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004127 if (DBG) {
4128 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4129 }
4130 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4131 p2);
4132 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004133
Jordan Liu4c733742019-02-28 12:03:40 -08004134
4135 @Override
4136 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4137 int slotIndex, String callingPackage, String aid, int p2) {
4138 enforceModifyPermission();
4139 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4140 if (DBG) {
4141 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4142 }
4143 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4144 callingPackage, aid, p2);
4145 }
4146
4147 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4148 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 if (TextUtils.equals(ISDR_AID, aid)) {
4152 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004153 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4154 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004155 if (bestComponent == null
4156 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4157 loge("The calling package is not allowed to access ISD-R.");
4158 throw new SecurityException(
4159 "The calling package is not allowed to access ISD-R.");
4160 }
Derek Tan740e1672017-06-27 14:56:27 -07004161 }
Derek Tan740e1672017-06-27 14:56:27 -07004162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004163 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004164 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4165 null /* workSource */);
4166 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004167 return response;
4168 } finally {
4169 Binder.restoreCallingIdentity(identity);
4170 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004171 }
4172
4173 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004174 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4176 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004177 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4178 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4179 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004180
Jordan Liu4c733742019-02-28 12:03:40 -08004181 @Override
4182 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4183 enforceModifyPermission();
4184 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4185 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4186 channel);
4187 }
4188
4189 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004190 final long identity = Binder.clearCallingIdentity();
4191 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004192 if (channel < 0) {
4193 return false;
4194 }
Jordan Liu4c733742019-02-28 12:03:40 -08004195 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4196 null /* workSource */);
4197 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004198 return success;
4199 } finally {
4200 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004201 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004202 }
4203
4204 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004205 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004206 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4208 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004209 if (DBG) {
4210 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4211 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4212 + p3 + " data=" + data);
4213 }
4214 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4215 command, p1, p2, p3, data);
4216 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004217
Jordan Liu4c733742019-02-28 12:03:40 -08004218 @Override
4219 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4220 int command, int p1, int p2, int p3, String data) {
4221 enforceModifyPermission();
4222 if (DBG) {
4223 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4224 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4225 + p3 + " data=" + data);
4226 }
4227 return iccTransmitApduLogicalChannelWithPermission(
4228 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4229 data);
4230 }
4231
4232 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4233 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004234 final long identity = Binder.clearCallingIdentity();
4235 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004236 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004237 return "";
4238 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004241 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4242 null /* workSource */);
4243 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004245 // Append the returned status code to the end of the response payload.
4246 String s = Integer.toHexString(
4247 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4248 if (response.payload != null) {
4249 s = IccUtils.bytesToHexString(response.payload) + s;
4250 }
4251 return s;
4252 } finally {
4253 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004254 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004255 }
Jake Hambye994d462014-02-03 13:10:13 -08004256
Evan Charltonc66da362014-05-16 14:06:40 -07004257 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004258 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4259 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4261 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004262 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004263 if (DBG) {
4264 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4265 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4266 }
4267 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4268 cla, command, p1, p2, p3, data);
4269 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004270
Jordan Liu4c733742019-02-28 12:03:40 -08004271 @Override
4272 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4273 int command, int p1, int p2, int p3, String data) {
4274 enforceModifyPermission();
4275 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4276 if (DBG) {
4277 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4278 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4279 + " data=" + data);
4280 }
4281
4282 return iccTransmitApduBasicChannelWithPermission(
4283 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4284 p2, p3, data);
4285 }
4286
4287 // open APDU basic channel assuming the caller has sufficient permissions
4288 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4289 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4293 && TextUtils.equals(ISDR_AID, data)) {
4294 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004295 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4296 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004297 if (bestComponent == null
4298 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4299 loge("The calling package is not allowed to select ISD-R.");
4300 throw new SecurityException(
4301 "The calling package is not allowed to select ISD-R.");
4302 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004303 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004305 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004306 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4307 null /* workSource */);
4308 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004309
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004310 // Append the returned status code to the end of the response payload.
4311 String s = Integer.toHexString(
4312 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4313 if (response.payload != null) {
4314 s = IccUtils.bytesToHexString(response.payload) + s;
4315 }
4316 return s;
4317 } finally {
4318 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004319 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004320 }
4321
4322 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004323 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004324 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4326 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 if (DBG) {
4331 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4332 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4333 }
4334
4335 IccIoResult response =
4336 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4337 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4338 subId);
4339
4340 if (DBG) {
4341 log("Exchange SIM_IO [R]" + response);
4342 }
4343
4344 byte[] result = null;
4345 int length = 2;
4346 if (response.payload != null) {
4347 length = 2 + response.payload.length;
4348 result = new byte[length];
4349 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4350 } else {
4351 result = new byte[length];
4352 }
4353
4354 result[length - 1] = (byte) response.sw2;
4355 result[length - 2] = (byte) response.sw1;
4356 return result;
4357 } finally {
4358 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004359 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004360 }
4361
Nathan Haroldb3014052017-01-25 15:57:32 -08004362 /**
4363 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4364 * on a particular subscription
4365 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004366 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4367 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004368 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004369 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004370 return null;
4371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004372
4373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 if (appType != TelephonyManager.APPTYPE_USIM
4376 && appType != TelephonyManager.APPTYPE_SIM) {
4377 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4378 return null;
4379 }
4380 Object response = sendRequest(
4381 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4382 if (response instanceof String[]) {
4383 return (String[]) response;
4384 }
yincheng zhao2737e882019-09-06 17:06:54 -07004385 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004386 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004387 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004388 } finally {
4389 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004390 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004391 }
4392
yincheng zhao2737e882019-09-06 17:06:54 -07004393 /**
4394 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4395 * subscription.
4396 *
4397 * @param subId the id of the subscription.
4398 * @param appType the uicc app type, must be USIM or SIM.
4399 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4400 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004401 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004402 * @return number of fplmns that is successfully written to the SIM.
4403 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004404 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4405 String callingFeatureId) {
4406 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4407 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004408 if (DBG) logv("no permissions for setForbiddenplmns");
4409 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4410 }
4411 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4412 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4413 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4414 }
4415 if (fplmns == null) {
4416 throw new IllegalArgumentException("Fplmn List provided is null");
4417 }
4418 for (String fplmn : fplmns) {
4419 if (!CellIdentity.isValidPlmn(fplmn)) {
4420 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4421 }
4422 }
4423 final long identity = Binder.clearCallingIdentity();
4424 try {
4425 Object response = sendRequest(
4426 CMD_SET_FORBIDDEN_PLMNS,
4427 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4428 subId);
4429 return (int) response;
4430 } finally {
4431 Binder.restoreCallingIdentity(identity);
4432 }
4433 }
4434
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004435 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004436 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4438 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440 final long identity = Binder.clearCallingIdentity();
4441 try {
4442 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4443 if (response.payload == null) {
4444 return "";
4445 }
Evan Charltonc66da362014-05-16 14:06:40 -07004446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 // Append the returned status code to the end of the response payload.
4448 String s = Integer.toHexString(
4449 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4450 s = IccUtils.bytesToHexString(response.payload) + s;
4451 return s;
4452 } finally {
4453 Binder.restoreCallingIdentity(identity);
4454 }
Evan Charltonc66da362014-05-16 14:06:40 -07004455 }
4456
Jake Hambye994d462014-02-03 13:10:13 -08004457 /**
4458 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4459 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4460 *
4461 * @param itemID the ID of the item to read
4462 * @return the NV item as a String, or null on error.
4463 */
4464 @Override
4465 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004466 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4468 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469
4470 final long identity = Binder.clearCallingIdentity();
4471 try {
4472 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004473 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4475 return value;
4476 } finally {
4477 Binder.restoreCallingIdentity(identity);
4478 }
Jake Hambye994d462014-02-03 13:10:13 -08004479 }
4480
4481 /**
4482 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4483 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4484 *
4485 * @param itemID the ID of the item to read
4486 * @param itemValue the value to write, as a String
4487 * @return true on success; false on any failure
4488 */
4489 @Override
4490 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004491 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4493 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004494
4495 final long identity = Binder.clearCallingIdentity();
4496 try {
4497 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4498 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004499 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4501 return success;
4502 } finally {
4503 Binder.restoreCallingIdentity(identity);
4504 }
Jake Hambye994d462014-02-03 13:10:13 -08004505 }
4506
4507 /**
4508 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4509 * Used for device configuration by some CDMA operators.
4510 *
4511 * @param preferredRoamingList byte array containing the new PRL
4512 * @return true on success; false on any failure
4513 */
4514 @Override
4515 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4517 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518
4519 final long identity = Binder.clearCallingIdentity();
4520 try {
4521 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4522 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4523 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4524 return success;
4525 } finally {
4526 Binder.restoreCallingIdentity(identity);
4527 }
Jake Hambye994d462014-02-03 13:10:13 -08004528 }
4529
4530 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004531 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004532 * Used for device configuration by some CDMA operators.
4533 *
chen xu6dac5ab2018-10-26 17:39:23 -07004534 * @param slotIndex - device slot.
4535 *
Jake Hambye994d462014-02-03 13:10:13 -08004536 * @return true on success; false on any failure
4537 */
4538 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004539 public boolean resetModemConfig(int slotIndex) {
4540 Phone phone = PhoneFactory.getPhone(slotIndex);
4541 if (phone != null) {
4542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4543 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004544
chen xu6dac5ab2018-10-26 17:39:23 -07004545 final long identity = Binder.clearCallingIdentity();
4546 try {
4547 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4548 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4549 return success;
4550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 }
chen xu6dac5ab2018-10-26 17:39:23 -07004554 return false;
4555 }
4556
4557 /**
4558 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4559 *
4560 * @param slotIndex - device slot.
4561 *
4562 * @return true on success; false on any failure
4563 */
4564 @Override
4565 public boolean rebootModem(int slotIndex) {
4566 Phone phone = PhoneFactory.getPhone(slotIndex);
4567 if (phone != null) {
4568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4569 mApp, phone.getSubId(), "rebootModem");
4570
4571 final long identity = Binder.clearCallingIdentity();
4572 try {
4573 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4574 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4575 return success;
4576 } finally {
4577 Binder.restoreCallingIdentity(identity);
4578 }
4579 }
4580 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004581 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004582
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004583 public String[] getPcscfAddress(String apnType, String callingPackage,
4584 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004585 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4587 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004588 return new String[0];
4589 }
4590
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591 final long identity = Binder.clearCallingIdentity();
4592 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004593 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004594 } finally {
4595 Binder.restoreCallingIdentity(identity);
4596 }
Wink Saville36469e72014-06-11 15:17:00 -07004597 }
4598
Brad Ebinger51f743a2017-01-23 13:50:20 -08004599 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004600 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4601 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004602 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004603 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004604 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004605
4606 final long identity = Binder.clearCallingIdentity();
4607 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004608 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004609 // may happen if the device does not support IMS.
4610 return;
4611 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004612 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004613 } finally {
4614 Binder.restoreCallingIdentity(identity);
4615 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004616 }
4617
4618 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004619 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4620 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004621 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004622 public void disableIms(int slotId) {
4623 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624
4625 final long identity = Binder.clearCallingIdentity();
4626 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004627 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004628 // may happen if the device does not support IMS.
4629 return;
4630 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004631 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632 } finally {
4633 Binder.restoreCallingIdentity(identity);
4634 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004635 }
4636
4637 /**
4638 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4639 * feature or {@link null} if the service is not available. If the feature is available, the
4640 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4641 */
4642 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004643 IImsServiceFeatureCallback callback) {
4644 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004645
4646 final long identity = Binder.clearCallingIdentity();
4647 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004648 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004649 // may happen if the device does not support IMS.
4650 return null;
4651 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004652 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 } finally {
4654 Binder.restoreCallingIdentity(identity);
4655 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004656 }
4657
4658 /**
4659 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4660 * feature during emergency calling or {@link null} if the service is not available. If the
4661 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4662 * listener for feature updates.
4663 */
4664 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004666
4667 final long identity = Binder.clearCallingIdentity();
4668 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004669 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004670 // may happen if the device does not support IMS.
4671 return null;
4672 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004673 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004674 } finally {
4675 Binder.restoreCallingIdentity(identity);
4676 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004677 }
4678
Brad Ebinger5f64b052017-12-14 14:26:15 -08004679 /**
4680 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004681 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004682 */
4683 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685
4686 final long identity = Binder.clearCallingIdentity();
4687 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004688 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004689 // may happen if the device does not support IMS.
4690 return null;
4691 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004692 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004696 }
4697
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004698 /**
4699 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004700 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004701 */
4702 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4703 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704
4705 final long identity = Binder.clearCallingIdentity();
4706 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004707 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004708 // may happen if the device does not support IMS.
4709 return null;
4710 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004711 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004712 } finally {
4713 Binder.restoreCallingIdentity(identity);
4714 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004715 }
4716
Brad Ebinger884c07b2018-02-15 16:17:40 -08004717 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004718 * Sets the ImsService Package Name that Telephony will bind to.
4719 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004720 * @param slotIndex the slot ID that the ImsService should bind for.
4721 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004722 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004723 * @param featureTypes An integer array of feature types associated with a packageName.
4724 * @param packageName The name of the package that the current configuration will be replaced
4725 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004726 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004727 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004728 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4729 int[] featureTypes, String packageName) {
4730 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4731 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4733 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004734 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004736 final long identity = Binder.clearCallingIdentity();
4737 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004738 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004739 // may happen if the device does not support IMS.
4740 return false;
4741 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004742 Map<Integer, String> featureConfig = new HashMap<>();
4743 for (int featureType : featureTypes) {
4744 featureConfig.put(featureType, packageName);
4745 }
4746 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4747 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004748 } finally {
4749 Binder.restoreCallingIdentity(identity);
4750 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004751 }
4752
4753 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004754 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004755 *
4756 * @param slotId The slot that the ImsService is associated with.
4757 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4758 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004759 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004760 * @return the package name of the ImsService configuration.
4761 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004762 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4763 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004764 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004765 TelephonyPermissions
4766 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4767 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4768 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004770 final long identity = Binder.clearCallingIdentity();
4771 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004772 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004773 // may happen if the device does not support IMS.
4774 return "";
4775 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004776 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004777 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4778 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004779 } finally {
4780 Binder.restoreCallingIdentity(identity);
4781 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004782 }
4783
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004784 /**
4785 * Get the MmTelFeature state associated with the requested subscription id.
4786 * @param subId The subscription that the MmTelFeature is associated with.
4787 * @param callback A callback with an integer containing the
4788 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4789 */
4790 @Override
4791 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4792 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4793 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4794 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4795 "IMS not available on device.");
4796 }
4797 final long token = Binder.clearCallingIdentity();
4798 try {
4799 int slotId = getSlotIndex(subId);
4800 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4801 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4802 + subId + "'");
4803 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4804 }
4805 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4806 try {
4807 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4808 } catch (RemoteException e) {
4809 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4810 + "Ignore");
4811 }
4812 });
4813 } finally {
4814 Binder.restoreCallingIdentity(token);
4815 }
4816 }
4817
Wink Saville36469e72014-06-11 15:17:00 -07004818 public void setImsRegistrationState(boolean registered) {
4819 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004820
4821 final long identity = Binder.clearCallingIdentity();
4822 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004823 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824 } finally {
4825 Binder.restoreCallingIdentity(identity);
4826 }
Wink Saville36469e72014-06-11 15:17:00 -07004827 }
4828
4829 /**
Stuart Scott54788802015-03-30 13:18:01 -07004830 * Set the network selection mode to automatic.
4831 *
4832 */
4833 @Override
4834 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4836 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004837
Pengquan Menge92a50d2018-09-21 15:54:48 -07004838 if (!isActiveSubscription(subId)) {
4839 return;
4840 }
4841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004842 final long identity = Binder.clearCallingIdentity();
4843 try {
4844 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4845 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4846 } finally {
4847 Binder.restoreCallingIdentity(identity);
4848 }
Stuart Scott54788802015-03-30 13:18:01 -07004849 }
4850
Pengquan Mengea84e042018-09-20 14:57:26 -07004851 /**
4852 * Ask the radio to connect to the input network and change selection mode to manual.
4853 *
4854 * @param subId the id of the subscription.
4855 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4856 * the operator to attach to.
4857 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4858 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4859 * normal network selection next time.
4860 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004861 */
4862 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004863 public boolean setNetworkSelectionModeManual(
4864 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4866 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004867
4868 if (!isActiveSubscription(subId)) {
4869 return false;
4870 }
4871
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004872 final long identity = Binder.clearCallingIdentity();
4873 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004874 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004875 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004876 if (DBG) {
4877 log("setNetworkSelectionModeManual: subId: " + subId
4878 + " operator: " + operatorInfo);
4879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004880 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4881 } finally {
4882 Binder.restoreCallingIdentity(identity);
4883 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004884 }
4885
4886 /**
4887 * Scans for available networks.
4888 */
4889 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004890 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4891 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4893 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004894 LocationAccessPolicy.LocationPermissionResult locationResult =
4895 LocationAccessPolicy.checkLocationPermission(mApp,
4896 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4897 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004898 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004899 .setCallingPid(Binder.getCallingPid())
4900 .setCallingUid(Binder.getCallingUid())
4901 .setMethod("getCellNetworkScanResults")
4902 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4903 .build());
4904 switch (locationResult) {
4905 case DENIED_HARD:
4906 throw new SecurityException("Not allowed to access scan results -- location");
4907 case DENIED_SOFT:
4908 return null;
4909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910
Pengquan Menga1bb6272018-09-06 09:59:22 -07004911 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 try {
4913 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004914 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004915 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004916 } finally {
4917 Binder.restoreCallingIdentity(identity);
4918 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004919 }
4920
4921 /**
yinxub1bed742017-04-17 11:45:04 -07004922 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004923 *
yinxub1bed742017-04-17 11:45:04 -07004924 * @param subId id of the subscription
4925 * @param request contains the radio access networks with bands/channels to scan
4926 * @param messenger callback messenger for scan results or errors
4927 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004928 * @return the id of the requested scan which can be used to stop the scan.
4929 */
4930 @Override
4931 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004932 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4934 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004935 LocationAccessPolicy.LocationPermissionResult locationResult =
4936 LocationAccessPolicy.checkLocationPermission(mApp,
4937 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4938 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004939 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004940 .setCallingPid(Binder.getCallingPid())
4941 .setCallingUid(Binder.getCallingUid())
4942 .setMethod("requestNetworkScan")
4943 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4944 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004945 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004946 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004947 if (e != null) {
4948 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4949 throw e;
4950 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004951 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004952 return TelephonyScanManager.INVALID_SCAN_ID;
4953 }
4954 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004955 }
Hall Liu912dfd32019-04-25 14:02:26 -07004956 int callingUid = Binder.getCallingUid();
4957 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004958 final long identity = Binder.clearCallingIdentity();
4959 try {
4960 return mNetworkScanRequestTracker.startNetworkScan(
4961 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004962 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004963 } finally {
4964 Binder.restoreCallingIdentity(identity);
4965 }
yinxu504e1392017-04-12 16:03:22 -07004966 }
4967
Hall Liub2ac8ef2019-02-28 15:56:23 -08004968 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004969 NetworkScanRequest request, int subId) {
4970 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4971 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4972 boolean hasNetworkScanPermission =
4973 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4974 == PERMISSION_GRANTED;
4975
4976 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4977 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4978 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004979 }
4980
4981 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4982 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004983 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4984 return new SecurityException("Specific channels must not be"
4985 + " scanned without location access.");
4986 }
4987 }
4988 }
4989
Hall Liub2ac8ef2019-02-28 15:56:23 -08004990 return null;
4991 }
4992
yinxu504e1392017-04-12 16:03:22 -07004993 /**
4994 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004995 *
4996 * @param subId id of the subscription
4997 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004998 */
4999 @Override
5000 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5002 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003
Hall Liu912dfd32019-04-25 14:02:26 -07005004 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005 final long identity = Binder.clearCallingIdentity();
5006 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005007 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008 } finally {
5009 Binder.restoreCallingIdentity(identity);
5010 }
yinxu504e1392017-04-12 16:03:22 -07005011 }
5012
5013 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005014 * Get the calculated preferred network type.
5015 * Used for debugging incorrect network type.
5016 *
5017 * @return the preferred network type, defined in RILConstants.java.
5018 */
5019 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005020 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005021 final Phone defaultPhone = getDefaultPhone();
5022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005023 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005024 return RILConstants.PREFERRED_NETWORK_MODE;
5025 }
5026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005027 final long identity = Binder.clearCallingIdentity();
5028 try {
5029 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005030 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031 } finally {
5032 Binder.restoreCallingIdentity(identity);
5033 }
Junda Liu84d15a22014-07-02 11:21:04 -07005034 }
5035
5036 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005037 * Get the preferred network type.
5038 * Used for device configuration by some CDMA operators.
5039 *
5040 * @return the preferred network type, defined in RILConstants.java.
5041 */
5042 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005043 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005044 TelephonyPermissions
5045 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5046 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005047
5048 final long identity = Binder.clearCallingIdentity();
5049 try {
5050 if (DBG) log("getPreferredNetworkType");
5051 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5052 int networkType = (result != null ? result[0] : -1);
5053 if (DBG) log("getPreferredNetworkType: " + networkType);
5054 return networkType;
5055 } finally {
5056 Binder.restoreCallingIdentity(identity);
5057 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005058 }
5059
5060 /**
5061 * Set the preferred network type.
5062 * Used for device configuration by some CDMA operators.
5063 *
5064 * @param networkType the preferred network type, defined in RILConstants.java.
5065 * @return true on success; false on any failure.
5066 */
5067 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005068 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5070 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071
5072 final long identity = Binder.clearCallingIdentity();
5073 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005074 Settings.Global.putInt(mApp.getContentResolver(),
5075 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5076 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077 } finally {
5078 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005079 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005080 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005081
5082 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005083 * Get the allowed network types that store in the telephony provider.
5084 *
5085 * @param subId the id of the subscription.
5086 * @return allowedNetworkTypes the allowed network types.
5087 */
5088 @Override
5089 public long getAllowedNetworkTypes(int subId) {
5090 TelephonyPermissions
5091 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5092 mApp, subId, "getAllowedNetworkTypes");
5093
5094 final long identity = Binder.clearCallingIdentity();
5095 try {
5096 return SubscriptionManager.getLongSubscriptionProperty(
5097 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
5100 }
5101 }
5102
5103 /**
5104 * Set the allowed network types.
5105 *
5106 * @param subId the id of the subscription.
5107 * @param allowedNetworkTypes the allowed network types.
5108 * @return true on success; false on any failure.
5109 */
5110 @Override
5111 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5113 mApp, subId, "setAllowedNetworkTypes");
5114 final long identity = Binder.clearCallingIdentity();
5115 try {
5116 SubscriptionManager.setSubscriptionProperty(subId,
5117 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5118 String.valueOf(allowedNetworkTypes));
5119 return setPreferredNetworkTypesInternal(subId);
5120 } finally {
5121 Binder.restoreCallingIdentity(identity);
5122 }
5123 }
5124
5125 private boolean setPreferredNetworkTypesInternal(int subId) {
5126 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5127 Settings.Global.getInt(mApp.getContentResolver(),
5128 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5129 RILConstants.PREFERRED_NETWORK_MODE));
5130 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5131 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5132 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5133 (int) (networkTypeBitMask & allowedNetworkTypes));
5134
5135 if (DBG) {
5136 log("setPreferredNetworkTypesInternal: subId " + subId
5137 + " networkTypes " + networkTypeBitMask
5138 + " allowedNetworkTypes " + allowedNetworkTypes
5139 + " networkMode " + networkMode);
5140 }
5141
5142 Boolean success = (Boolean) sendRequest(
5143 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5144 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5145 return success;
5146 }
5147
5148 /**
Miaoa84611c2019-03-15 09:21:10 +08005149 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005150 *
Miaoa84611c2019-03-15 09:21:10 +08005151 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005152 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005153 * @hide
5154 */
5155 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005156 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005157 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005159 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005160 try {
Miaoa84611c2019-03-15 09:21:10 +08005161 if (phone != null) {
5162 return phone.hasMatchedTetherApnSetting();
5163 } else {
5164 return false;
5165 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 } finally {
5167 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005168 }
Junda Liu475951f2014-11-07 16:45:03 -08005169 }
5170
5171 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005172 * Set mobile data enabled
5173 * Used by the user through settings etc to turn on/off mobile data
5174 *
5175 * @param enable {@code true} turn turn data on, else {@code false}
5176 */
5177 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005178 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5180 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005181
5182 final long identity = Binder.clearCallingIdentity();
5183 try {
5184 int phoneId = mSubscriptionController.getPhoneId(subId);
5185 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5186 Phone phone = PhoneFactory.getPhone(phoneId);
5187 if (phone != null) {
5188 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005189 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005191 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 }
5193 } finally {
5194 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005195 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005196 }
5197
5198 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005199 * Get the user enabled state of Mobile Data.
5200 *
5201 * TODO: remove and use isUserDataEnabled.
5202 * This can't be removed now because some vendor codes
5203 * calls through ITelephony directly while they should
5204 * use TelephonyManager.
5205 *
5206 * @return true on enabled
5207 */
5208 @Override
5209 public boolean getDataEnabled(int subId) {
5210 return isUserDataEnabled(subId);
5211 }
5212
5213 /**
5214 * Get whether mobile data is enabled per user setting.
5215 *
5216 * There are other factors deciding whether mobile data is actually enabled, but they are
5217 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005218 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005219 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005220 *
5221 * @return {@code true} if data is enabled else {@code false}
5222 */
5223 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005224 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005225 try {
5226 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5227 null);
5228 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5230 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232
5233 final long identity = Binder.clearCallingIdentity();
5234 try {
5235 int phoneId = mSubscriptionController.getPhoneId(subId);
5236 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5237 Phone phone = PhoneFactory.getPhone(phoneId);
5238 if (phone != null) {
5239 boolean retVal = phone.isUserDataEnabled();
5240 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5241 return retVal;
5242 } else {
5243 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5244 return false;
5245 }
5246 } finally {
5247 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005248 }
5249 }
5250
5251 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005252 * Checks if the device is capable of mobile data by considering whether whether the
5253 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5254 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005255 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005256 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005257 */
5258 @Override
5259 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005260 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261
5262 final long identity = Binder.clearCallingIdentity();
5263 try {
5264 int phoneId = mSubscriptionController.getPhoneId(subId);
5265 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5266 Phone phone = PhoneFactory.getPhone(phoneId);
5267 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005268 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5270 return retVal;
5271 } else {
5272 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5273 return false;
5274 }
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005277 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005278 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005279
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005280 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5281 Phone phone) {
5282 //load access rules from carrier configs, and check those as well: b/139133814
5283 SubscriptionController subController = SubscriptionController.getInstance();
5284 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5285 || subController == null) return privilegeFromSim;
5286
5287 int uid = Binder.getCallingUid();
5288 PackageManager pkgMgr = phone.getContext().getPackageManager();
5289 String[] packages = pkgMgr.getPackagesForUid(uid);
5290
5291 final long identity = Binder.clearCallingIdentity();
5292 try {
5293 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5294 SubscriptionManager subManager = (SubscriptionManager)
5295 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5296 for (String pkg : packages) {
5297 if (subManager.canManageSubscription(subInfo, pkg)) {
5298 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5299 }
5300 }
5301 return privilegeFromSim;
5302 } finally {
5303 Binder.restoreCallingIdentity(identity);
5304 }
5305 }
5306
5307 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5308 String pkgName) {
5309 //load access rules from carrier configs, and check those as well: b/139133814
5310 SubscriptionController subController = SubscriptionController.getInstance();
5311 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5312 || subController == null) return privilegeFromSim;
5313
5314 final long identity = Binder.clearCallingIdentity();
5315 try {
5316 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5317 SubscriptionManager subManager = (SubscriptionManager)
5318 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5319 return subManager.canManageSubscription(subInfo, pkgName)
5320 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5321 } finally {
5322 Binder.restoreCallingIdentity(identity);
5323 }
5324 }
5325
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005326 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005327 public int getCarrierPrivilegeStatus(int subId) {
5328 final Phone phone = getPhone(subId);
5329 if (phone == null) {
5330 loge("getCarrierPrivilegeStatus: Invalid subId");
5331 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5332 }
5333 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005334 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005335 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005336 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5337 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005338
5339 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5340 card.getCarrierPrivilegeStatusForCurrentTransaction(
5341 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005342 }
Junda Liu29340342014-07-10 15:23:27 -07005343
5344 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005345 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005346 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005347 final Phone phone = getPhone(subId);
5348 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005349 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005350 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5351 }
5352 UiccProfile profile =
5353 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5354 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005355 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005356 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5357 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005358 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005359 profile.getCarrierPrivilegeStatusForUid(
5360 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005361 }
5362
5363 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005364 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5365 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005366 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005367 }
5368
5369 int phoneId = SubscriptionManager.getPhoneId(subId);
5370 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005371 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005372 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005373 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5374 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005375 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5376 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5377 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005378 }
5379
5380 @Override
5381 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005382 if (TextUtils.isEmpty(pkgName))
5383 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005384 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5385 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5386 UiccCard card = UiccController.getInstance().getUiccCard(i);
5387 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005388 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005389 continue;
5390 }
5391
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005392 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5393 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5394 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005395 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5396 break;
5397 }
5398 }
5399
5400 return result;
Junda Liu29340342014-07-10 15:23:27 -07005401 }
Derek Tan89e89d42014-07-08 17:00:10 -07005402
5403 @Override
Junda Liue64de782015-04-16 17:19:16 -07005404 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5405 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5406 loge("phoneId " + phoneId + " is not valid.");
5407 return null;
5408 }
5409 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005410 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005411 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005412 return null ;
5413 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005414 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005415 }
5416
Amith Yamasani6e118872016-02-19 12:53:51 -08005417 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005418 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005419 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005420 List<String> privilegedPackages = new ArrayList<>();
5421 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005422 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5423 // has UICC in that slot.
5424 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005425 if (card.hasCarrierPrivilegeRules()) {
5426 if (packages == null) {
5427 // Only check packages in user 0 for now
5428 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005429 PackageManager.MATCH_DISABLED_COMPONENTS
5430 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005431 | PackageManager.GET_SIGNING_CERTIFICATES,
5432 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005433 }
5434 for (int p = packages.size() - 1; p >= 0; p--) {
5435 PackageInfo pkgInfo = packages.get(p);
5436 if (pkgInfo != null && pkgInfo.packageName != null
5437 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005438 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005439 privilegedPackages.add(pkgInfo.packageName);
5440 }
5441 }
5442 }
5443 }
5444 return privilegedPackages;
5445 }
5446
chen xuf7e9fe82019-05-09 19:31:02 -07005447 @Override
5448 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005449 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5450
5451 final long identity = Binder.clearCallingIdentity();
5452
chen xuf7e9fe82019-05-09 19:31:02 -07005453 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005454 try {
5455 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5456 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5457 }
5458 } finally {
5459 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005460 }
5461 return privilegedPackages;
5462 }
5463
Wink Savilleb564aae2014-10-23 10:18:09 -07005464 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005465 final Phone phone = getPhone(subId);
5466 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005467 if (card == null) {
5468 loge("getIccId: No UICC");
5469 return null;
5470 }
5471 String iccId = card.getIccId();
5472 if (TextUtils.isEmpty(iccId)) {
5473 loge("getIccId: ICC ID is null or empty.");
5474 return null;
5475 }
5476 return iccId;
5477 }
5478
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005479 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005480 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5481 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005482 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005483 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005484
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485 final long identity = Binder.clearCallingIdentity();
5486 try {
5487 final String iccId = getIccId(subId);
5488 final Phone phone = getPhone(subId);
5489 if (phone == null) {
5490 return false;
5491 }
5492 final String subscriberId = phone.getSubscriberId();
5493
5494 if (DBG_MERGE) {
5495 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5496 + subscriberId + " to " + number);
5497 }
5498
5499 if (TextUtils.isEmpty(iccId)) {
5500 return false;
5501 }
5502
5503 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5504
5505 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5506 if (alphaTag == null) {
5507 editor.remove(alphaTagPrefKey);
5508 } else {
5509 editor.putString(alphaTagPrefKey, alphaTag);
5510 }
5511
5512 // Record both the line number and IMSI for this ICCID, since we need to
5513 // track all merged IMSIs based on line number
5514 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5515 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5516 if (number == null) {
5517 editor.remove(numberPrefKey);
5518 editor.remove(subscriberPrefKey);
5519 } else {
5520 editor.putString(numberPrefKey, number);
5521 editor.putString(subscriberPrefKey, subscriberId);
5522 }
5523
5524 editor.commit();
5525 return true;
5526 } finally {
5527 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005528 }
Derek Tan7226c842014-07-02 17:42:23 -07005529 }
5530
5531 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005532 public String getLine1NumberForDisplay(int subId, String callingPackage,
5533 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005534 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005535 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005536 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005537 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005538 return null;
5539 }
Derek Tan97ebb422014-09-05 16:55:38 -07005540
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005541 final long identity = Binder.clearCallingIdentity();
5542 try {
5543 String iccId = getIccId(subId);
5544 if (iccId != null) {
5545 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5546 if (DBG_MERGE) {
5547 log("getLine1NumberForDisplay returning "
5548 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5549 }
5550 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005552 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5553 return null;
5554 } finally {
5555 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005556 }
Derek Tan7226c842014-07-02 17:42:23 -07005557 }
5558
5559 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005560 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5561 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005562 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005563 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005564 return null;
5565 }
Derek Tan97ebb422014-09-05 16:55:38 -07005566
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567 final long identity = Binder.clearCallingIdentity();
5568 try {
5569 String iccId = getIccId(subId);
5570 if (iccId != null) {
5571 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5572 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5573 }
5574 return null;
5575 } finally {
5576 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005577 }
Derek Tan7226c842014-07-02 17:42:23 -07005578 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005579
5580 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005581 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5582 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005583 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5584 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005585 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005586 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005587 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005588 return null;
5589 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005590
Jordan Liub49b04b2019-05-06 14:45:15 -07005591 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5592 // the process, where TelephonyManager was instantiated.
5593 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005594 final long identity = Binder.clearCallingIdentity();
5595 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005596 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005597 final TelephonyManager tele = TelephonyManager.from(context);
5598 final SubscriptionManager sub = SubscriptionManager.from(context);
5599
5600 // Figure out what subscribers are currently active
5601 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602
Jordan Liub49b04b2019-05-06 14:45:15 -07005603 // Only consider subs which match the current subId
5604 // This logic can be simplified. See b/131189269 for progress.
5605 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005606 activeSubscriberIds.add(tele.getSubscriberId(subId));
5607 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608
5609 // First pass, find a number override for an active subscriber
5610 String mergeNumber = null;
5611 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5612 for (String key : prefs.keySet()) {
5613 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5614 final String subscriberId = (String) prefs.get(key);
5615 if (activeSubscriberIds.contains(subscriberId)) {
5616 final String iccId = key.substring(
5617 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5618 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5619 mergeNumber = (String) prefs.get(numberKey);
5620 if (DBG_MERGE) {
5621 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5622 + " for active subscriber " + subscriberId);
5623 }
5624 if (!TextUtils.isEmpty(mergeNumber)) {
5625 break;
5626 }
5627 }
5628 }
5629 }
5630
5631 // Shortcut when no active merged subscribers
5632 if (TextUtils.isEmpty(mergeNumber)) {
5633 return null;
5634 }
5635
5636 // Second pass, find all subscribers under that line override
5637 final ArraySet<String> result = new ArraySet<>();
5638 for (String key : prefs.keySet()) {
5639 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5640 final String number = (String) prefs.get(key);
5641 if (mergeNumber.equals(number)) {
5642 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5643 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5644 final String subscriberId = (String) prefs.get(subscriberKey);
5645 if (!TextUtils.isEmpty(subscriberId)) {
5646 result.add(subscriberId);
5647 }
5648 }
5649 }
5650 }
5651
5652 final String[] resultArray = result.toArray(new String[result.size()]);
5653 Arrays.sort(resultArray);
5654 if (DBG_MERGE) {
5655 Slog.d(LOG_TAG,
5656 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5657 }
5658 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005659 } finally {
5660 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005661 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005662 }
5663
5664 @Override
zoey chen38003472019-12-13 17:16:31 +08005665 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5666 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005667
5668 final long identity = Binder.clearCallingIdentity();
5669 try {
5670 final TelephonyManager telephonyManager = mApp.getSystemService(
5671 TelephonyManager.class);
5672 String subscriberId = telephonyManager.getSubscriberId(subId);
5673 if (subscriberId == null) {
5674 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005675 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005676 + subId);
5677 }
5678 return null;
5679 }
5680
5681 final SubscriptionInfo info = SubscriptionController.getInstance()
5682 .getSubscriptionInfo(subId);
5683 final ParcelUuid groupUuid = info.getGroupUuid();
5684 // If it doesn't belong to any group, return just subscriberId of itself.
5685 if (groupUuid == null) {
5686 return new String[]{subscriberId};
5687 }
5688
5689 // Get all subscriberIds from the group.
5690 final List<String> mergedSubscriberIds = new ArrayList<>();
5691 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005692 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5693 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005694 for (SubscriptionInfo subInfo : groupInfos) {
5695 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5696 if (subscriberId != null) {
5697 mergedSubscriberIds.add(subscriberId);
5698 }
5699 }
5700
5701 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5702 } finally {
5703 Binder.restoreCallingIdentity(identity);
5704
5705 }
5706 }
5707
5708 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005709 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005710 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005711 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712
5713 final long identity = Binder.clearCallingIdentity();
5714 try {
5715 final Phone phone = getPhone(subId);
5716 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005720 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005721
5722 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005723 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005724 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5725 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005726 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5727 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728
5729 final long identity = Binder.clearCallingIdentity();
5730 try {
5731 final Phone phone = getPhone(subId);
5732 if (phone == null) {
5733 return false;
5734 }
5735 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5736 cdmaNonRoamingList);
5737 } finally {
5738 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005739 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005740 }
5741
5742 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005743 @Deprecated
5744 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5745 enforceModifyPermission();
5746
5747 int returnValue = 0;
5748 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005749 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005750 if(result.exception == null) {
5751 if (result.result != null) {
5752 byte[] responseData = (byte[])(result.result);
5753 if(responseData.length > oemResp.length) {
5754 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5755 responseData.length + "bytes. Buffer Size is " +
5756 oemResp.length + "bytes.");
5757 }
5758 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5759 returnValue = responseData.length;
5760 }
5761 } else {
5762 CommandException ex = (CommandException) result.exception;
5763 returnValue = ex.getCommandError().ordinal();
5764 if(returnValue > 0) returnValue *= -1;
5765 }
5766 } catch (RuntimeException e) {
5767 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5768 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5769 if(returnValue > 0) returnValue *= -1;
5770 }
5771
5772 return returnValue;
5773 }
5774
5775 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005776 public void setRadioCapability(RadioAccessFamily[] rafs) {
5777 try {
5778 ProxyController.getInstance().setRadioCapability(rafs);
5779 } catch (RuntimeException e) {
5780 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5781 }
5782 }
5783
5784 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005785 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005786 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005787 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005788 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005789 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005790 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 final long identity = Binder.clearCallingIdentity();
5792 try {
chen xub97461a2018-10-26 14:17:57 -07005793 TelephonyPermissions
5794 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5795 mApp, phone.getSubId(), "getRadioAccessFamily");
5796 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797 } finally {
5798 Binder.restoreCallingIdentity(identity);
5799 }
chen xub97461a2018-10-26 14:17:57 -07005800 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005801 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005802
5803 @Override
5804 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005805 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005806 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807
5808 final long identity = Binder.clearCallingIdentity();
5809 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005810 ImsManager.getInstance(defaultPhone.getContext(),
5811 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812 } finally {
5813 Binder.restoreCallingIdentity(identity);
5814 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005815 }
5816
5817 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005818 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005819 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005820 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5821 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005822 return false;
5823 }
Svet Ganovb320e182015-04-16 12:30:10 -07005824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 final long identity = Binder.clearCallingIdentity();
5826 try {
5827 // Check the user preference and the system-level IMS setting. Even if the user has
5828 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5829 // In the long run, we may instead need to check if there exists a connection service
5830 // which can support video calling.
5831 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005832 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833 return imsManager.isVtEnabledByPlatform()
5834 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5835 && imsManager.isVtEnabledByUser();
5836 } finally {
5837 Binder.restoreCallingIdentity(identity);
5838 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005839 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005840
Andrew Leea1239f22015-03-02 17:44:07 -08005841 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005842 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5843 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005845 mApp, subId, callingPackage, callingFeatureId,
5846 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847 return false;
5848 }
5849
5850 final long identity = Binder.clearCallingIdentity();
5851 try {
5852 CarrierConfigManager configManager =
5853 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005854 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005855 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5856 } finally {
5857 Binder.restoreCallingIdentity(identity);
5858 }
Andrew Leea1239f22015-03-02 17:44:07 -08005859 }
5860
5861 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005862 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005864 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005865 return false;
5866 }
5867
5868 final long identity = Binder.clearCallingIdentity();
5869 try {
5870 CarrierConfigManager configManager =
5871 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005872 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005873 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5874 } finally {
5875 Binder.restoreCallingIdentity(identity);
5876 }
Andrew Leea1239f22015-03-02 17:44:07 -08005877 }
5878
Andrew Lee9431b832015-03-09 18:46:45 -07005879 @Override
5880 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005881 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005882 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005883 }
5884
5885 @Override
5886 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 final long identity = Binder.clearCallingIdentity();
5888 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005889 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890 } finally {
5891 Binder.restoreCallingIdentity(identity);
5892 }
Andrew Lee9431b832015-03-09 18:46:45 -07005893 }
5894
Hall Liuf6668912018-10-31 17:05:23 -07005895 /**
5896 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5897 * support for the feature and device firmware support.
5898 *
5899 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5900 */
5901 @Override
5902 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005904 final Phone phone = getPhone(subscriptionId);
5905 if (phone == null) {
5906 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5907 return false;
5908 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005909 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005910 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5912 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005913 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914 return isCarrierSupported && isDeviceSupported;
5915 } finally {
5916 Binder.restoreCallingIdentity(identity);
5917 }
Hall Liu98187582018-01-22 19:15:32 -08005918 }
5919
Hall Liuf6668912018-10-31 17:05:23 -07005920 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005921 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5922 * RTT setting, will return true if the device and carrier both support RTT.
5923 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005924 */
5925 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926 final long identity = Binder.clearCallingIdentity();
5927 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00005928 boolean isRttSupported = isRttSupported(subscriptionId);
5929 boolean isUserRttSettingOn = Settings.Secure.getInt(
5930 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5931 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5932 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5933 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934 } finally {
5935 Binder.restoreCallingIdentity(identity);
5936 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005937 }
5938
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005939 @Deprecated
5940 @Override
5941 public String getDeviceId(String callingPackage) {
5942 return getDeviceIdWithFeature(callingPackage, null);
5943 }
5944
Sanket Padawe7310cc72015-01-14 09:53:20 -08005945 /**
5946 * Returns the unique device ID of phone, for example, the IMEI for
5947 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5948 *
5949 * <p>Requires Permission:
5950 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5951 */
5952 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005953 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005954 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005955 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005956 return null;
5957 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005958 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005959 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005960 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005961 return null;
5962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963
5964 final long identity = Binder.clearCallingIdentity();
5965 try {
5966 return phone.getDeviceId();
5967 } finally {
5968 Binder.restoreCallingIdentity(identity);
5969 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005970 }
5971
Ping Sunc67b7c22016-03-02 19:16:45 +08005972 /**
5973 * {@hide}
5974 * Returns the IMS Registration Status on a particular subid
5975 *
5976 * @param subId
5977 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005978 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005979 Phone phone = getPhone(subId);
5980 if (phone != null) {
5981 return phone.isImsRegistered();
5982 } else {
5983 return false;
5984 }
5985 }
5986
Santos Cordon7a1885b2015-02-03 11:15:19 -08005987 @Override
5988 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005989 final long identity = Binder.clearCallingIdentity();
5990 try {
5991 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5992 } finally {
5993 Binder.restoreCallingIdentity(identity);
5994 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005995 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005996
Tyler Gunnf70ed162019-04-03 15:28:53 -07005997 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005998 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005999 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006000 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006001 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006002 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6003 }
6004 final long identity = Binder.clearCallingIdentity();
6005 try {
6006 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6007 } finally {
6008 Binder.restoreCallingIdentity(identity);
6009 }
6010 }
6011
6012 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006013 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6014 final long identity = Binder.clearCallingIdentity();
6015 try {
6016 Phone phone = getPhone(subscriptionId);
6017 if (phone == null) {
6018 return null;
6019 }
6020 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6021 } finally {
6022 Binder.restoreCallingIdentity(identity);
6023 }
6024 }
6025
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006026 /**
6027 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006028 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006029 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 final long identity = Binder.clearCallingIdentity();
6031 try {
6032 Phone phone = getPhone(subId);
6033 if (phone != null) {
6034 return phone.isWifiCallingEnabled();
6035 } else {
6036 return false;
6037 }
6038 } finally {
6039 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006040 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006041 }
6042
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006043 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006044 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006045 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006046 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006047 final long identity = Binder.clearCallingIdentity();
6048 try {
6049 Phone phone = getPhone(subId);
6050 if (phone != null) {
6051 return phone.isVideoEnabled();
6052 } else {
6053 return false;
6054 }
6055 } finally {
6056 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006057 }
6058 }
6059
6060 /**
6061 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6062 * defined in {@link ImsRegistrationImplBase}.
6063 */
6064 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 final long identity = Binder.clearCallingIdentity();
6066 try {
6067 Phone phone = getPhone(subId);
6068 if (phone != null) {
6069 return phone.getImsRegistrationTech();
6070 } else {
6071 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6072 }
6073 } finally {
6074 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006075 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006076 }
6077
Stuart Scott8eef64f2015-04-08 15:13:54 -07006078 @Override
6079 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006080 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006081 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6082 return;
6083 }
6084
Svet Ganovcc087f82015-05-12 20:35:54 -07006085 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006086
Svet Ganovcc087f82015-05-12 20:35:54 -07006087 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006088 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6089 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006090 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006091 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006092 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006093 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6094 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006095 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006096 // There has been issues when Sms raw table somehow stores orphan
6097 // fragments. They lead to garbled message when new fragments come
6098 // in and combined with those stale ones. In case this happens again,
6099 // user can reset all network settings which will clean up this table.
6100 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006101 // Clean up IMS settings as well here.
6102 int slotId = getSlotIndex(subId);
6103 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6104 ImsManager.getInstance(mApp, slotId).factoryReset();
6105 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006106
6107 // Erase modem config if erase modem on network setting is enabled.
6108 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6109 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6110 if (configValue != null && Boolean.parseBoolean(configValue)) {
6111 sendEraseModemConfig(getDefaultPhone());
6112 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006113 } finally {
6114 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006115 }
6116 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006117
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006118 private void cleanUpSmsRawTable(Context context) {
6119 ContentResolver resolver = context.getContentResolver();
6120 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6121 resolver.delete(uri, null, null);
6122 }
6123
Narayan Kamath1c496c22015-04-16 14:40:19 +01006124 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006125 public String getSimLocaleForSubscriber(int subId) {
6126 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6127 final Phone phone = getPhone(subId);
6128 if (phone == null) {
6129 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006130 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006131 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 final long identity = Binder.clearCallingIdentity();
6133 try {
chen xu5d3637b2019-01-21 23:31:38 -08006134 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006135 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006136 if (info == null) {
6137 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6138 return null;
6139 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140 // Try and fetch the locale from the carrier properties or from the SIM language
6141 // preferences (EF-PL and EF-LI)...
6142 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006144 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6145 if (localeFromDefaultSim != null) {
6146 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6147 if (DBG) log("Using locale from subId: " + subId + " locale: "
6148 + localeFromDefaultSim);
6149 return localeFromDefaultSim.toLanguageTag();
6150 } else {
6151 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006152 }
6153 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155 // The SIM language preferences only store a language (e.g. fr = French), not an
6156 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6157 // the SIM and carrier preferences does not include a country we add the country
6158 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006159 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006161 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162 return mccLocale.toLanguageTag();
6163 }
6164
6165 if (DBG) log("No locale found - returning null");
6166 return null;
6167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006170 }
6171
6172 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006173 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6174 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006175 }
6176
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006177 /**
6178 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6179 */
6180 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006181 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6182 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006183 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006184
Chenjie Yu1ba97252018-01-11 18:16:20 -08006185 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006186 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006187
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006188 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006189 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6190 * representing the state of the modem.
6191 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006192 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6193 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006194 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006195 */
6196 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006197 public void requestModemActivityInfo(ResultReceiver result) {
6198 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006199 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006200
6201 final long identity = Binder.clearCallingIdentity();
6202 try {
6203 ModemActivityInfo ret = null;
6204 synchronized (mLastModemActivityInfo) {
6205 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6206 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006207 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006208 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006209 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006210 int[] txTimeMs = info.getTransmitTimeMillis();
6211 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006212 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006213 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 }
6215 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006216 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6217 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006218 mLastModemActivityInfo.setIdleTimeMillis(
6219 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006220 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6221 mLastModemActivityInfo.setReceiveTimeMillis(
6222 info.getReceiveTimeMillis() + mLastModemActivityInfo
6223 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006224 }
Chen Xud78231e2019-09-10 18:49:52 -07006225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6227 mLastModemActivityInfo.getSleepTimeMillis(),
6228 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006229 mLastModemActivityInfo.getTransmitTimeMillis(),
6230 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232 Bundle bundle = new Bundle();
6233 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6234 result.send(0, bundle);
6235 } finally {
6236 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006237 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006238 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006239
Siddharth Rayb8114062018-06-17 15:02:38 -07006240 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6241 // less than total activity duration.
6242 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6243 if (info == null) {
6244 return false;
6245 }
6246 int activityDurationMs =
6247 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6248 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006249 int[] txTimeMs = info.getTransmitTimeMillis();
6250 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6251 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006252 }
6253 return (info.isValid()
6254 && (info.getSleepTimeMillis() <= activityDurationMs)
6255 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006256 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006257 && (totalTxTimeMs <= activityDurationMs));
6258 }
6259
Jack Yu85bd38a2015-11-09 11:34:32 -08006260 /**
6261 * {@hide}
6262 * Returns the service state information on specified subscription.
6263 */
6264 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006265 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6266 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006268 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006269 return null;
6270 }
6271
Hall Liuf19c44f2018-11-27 14:38:17 -08006272 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6273 LocationAccessPolicy.checkLocationPermission(mApp,
6274 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6275 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006276 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006277 .setCallingPid(Binder.getCallingPid())
6278 .setCallingUid(Binder.getCallingUid())
6279 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006280 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006281 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6282 .build());
6283
6284 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6285 LocationAccessPolicy.checkLocationPermission(mApp,
6286 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6287 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006288 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006289 .setCallingPid(Binder.getCallingPid())
6290 .setCallingUid(Binder.getCallingUid())
6291 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006292 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006293 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6294 .build());
6295 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6296 boolean hasFinePermission =
6297 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6298 boolean hasCoarsePermission =
6299 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301 final long identity = Binder.clearCallingIdentity();
6302 try {
6303 final Phone phone = getPhone(subId);
6304 if (phone == null) {
6305 return null;
6306 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006307
Hall Liuf19c44f2018-11-27 14:38:17 -08006308 ServiceState ss = phone.getServiceState();
6309
6310 // Scrub out the location info in ServiceState depending on what level of access
6311 // the caller has.
6312 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006313 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6314 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 } finally {
6316 Binder.restoreCallingIdentity(identity);
6317 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006318 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006319
6320 /**
6321 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6322 *
6323 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6324 * voicemail ringtone.
6325 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6326 * PhoneAccount.
6327 */
6328 @Override
6329 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006330 final long identity = Binder.clearCallingIdentity();
6331 try {
6332 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6333 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006334 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006335 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6338 } finally {
6339 Binder.restoreCallingIdentity(identity);
6340 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006341 }
6342
6343 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006344 * Sets the per-account voicemail ringtone.
6345 *
6346 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6347 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6348 *
6349 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6350 * voicemail ringtone.
6351 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6352 * PhoneAccount.
6353 */
6354 @Override
6355 public void setVoicemailRingtoneUri(String callingPackage,
6356 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006357 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006358 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006359 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6360 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6362 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6363 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006364 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365
6366 final long identity = Binder.clearCallingIdentity();
6367 try {
6368 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6369 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006370 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371 }
6372 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6373 } finally {
6374 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006375 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006376 }
6377
6378 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006379 * Returns whether vibration is set for voicemail notification in Phone settings.
6380 *
6381 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6382 * voicemail vibration setting.
6383 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6384 */
6385 @Override
6386 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387 final long identity = Binder.clearCallingIdentity();
6388 try {
6389 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6390 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006391 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006392 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006393
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6395 } finally {
6396 Binder.restoreCallingIdentity(identity);
6397 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006398 }
6399
Youhan Wange64578a2016-05-02 15:32:42 -07006400 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006401 * Sets the per-account voicemail vibration.
6402 *
6403 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6404 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6405 *
6406 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6407 * voicemail vibration setting.
6408 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6409 * specific PhoneAccount.
6410 */
6411 @Override
6412 public void setVoicemailVibrationEnabled(String callingPackage,
6413 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006414 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006415 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006416 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6417 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6419 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6420 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006421 }
6422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006423 final long identity = Binder.clearCallingIdentity();
6424 try {
6425 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6426 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006427 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006428 }
6429 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6430 } finally {
6431 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006432 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006433 }
6434
6435 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006436 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6437 *
6438 * @throws SecurityException if the caller does not have the required permission
6439 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006440 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006441 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006442 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006443 }
6444
6445 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006446 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6447 * permission.
6448 *
6449 * @throws SecurityException if the caller does not have the required permission
6450 */
6451 private void enforceSendSmsPermission() {
6452 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6453 }
6454
6455 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006456 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006457 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006458 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006459 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006460 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006461 final long identity = Binder.clearCallingIdentity();
6462 try {
6463 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006464 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006465 if (componentName == null) {
6466 throw new SecurityException(
6467 "Caller not current active visual voicemail package[null]");
6468 }
6469 String vvmPackage = componentName.getPackageName();
6470 if (!callingPackage.equals(vvmPackage)) {
6471 throw new SecurityException("Caller not current active visual voicemail package["
6472 + vvmPackage + "]");
6473 }
6474 } finally {
6475 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006476 }
6477 }
6478
6479 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006480 * Return the application ID for the app type.
6481 *
6482 * @param subId the subscription ID that this request applies to.
6483 * @param appType the uicc app type.
6484 * @return Application ID for specificied app type, or null if no uicc.
6485 */
6486 @Override
6487 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006488 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006489 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490
6491 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006492 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006493 if (phone == null) {
6494 return null;
6495 }
6496 String aid = null;
6497 try {
6498 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6499 .getApplicationByType(appType).getAid();
6500 } catch (Exception e) {
6501 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6502 }
6503 return aid;
6504 } finally {
6505 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006506 }
Youhan Wange64578a2016-05-02 15:32:42 -07006507 }
6508
Youhan Wang4001d252016-05-11 10:29:41 -07006509 /**
6510 * Return the Electronic Serial Number.
6511 *
6512 * @param subId the subscription ID that this request applies to.
6513 * @return ESN or null if error.
6514 */
6515 @Override
6516 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006517 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006518 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006519
6520 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006521 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006522 if (phone == null) {
6523 return null;
6524 }
6525 String esn = null;
6526 try {
6527 esn = phone.getEsn();
6528 } catch (Exception e) {
6529 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6530 }
6531 return esn;
6532 } finally {
6533 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006534 }
Youhan Wang4001d252016-05-11 10:29:41 -07006535 }
6536
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006537 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006538 * Return the Preferred Roaming List Version.
6539 *
6540 * @param subId the subscription ID that this request applies to.
6541 * @return PRLVersion or null if error.
6542 */
6543 @Override
6544 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006545 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006546 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006547
6548 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006549 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550 if (phone == null) {
6551 return null;
6552 }
6553 String cdmaPrlVersion = null;
6554 try {
6555 cdmaPrlVersion = phone.getCdmaPrlVersion();
6556 } catch (Exception e) {
6557 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6558 }
6559 return cdmaPrlVersion;
6560 } finally {
6561 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006562 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006563 }
6564
6565 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006566 * Get snapshot of Telephony histograms
6567 * @return List of Telephony histograms
6568 * @hide
6569 */
6570 @Override
6571 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6573 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574
6575 final long identity = Binder.clearCallingIdentity();
6576 try {
6577 return RIL.getTelephonyRILTimingHistograms();
6578 } finally {
6579 Binder.restoreCallingIdentity(identity);
6580 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006581 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006582
6583 /**
6584 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006585 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6586 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006587 * Require system privileges. In the future we may add this to carrier APIs.
6588 *
Michele Berionne482f8202018-11-27 18:57:59 -08006589 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006590 */
6591 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006592 @TelephonyManager.SetCarrierRestrictionResult
6593 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006594 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006595 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006596
Michele Berionne482f8202018-11-27 18:57:59 -08006597 if (carrierRestrictionRules == null) {
6598 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006599 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601 final long identity = Binder.clearCallingIdentity();
6602 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006603 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006604 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605 } finally {
6606 Binder.restoreCallingIdentity(identity);
6607 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006608 }
6609
6610 /**
6611 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006612 * Get the allowed carrier list and the excluded carrier list, including the priority between
6613 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006614 * Require system privileges. In the future we may add this to carrier APIs.
6615 *
Michele Berionne482f8202018-11-27 18:57:59 -08006616 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006617 */
6618 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006619 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006620 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006621 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622
6623 final long identity = Binder.clearCallingIdentity();
6624 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006625 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6626 if (response instanceof CarrierRestrictionRules) {
6627 return (CarrierRestrictionRules) response;
6628 }
6629 // Response is an Exception of some kind,
6630 // which is signalled to the user as a NULL retval
6631 return null;
6632 } catch (Exception e) {
6633 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6634 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006635 } finally {
6636 Binder.restoreCallingIdentity(identity);
6637 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006638 }
6639
fionaxu59545b42016-05-25 15:53:37 -07006640 /**
6641 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6642 * @param subId the subscription ID that this action applies to.
6643 * @param enabled control enable or disable metered apns.
6644 * {@hide}
6645 */
6646 @Override
6647 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6648 enforceModifyPermission();
6649 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650
6651 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006652 if (phone == null) {
6653 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6654 return;
6655 }
6656 try {
6657 phone.carrierActionSetMeteredApnsEnabled(enabled);
6658 } catch (Exception e) {
6659 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006660 } finally {
6661 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006662 }
6663 }
6664
6665 /**
6666 * Action set from carrier signalling broadcast receivers to enable/disable radio
6667 * @param subId the subscription ID that this action applies to.
6668 * @param enabled control enable or disable radio.
6669 * {@hide}
6670 */
6671 @Override
6672 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6673 enforceModifyPermission();
6674 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006675
6676 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006677 if (phone == null) {
6678 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6679 return;
6680 }
6681 try {
6682 phone.carrierActionSetRadioEnabled(enabled);
6683 } catch (Exception e) {
6684 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685 } finally {
6686 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006687 }
6688 }
6689
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006690 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006691 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6692 * network status based on which carrier apps could apply actions accordingly,
6693 * enable/disable default url handler for example.
6694 *
6695 * @param subId the subscription ID that this action applies to.
6696 * @param report control start/stop reporting the default network status.
6697 * {@hide}
6698 */
6699 @Override
6700 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6701 enforceModifyPermission();
6702 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703
6704 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006705 if (phone == null) {
6706 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6707 return;
6708 }
6709 try {
6710 phone.carrierActionReportDefaultNetworkStatus(report);
6711 } catch (Exception e) {
6712 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713 } finally {
6714 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006715 }
6716 }
6717
6718 /**
fionaxud9622282017-07-17 17:51:30 -07006719 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6720 * @param subId the subscription ID that this action applies to.
6721 * {@hide}
6722 */
6723 @Override
6724 public void carrierActionResetAll(int subId) {
6725 enforceModifyPermission();
6726 final Phone phone = getPhone(subId);
6727 if (phone == null) {
6728 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6729 return;
6730 }
6731 try {
6732 phone.carrierActionResetAll();
6733 } catch (Exception e) {
6734 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6735 }
6736 }
6737
6738 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006739 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6740 * bug report is being generated.
6741 */
6742 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006743 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006744 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6745 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006746 writer.println("Permission Denial: can't dump Phone from pid="
6747 + Binder.getCallingPid()
6748 + ", uid=" + Binder.getCallingUid()
6749 + "without permission "
6750 + android.Manifest.permission.DUMP);
6751 return;
6752 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006753 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006754 }
Jack Yueb89b242016-06-22 13:27:47 -07006755
Brad Ebingerdac2f002018-04-03 15:17:52 -07006756 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006757 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6758 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6759 @NonNull String[] args) {
6760 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6761 this, in.getFileDescriptor(), out.getFileDescriptor(),
6762 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006763 }
6764
Jack Yueb89b242016-06-22 13:27:47 -07006765 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006766 * Get aggregated video call data usage since boot.
6767 *
6768 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6769 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006770 * {@hide}
6771 */
6772 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006773 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006774 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6775 null);
6776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006777 final long identity = Binder.clearCallingIdentity();
6778 try {
6779 // NetworkStatsService keeps tracking the active network interface and identity. It
6780 // records the delta with the corresponding network identity.
6781 // We just return the total video call data usage snapshot since boot.
6782 Phone phone = getPhone(subId);
6783 if (phone != null) {
6784 return phone.getVtDataUsage(perUidStats);
6785 }
6786 return null;
6787 } finally {
6788 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006789 }
Jack Yueb89b242016-06-22 13:27:47 -07006790 }
Jack Yu75ab2952016-07-08 14:29:33 -07006791
6792 /**
6793 * Policy control of data connection. Usually used when data limit is passed.
6794 * @param enabled True if enabling the data, otherwise disabling.
6795 * @param subId Subscription index
6796 * {@hide}
6797 */
6798 @Override
6799 public void setPolicyDataEnabled(boolean enabled, int subId) {
6800 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801
6802 final long identity = Binder.clearCallingIdentity();
6803 try {
6804 Phone phone = getPhone(subId);
6805 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006806 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006807 }
6808 } finally {
6809 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006810 }
6811 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006812
6813 /**
6814 * Get Client request stats
6815 * @return List of Client Request Stats
6816 * @hide
6817 */
6818 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006819 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6820 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006821 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006822 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006823 return null;
6824 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006825 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006827 final long identity = Binder.clearCallingIdentity();
6828 try {
6829 if (phone != null) {
6830 return phone.getClientRequestStats();
6831 }
6832
6833 return null;
6834 } finally {
6835 Binder.restoreCallingIdentity(identity);
6836 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006837 }
6838
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006839 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006840 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006841 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006842 }
Jack Yueb4124c2017-02-16 15:32:43 -08006843
6844 /**
Grace Chen70990072017-03-24 17:21:30 -07006845 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006846 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006847 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006848 * @param state State of SIM (power down, power up, pass through)
6849 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6850 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6851 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006852 *
6853 **/
6854 @Override
Grace Chen70990072017-03-24 17:21:30 -07006855 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006856 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006857 Phone phone = PhoneFactory.getPhone(slotIndex);
6858
vagdeviaf9a5b92018-08-15 16:01:53 -07006859 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861 final long identity = Binder.clearCallingIdentity();
6862 try {
6863 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006864 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865 }
6866 } finally {
6867 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006868 }
6869 }
Shuo Qiandd210312017-04-12 22:11:33 +00006870
Tyler Gunn65d45c22017-06-05 11:22:26 -07006871 private boolean isUssdApiAllowed(int subId) {
6872 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006873 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006874 if (configManager == null) {
6875 return false;
6876 }
6877 PersistableBundle pb = configManager.getConfigForSubId(subId);
6878 if (pb == null) {
6879 return false;
6880 }
6881 return pb.getBoolean(
6882 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6883 }
6884
Shuo Qiandd210312017-04-12 22:11:33 +00006885 /**
6886 * Check if phone is in emergency callback mode
6887 * @return true if phone is in emergency callback mode
6888 * @param subId sub id
6889 */
goneil9c5f4872017-12-05 14:07:56 -08006890 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006891 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006892 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006893 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006894
6895 final long identity = Binder.clearCallingIdentity();
6896 try {
6897 if (phone != null) {
6898 return phone.isInEcm();
6899 } else {
6900 return false;
6901 }
6902 } finally {
6903 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006904 }
6905 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006906
6907 /**
6908 * Get the current signal strength information for the given subscription.
6909 * Because this information is not updated when the device is in a low power state
6910 * it should not be relied-upon to be current.
6911 * @param subId Subscription index
6912 * @return the most recent cached signal strength info from the modem
6913 */
6914 @Override
6915 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006916 final long identity = Binder.clearCallingIdentity();
6917 try {
6918 Phone p = getPhone(subId);
6919 if (p == null) {
6920 return null;
6921 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006923 return p.getSignalStrength();
6924 } finally {
6925 Binder.restoreCallingIdentity(identity);
6926 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006927 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006928
Pengquan Meng77b7f132018-08-22 14:49:57 -07006929 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006930 * Get the current modem radio state for the given slot.
6931 * @param slotIndex slot index.
6932 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006933 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006934 * @return the current radio power state from the modem
6935 */
6936 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006937 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006938 Phone phone = PhoneFactory.getPhone(slotIndex);
6939 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6941 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006942 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6943 }
6944
6945 final long identity = Binder.clearCallingIdentity();
6946 try {
6947 return phone.getRadioPowerState();
6948 } finally {
6949 Binder.restoreCallingIdentity(identity);
6950 }
6951 }
6952 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6953 }
6954
6955 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006956 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6957 *
6958 * <p>Requires one of the following permissions:
6959 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6960 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6961 * privileges.
6962 *
6963 * @param subId subscription id
6964 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6965 * {@code false}.
6966 */
6967 @Override
6968 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006969 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6970 null /* message */);
6971
Pengquan Menga1bb6272018-09-06 09:59:22 -07006972 boolean isEnabled = false;
6973 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006974 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006975 Phone phone = getPhone(subId);
6976 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006977 } catch (Exception e) {
6978 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6979 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006980 } finally {
6981 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006982 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006983 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006984 }
6985
6986
6987 /**
6988 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6989 *
6990 * <p> Requires permission:
6991 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6992 * privileges.
6993 *
6994 * @param subId subscription id
6995 * @param isEnabled {@code true} means enable, {@code false} means disable.
6996 */
6997 @Override
6998 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7000 mApp, subId, "setDataRoamingEnabled");
7001
Pengquan Menga1bb6272018-09-06 09:59:22 -07007002 final long identity = Binder.clearCallingIdentity();
7003 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007004 Phone phone = getPhone(subId);
7005 if (phone != null) {
7006 phone.setDataRoamingEnabled(isEnabled);
7007 }
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007010 }
7011 }
7012
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007013 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007014 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007015 TelephonyPermissions
7016 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007017 mApp, subId, "isManualNetworkSelectionAllowed");
7018
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007019 boolean isAllowed = true;
7020 final long identity = Binder.clearCallingIdentity();
7021 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007022 Phone phone = getPhone(subId);
7023 if (phone != null) {
7024 isAllowed = phone.isCspPlmnEnabled();
7025 }
7026 } finally {
7027 Binder.restoreCallingIdentity(identity);
7028 }
7029 return isAllowed;
7030 }
7031
7032 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007033 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007034 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007035 try {
7036 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007037 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007038 } catch (SecurityException e) {
7039 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7040 // has carrier privileges on an active UICC
7041 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7042 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007043 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007044 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007045 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007046
7047 final long identity = Binder.clearCallingIdentity();
7048 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007049 UiccController uiccController = UiccController.getInstance();
7050 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007051 if (hasReadPermission) {
7052 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007053 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007054
7055 // Remove private info if the caller doesn't have access
7056 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7057 for (UiccCardInfo cardInfo : cardInfos) {
7058 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7059 // is available
7060 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7061 if (card == null || card.getUiccProfile() == null) {
7062 // assume no access if the card or profile is unavailable
7063 filteredInfos.add(cardInfo.getUnprivileged());
7064 continue;
7065 }
7066 UiccProfile profile = card.getUiccProfile();
7067 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7068 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7069 filteredInfos.add(cardInfo);
7070 } else {
7071 filteredInfos.add(cardInfo.getUnprivileged());
7072 }
7073 }
7074 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007075 } finally {
7076 Binder.restoreCallingIdentity(identity);
7077 }
7078 }
7079
7080 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007081 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007082 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007083
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084 final long identity = Binder.clearCallingIdentity();
7085 try {
7086 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7087 if (slots == null) {
7088 Rlog.i(LOG_TAG, "slots is null.");
7089 return null;
7090 }
7091
7092 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7093 for (int i = 0; i < slots.length; i++) {
7094 UiccSlot slot = slots[i];
7095 if (slot == null) {
7096 continue;
7097 }
7098
Jordan Liu7be7e652019-05-06 18:55:02 +00007099 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100 UiccCard card = slot.getUiccCard();
7101 if (card != null) {
7102 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007103 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007104 cardId = slot.getEid();
7105 if (TextUtils.isEmpty(cardId)) {
7106 cardId = slot.getIccId();
7107 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108 }
7109
Jordan Liu857451f2019-05-09 16:35:35 -07007110 if (cardId != null) {
7111 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7112 // if cardId is an EID, it's all digits so this is fine
7113 cardId = IccUtils.stripTrailingFs(cardId);
7114 }
7115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116 int cardState = 0;
7117 switch (slot.getCardState()) {
7118 case CARDSTATE_ABSENT:
7119 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7120 break;
7121 case CARDSTATE_PRESENT:
7122 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7123 break;
7124 case CARDSTATE_ERROR:
7125 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7126 break;
7127 case CARDSTATE_RESTRICTED:
7128 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7129 break;
7130 default:
7131 break;
7132
7133 }
7134
7135 infos[i] = new UiccSlotInfo(
7136 slot.isActive(),
7137 slot.isEuicc(),
7138 cardId,
7139 cardState,
7140 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007141 slot.isExtendedApduSupported(),
7142 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007143 }
7144 return infos;
7145 } finally {
7146 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007147 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007148 }
7149
7150 @Override
7151 public boolean switchSlots(int[] physicalSlots) {
7152 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007153
7154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7157 } finally {
7158 Binder.restoreCallingIdentity(identity);
7159 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007160 }
Jack Yu4c988042018-02-27 15:30:01 -08007161
7162 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007163 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007164 final long identity = Binder.clearCallingIdentity();
7165 try {
7166 return UiccController.getInstance().getCardIdForDefaultEuicc();
7167 } finally {
7168 Binder.restoreCallingIdentity(identity);
7169 }
7170 }
7171
7172 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007173 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7174 enforceModifyPermission();
7175 final Phone phone = getPhone(subId);
7176 if (phone == null) {
7177 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7178 return;
7179 }
7180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 final long identity = Binder.clearCallingIdentity();
7182 try {
7183 phone.setRadioIndicationUpdateMode(filters, mode);
7184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
Jack Yu4c988042018-02-27 15:30:01 -08007187 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007188
7189 /**
goneil47ffb6e2018-04-06 15:40:58 -07007190 * A test API to reload the UICC profile.
7191 *
7192 * <p>Requires that the calling app has permission
7193 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7194 * @hide
7195 */
7196 @Override
7197 public void refreshUiccProfile(int subId) {
7198 enforceModifyPermission();
7199
7200 final long identity = Binder.clearCallingIdentity();
7201 try {
7202 Phone phone = getPhone(subId);
7203 if (phone == null) {
7204 return;
7205 }
7206 UiccCard uiccCard = phone.getUiccCard();
7207 if (uiccCard == null) {
7208 return;
7209 }
7210 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7211 if (uiccProfile == null) {
7212 return;
7213 }
7214 uiccProfile.refresh();
7215 } finally {
7216 Binder.restoreCallingIdentity(identity);
7217 }
7218 }
7219
7220 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007221 * Returns false if the mobile data is disabled by default, otherwise return true.
7222 */
7223 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007224 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007225 }
7226
7227 /**
7228 * Returns true if the data roaming is enabled by default, i.e the system property
7229 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7230 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7231 */
7232 private boolean getDefaultDataRoamingEnabled(int subId) {
7233 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007234 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007235 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007236 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7237 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7238 return isDataRoamingEnabled;
7239 }
7240
7241 /**
7242 * Returns the default network type for the given {@code subId}, if the default network type is
7243 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7244 */
7245 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007246 List<Integer> list = TelephonyProperties.default_network();
7247 int phoneId = mSubscriptionController.getPhoneId(subId);
7248 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7249 return list.get(phoneId);
7250 }
7251 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007252 }
fionaxua13278b2018-03-21 00:08:13 -07007253
7254 @Override
7255 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007256 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007257 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007258
7259 final long identity = Binder.clearCallingIdentity();
7260 try {
7261 final Phone phone = getPhone(subId);
7262 if (phone == null) {
7263 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7264 return;
7265 }
chen xueaba88a2019-03-15 13:15:10 -07007266 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7267 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007268 } finally {
7269 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007270 }
fionaxua13278b2018-03-21 00:08:13 -07007271 }
7272
7273 @Override
7274 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007275 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007276
7277 final long identity = Binder.clearCallingIdentity();
7278 try {
7279 final Phone phone = getPhone(subId);
7280 if (phone == null) {
7281 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7282 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7283 }
7284 return phone.getCarrierIdListVersion();
7285 } finally {
7286 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007287 }
fionaxua13278b2018-03-21 00:08:13 -07007288 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007289
7290 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007291 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7292 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007294 mApp, subId, callingPackage, callingFeatureId,
7295 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007296 return -1;
7297 }
7298
7299 final long identity = Binder.clearCallingIdentity();
7300 try {
7301 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7302 } finally {
7303 Binder.restoreCallingIdentity(identity);
7304 }
7305 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007306
7307 @Override
7308 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007309 TelephonyPermissions
7310 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007311 mApp, subId, "getCdmaRoamingMode");
7312
7313 final long identity = Binder.clearCallingIdentity();
7314 try {
7315 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7316 } finally {
7317 Binder.restoreCallingIdentity(identity);
7318 }
7319 }
7320
7321 @Override
7322 public boolean setCdmaRoamingMode(int subId, int mode) {
7323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7324 mApp, subId, "setCdmaRoamingMode");
7325
7326 final long identity = Binder.clearCallingIdentity();
7327 try {
7328 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7329 } finally {
7330 Binder.restoreCallingIdentity(identity);
7331 }
7332 }
7333
7334 @Override
7335 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7337 mApp, subId, "setCdmaSubscriptionMode");
7338
7339 final long identity = Binder.clearCallingIdentity();
7340 try {
7341 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7342 } finally {
7343 Binder.restoreCallingIdentity(identity);
7344 }
7345 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007346
sqianc5eccab2018-10-19 18:46:41 -07007347 @Override
sqian8c685422019-02-22 15:55:18 -08007348 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007349 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007350 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007351 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7352 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007353 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7354 }
7355 final long identity = Binder.clearCallingIdentity();
7356 try {
sqian854d44b2018-12-12 16:48:18 -08007357 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7358 for (Phone phone: PhoneFactory.getPhones()) {
7359 if (phone.getEmergencyNumberTracker() != null
7360 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7361 emergencyNumberListInternal.put(
7362 phone.getSubId(),
7363 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7364 }
sqian11b7a0e2018-12-05 18:48:28 -08007365 }
sqian854d44b2018-12-12 16:48:18 -08007366 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007367 } finally {
7368 Binder.restoreCallingIdentity(identity);
7369 }
sqianc5eccab2018-10-19 18:46:41 -07007370 }
7371
7372 @Override
sqian8c685422019-02-22 15:55:18 -08007373 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007374 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007375 if (!exactMatch) {
7376 TelephonyPermissions
7377 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007378 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007379 }
7380 final long identity = Binder.clearCallingIdentity();
7381 try {
sqian854d44b2018-12-12 16:48:18 -08007382 for (Phone phone: PhoneFactory.getPhones()) {
7383 if (phone.getEmergencyNumberTracker() != null
7384 && phone.getEmergencyNumberTracker() != null) {
7385 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7386 number, exactMatch)) {
7387 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007388 }
7389 }
sqian11b7a0e2018-12-05 18:48:28 -08007390 }
7391 return false;
7392 } finally {
7393 Binder.restoreCallingIdentity(identity);
7394 }
7395 }
7396
sqianf4ca7ed2019-01-15 18:32:07 -08007397 /**
7398 * Update emergency number list for test mode.
7399 */
7400 @Override
7401 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7402 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7403 "updateEmergencyNumberListTestMode");
7404
7405 final long identity = Binder.clearCallingIdentity();
7406 try {
7407 for (Phone phone: PhoneFactory.getPhones()) {
7408 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7409 if (tracker != null) {
7410 tracker.executeEmergencyNumberTestModeCommand(action, num);
7411 }
7412 }
7413 } finally {
7414 Binder.restoreCallingIdentity(identity);
7415 }
7416 }
7417
7418 /**
7419 * Get the full emergency number list for test mode.
7420 */
7421 @Override
7422 public List<String> getEmergencyNumberListTestMode() {
7423 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7424 "getEmergencyNumberListTestMode");
7425
7426 final long identity = Binder.clearCallingIdentity();
7427 try {
7428 Set<String> emergencyNumbers = new HashSet<>();
7429 for (Phone phone: PhoneFactory.getPhones()) {
7430 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7431 if (tracker != null) {
7432 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7433 emergencyNumbers.add(num.getNumber());
7434 }
7435 }
7436 }
7437 return new ArrayList<>(emergencyNumbers);
7438 } finally {
7439 Binder.restoreCallingIdentity(identity);
7440 }
7441 }
7442
chen xud6b45bd2018-10-30 22:27:10 -07007443 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007444 public int getEmergencyNumberDbVersion(int subId) {
7445 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7446
7447 final long identity = Binder.clearCallingIdentity();
7448 try {
7449 final Phone phone = getPhone(subId);
7450 if (phone == null) {
7451 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7452 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7453 }
7454 return phone.getEmergencyNumberDbVersion();
7455 } finally {
7456 Binder.restoreCallingIdentity(identity);
7457 }
7458 }
7459
7460 @Override
7461 public void notifyOtaEmergencyNumberDbInstalled() {
7462 enforceModifyPermission();
7463
7464 final long identity = Binder.clearCallingIdentity();
7465 try {
7466 for (Phone phone: PhoneFactory.getPhones()) {
7467 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7468 if (tracker != null) {
7469 tracker.updateOtaEmergencyNumberDatabase();
7470 }
7471 }
7472 } finally {
7473 Binder.restoreCallingIdentity(identity);
7474 }
7475 }
7476
7477 @Override
7478 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7479 enforceActiveEmergencySessionPermission();
7480
7481 final long identity = Binder.clearCallingIdentity();
7482 try {
7483 for (Phone phone: PhoneFactory.getPhones()) {
7484 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7485 if (tracker != null) {
7486 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7487 }
7488 }
7489 } finally {
7490 Binder.restoreCallingIdentity(identity);
7491 }
7492 }
7493
7494 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007495 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7496 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7497 Phone phone = getPhone(subId);
7498 if (phone == null) {
7499 return null;
7500 }
7501 final long identity = Binder.clearCallingIdentity();
7502 try {
7503 UiccProfile profile = UiccController.getInstance()
7504 .getUiccProfileForPhone(phone.getPhoneId());
7505 if (profile != null) {
7506 return profile.getCertsFromCarrierPrivilegeAccessRules();
7507 }
7508 } finally {
7509 Binder.restoreCallingIdentity(identity);
7510 }
7511 return null;
7512 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007513
7514 /**
7515 * Enable or disable a modem stack.
7516 */
7517 @Override
7518 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7519 enforceModifyPermission();
7520
7521 final long identity = Binder.clearCallingIdentity();
7522 try {
7523 Phone phone = PhoneFactory.getPhone(slotIndex);
7524 if (phone == null) {
7525 return false;
7526 } else {
7527 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7528 }
7529 } finally {
7530 Binder.restoreCallingIdentity(identity);
7531 }
7532 }
Michelecea4cf22018-12-21 15:00:11 -08007533
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007534 /**
7535 * Whether a modem stack is enabled or not.
7536 */
7537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007538 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7539 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007540 Phone phone = PhoneFactory.getPhone(slotIndex);
7541 if (phone == null) return false;
7542
7543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007544 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7545 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007546 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7547 }
7548
7549 final long identity = Binder.clearCallingIdentity();
7550 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007551 try {
7552 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7553 } catch (NoSuchElementException ex) {
7554 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7555 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007556 } finally {
7557 Binder.restoreCallingIdentity(identity);
7558 }
7559 }
7560
Michelecea4cf22018-12-21 15:00:11 -08007561 @Override
Michele0ea7d782019-03-19 14:58:42 -07007562 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007563 enforceModifyPermission();
7564
7565 final long identity = Binder.clearCallingIdentity();
7566 try {
7567 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007568 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007569 .commit();
7570 } finally {
7571 Binder.restoreCallingIdentity(identity);
7572 }
7573 }
7574
7575 @Override
Michele0ea7d782019-03-19 14:58:42 -07007576 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007577 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007578 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007579 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7580 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007581 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007582 }
Michelecea4cf22018-12-21 15:00:11 -08007583
7584 final long identity = Binder.clearCallingIdentity();
7585 try {
Michele0ea7d782019-03-19 14:58:42 -07007586 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007587 } finally {
7588 Binder.restoreCallingIdentity(identity);
7589 }
7590 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007591
Michele0ea7d782019-03-19 14:58:42 -07007592 @TelephonyManager.IsMultiSimSupportedResult
7593 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007594 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7595 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7596 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007597 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7598 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007599 }
7600 // Check if the hardware supports multisim functionality. If usage of multisim is not
7601 // supported by the modem, indicate that it is restricted.
7602 PhoneCapability staticCapability =
7603 mPhoneConfigurationManager.getStaticPhoneCapability();
7604 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007605 loge("isMultiSimSupportedInternal: no static configuration available");
7606 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007607 }
7608 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007609 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7610 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007611 }
7612 // Check if support of multiple SIMs is restricted by carrier
7613 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007614 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007615 }
7616
Michele0ea7d782019-03-19 14:58:42 -07007617 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007618 }
7619
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007620 /**
7621 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007622 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7623 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7624 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007625 * @param numOfSims number of active sims we want to switch to
7626 */
7627 @Override
7628 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007629 if (numOfSims == 1) {
7630 enforceModifyPermission();
7631 } else {
7632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7633 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7634 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007635 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007636
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007637 try {
Michele30b57b22019-03-01 12:01:14 -08007638 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007639 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007640 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7641 return;
7642 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007643 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7644 } finally {
7645 Binder.restoreCallingIdentity(identity);
7646 }
7647 }
7648
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007649 @Override
7650 public boolean isApplicationOnUicc(int subId, int appType) {
7651 enforceReadPrivilegedPermission("isApplicationOnUicc");
7652 Phone phone = getPhone(subId);
7653 if (phone == null) {
7654 return false;
7655 }
7656 final long identity = Binder.clearCallingIdentity();
7657 try {
7658 UiccCard uiccCard = phone.getUiccCard();
7659 if (uiccCard == null) {
7660 return false;
7661 }
7662 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7663 if (uiccProfile == null) {
7664 return false;
7665 }
7666 if (TelephonyManager.APPTYPE_SIM <= appType
7667 && appType <= TelephonyManager.APPTYPE_ISIM) {
7668 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7669 }
7670 return false;
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
7673 }
7674 }
7675
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007676 /**
chen xub4baa772019-04-03 10:23:41 -07007677 * Get whether making changes to modem configurations will trigger reboot.
7678 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007679 */
7680 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007681 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7682 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007683 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007684 mApp, subId, callingPackage, callingFeatureId,
7685 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007686 return false;
7687 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007688 final long identity = Binder.clearCallingIdentity();
7689 try {
7690 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7691 } finally {
7692 Binder.restoreCallingIdentity(identity);
7693 }
7694 }
7695
Nathan Harold29f5f052019-02-15 13:41:57 -08007696 private void updateModemStateMetrics() {
7697 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7698 // TODO: check the state for each modem if the api is ready.
7699 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7700 }
7701
Pengquan Meng3889a572019-01-23 11:16:29 -08007702 @Override
7703 public int[] getSlotsMapping() {
7704 enforceReadPrivilegedPermission("getSlotsMapping");
7705
7706 final long identity = Binder.clearCallingIdentity();
7707 try {
7708 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7709 // All logical slots should have a mapping to a physical slot.
7710 int[] logicalSlotsMapping = new int[phoneCount];
7711 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7712 for (int i = 0; i < slotInfos.length; i++) {
7713 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7714 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7715 }
7716 }
7717 return logicalSlotsMapping;
7718 } finally {
7719 Binder.restoreCallingIdentity(identity);
7720 }
7721 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007722
7723 /**
7724 * Get the IRadio HAL Version
7725 */
7726 @Override
7727 public int getRadioHalVersion() {
7728 Phone phone = getDefaultPhone();
7729 if (phone == null) return -1;
7730 HalVersion hv = phone.getHalVersion();
7731 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7732 return hv.major * 100 + hv.minor;
7733 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007734
7735 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007736 * Get the current calling package name.
7737 * @return the current calling package name
7738 */
7739 @Override
7740 public String getCurrentPackageName() {
7741 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
7742 }
7743
7744 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007745 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7746 * corresponding network requests on a subId.
7747 *
7748 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007749 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007750 * 2) APN is un-metered for this subscription, or
7751 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007752 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007753 *
7754 * @return whether data is allowed for a apn type.
7755 *
7756 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007757 */
7758 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007759 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007760 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7761 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007762
7763 // Now that all security checks passes, perform the operation as ourselves.
7764 final long identity = Binder.clearCallingIdentity();
7765 try {
7766 Phone phone = getPhone(subId);
7767 if (phone == null) return false;
7768
Jack Yu41407ee2019-05-13 16:54:09 -07007769 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007770 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7771 } finally {
7772 Binder.restoreCallingIdentity(identity);
7773 }
7774 }
7775
7776 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007777 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007778 enforceReadPrivilegedPermission("isApnMetered");
7779
7780 // Now that all security checks passes, perform the operation as ourselves.
7781 final long identity = Binder.clearCallingIdentity();
7782 try {
7783 Phone phone = getPhone(subId);
7784 if (phone == null) return true; // By default return true.
7785
Jack Yu41407ee2019-05-13 16:54:09 -07007786 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007787 } finally {
7788 Binder.restoreCallingIdentity(identity);
7789 }
7790 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007791
7792 @Override
changbetty7157e9e2019-12-06 18:16:37 +08007793 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7794 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7795 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7796 if (iccRecords == null) {
7797 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7798 return false;
7799 }
7800 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7801 }
7802
7803 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007804 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007805 if (callingPackage == null) {
7806 callingPackage = getCurrentPackageName();
7807 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007808 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7809 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7810 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7811 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7812 }
7813 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7814 Intent intent = new Intent();
7815 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7816 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7817 // Bring up choose default SMS subscription dialog right now
7818 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7819 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7820 mApp.startActivity(intent);
7821 }
chen xud5ca2d52019-05-28 15:20:57 -07007822
7823 @Override
7824 public String getMmsUAProfUrl(int subId) {
7825 //TODO investigate if this API should require proper permission check in R b/133791609
7826 final long identity = Binder.clearCallingIdentity();
7827 try {
7828 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7829 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7830 } finally {
7831 Binder.restoreCallingIdentity(identity);
7832 }
7833 }
7834
7835 @Override
7836 public String getMmsUserAgent(int subId) {
7837 //TODO investigate if this API should require proper permission check in R b/133791609
7838 final long identity = Binder.clearCallingIdentity();
7839 try {
7840 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7841 .getString(com.android.internal.R.string.config_mms_user_agent);
7842 } finally {
7843 Binder.restoreCallingIdentity(identity);
7844 }
7845 }
Jack Yub07d4972019-05-28 16:12:25 -07007846
7847 @Override
7848 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7849 enforceModifyPermission();
7850
7851 // Now that all security checks passes, perform the operation as ourselves.
7852 final long identity = Binder.clearCallingIdentity();
7853 try {
7854 Phone phone = getPhone(subId);
7855 if (phone == null) return false;
7856
7857 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7858 } finally {
7859 Binder.restoreCallingIdentity(identity);
7860 }
7861 }
7862
7863 @Override
7864 public boolean isDataAllowedInVoiceCall(int subId) {
7865 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7866
7867 // Now that all security checks passes, perform the operation as ourselves.
7868 final long identity = Binder.clearCallingIdentity();
7869 try {
7870 Phone phone = getPhone(subId);
7871 if (phone == null) return false;
7872
7873 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7874 } finally {
7875 Binder.restoreCallingIdentity(identity);
7876 }
7877 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007878
changbettyd5c246e2019-12-24 15:40:37 +08007879 @Override
7880 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
7881 enforceModifyPermission();
7882
7883 // Now that all security checks passes, perform the operation as ourselves.
7884 final long identity = Binder.clearCallingIdentity();
7885 try {
7886 Phone phone = getPhone(subId);
7887 if (phone == null) return false;
7888
7889 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
7890 } finally {
7891 Binder.restoreCallingIdentity(identity);
7892 }
7893 }
7894
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007895 /**
7896 * Updates whether conference event pacakge handling is enabled.
7897 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7898 * otherwise.
7899 */
7900 @Override
7901 public void setCepEnabled(boolean isCepEnabled) {
7902 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7903
7904 final long identity = Binder.clearCallingIdentity();
7905 try {
7906 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7907 for (Phone phone : PhoneFactory.getPhones()) {
7908 Phone defaultPhone = phone.getImsPhone();
7909 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7910 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7911 ImsPhoneCallTracker imsPhoneCallTracker =
7912 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7913 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7914 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7915 + imsPhone.getMsisdn());
7916 }
7917 }
7918 } finally {
7919 Binder.restoreCallingIdentity(identity);
7920 }
7921 }
allenwtsu46dcc572020-01-08 18:24:03 +08007922
7923 /**
7924 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
7925 *
7926 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
7927 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
7928 * before being read.
7929 */
7930 @Override
7931 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
7932 isCompressed) {
7933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7934 mApp, subId, "notifyRcsAutoConfigurationReceived");
7935 try {
7936 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
7937 if (configBinder == null) {
7938 Rlog.e(LOG_TAG, "null result for getImsConfig");
7939 } else {
7940 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
7941 }
7942 } catch (RemoteException e) {
7943 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
7944 }
7945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007946}