blob: fe45a6c7ab3070eff2906afc32469a4b676ceff6 [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) {
Sarah Chin790d2922020-01-16 12:17:23 -08004040 try {
4041 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4042 } catch (SecurityException e) {
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 {
5074 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
5075 Boolean success = (Boolean) sendRequest(
5076 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5077 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5078 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005079 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5081 }
5082 return success;
5083 } finally {
5084 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005085 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005086 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005087
5088 /**
Miaoa84611c2019-03-15 09:21:10 +08005089 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005090 *
Miaoa84611c2019-03-15 09:21:10 +08005091 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005092 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005093 * @hide
5094 */
5095 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005096 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005097 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005099 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005100 try {
Miaoa84611c2019-03-15 09:21:10 +08005101 if (phone != null) {
5102 return phone.hasMatchedTetherApnSetting();
5103 } else {
5104 return false;
5105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106 } finally {
5107 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005108 }
Junda Liu475951f2014-11-07 16:45:03 -08005109 }
5110
5111 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005112 * Set mobile data enabled
5113 * Used by the user through settings etc to turn on/off mobile data
5114 *
5115 * @param enable {@code true} turn turn data on, else {@code false}
5116 */
5117 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005118 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5120 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121
5122 final long identity = Binder.clearCallingIdentity();
5123 try {
5124 int phoneId = mSubscriptionController.getPhoneId(subId);
5125 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5126 Phone phone = PhoneFactory.getPhone(phoneId);
5127 if (phone != null) {
5128 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005129 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005130 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005131 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132 }
5133 } finally {
5134 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005135 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005136 }
5137
5138 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005139 * Get the user enabled state of Mobile Data.
5140 *
5141 * TODO: remove and use isUserDataEnabled.
5142 * This can't be removed now because some vendor codes
5143 * calls through ITelephony directly while they should
5144 * use TelephonyManager.
5145 *
5146 * @return true on enabled
5147 */
5148 @Override
5149 public boolean getDataEnabled(int subId) {
5150 return isUserDataEnabled(subId);
5151 }
5152
5153 /**
5154 * Get whether mobile data is enabled per user setting.
5155 *
5156 * There are other factors deciding whether mobile data is actually enabled, but they are
5157 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005158 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005159 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005160 *
5161 * @return {@code true} if data is enabled else {@code false}
5162 */
5163 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005164 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005165 try {
5166 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5167 null);
5168 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005169 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5170 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005171 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172
5173 final long identity = Binder.clearCallingIdentity();
5174 try {
5175 int phoneId = mSubscriptionController.getPhoneId(subId);
5176 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5177 Phone phone = PhoneFactory.getPhone(phoneId);
5178 if (phone != null) {
5179 boolean retVal = phone.isUserDataEnabled();
5180 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5181 return retVal;
5182 } else {
5183 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5184 return false;
5185 }
5186 } finally {
5187 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005188 }
5189 }
5190
5191 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005192 * Checks if the device is capable of mobile data by considering whether whether the
5193 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5194 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005195 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005196 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005197 */
5198 @Override
5199 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005200 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201
5202 final long identity = Binder.clearCallingIdentity();
5203 try {
5204 int phoneId = mSubscriptionController.getPhoneId(subId);
5205 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5206 Phone phone = PhoneFactory.getPhone(phoneId);
5207 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005208 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005209 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5210 return retVal;
5211 } else {
5212 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5213 return false;
5214 }
5215 } finally {
5216 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005217 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005218 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005219
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005220 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5221 Phone phone) {
5222 //load access rules from carrier configs, and check those as well: b/139133814
5223 SubscriptionController subController = SubscriptionController.getInstance();
5224 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5225 || subController == null) return privilegeFromSim;
5226
5227 int uid = Binder.getCallingUid();
5228 PackageManager pkgMgr = phone.getContext().getPackageManager();
5229 String[] packages = pkgMgr.getPackagesForUid(uid);
5230
5231 final long identity = Binder.clearCallingIdentity();
5232 try {
5233 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5234 SubscriptionManager subManager = (SubscriptionManager)
5235 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5236 for (String pkg : packages) {
5237 if (subManager.canManageSubscription(subInfo, pkg)) {
5238 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5239 }
5240 }
5241 return privilegeFromSim;
5242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
5245 }
5246
5247 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5248 String pkgName) {
5249 //load access rules from carrier configs, and check those as well: b/139133814
5250 SubscriptionController subController = SubscriptionController.getInstance();
5251 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5252 || subController == null) return privilegeFromSim;
5253
5254 final long identity = Binder.clearCallingIdentity();
5255 try {
5256 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5257 SubscriptionManager subManager = (SubscriptionManager)
5258 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5259 return subManager.canManageSubscription(subInfo, pkgName)
5260 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5261 } finally {
5262 Binder.restoreCallingIdentity(identity);
5263 }
5264 }
5265
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005266 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005267 public int getCarrierPrivilegeStatus(int subId) {
5268 final Phone phone = getPhone(subId);
5269 if (phone == null) {
5270 loge("getCarrierPrivilegeStatus: Invalid subId");
5271 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5272 }
5273 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005274 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005275 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005276 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5277 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005278
5279 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5280 card.getCarrierPrivilegeStatusForCurrentTransaction(
5281 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005282 }
Junda Liu29340342014-07-10 15:23:27 -07005283
5284 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005285 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005286 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005287 final Phone phone = getPhone(subId);
5288 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005289 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005290 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5291 }
5292 UiccProfile profile =
5293 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5294 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005295 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005296 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5297 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005298 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005299 profile.getCarrierPrivilegeStatusForUid(
5300 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005301 }
5302
5303 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005304 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5305 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005306 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005307 }
5308
5309 int phoneId = SubscriptionManager.getPhoneId(subId);
5310 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005311 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005312 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005313 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5314 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005315 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5316 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5317 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005318 }
5319
5320 @Override
5321 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005322 if (TextUtils.isEmpty(pkgName))
5323 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005324 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5325 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5326 UiccCard card = UiccController.getInstance().getUiccCard(i);
5327 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005328 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005329 continue;
5330 }
5331
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005332 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5333 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5334 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005335 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5336 break;
5337 }
5338 }
5339
5340 return result;
Junda Liu29340342014-07-10 15:23:27 -07005341 }
Derek Tan89e89d42014-07-08 17:00:10 -07005342
5343 @Override
Junda Liue64de782015-04-16 17:19:16 -07005344 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5345 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5346 loge("phoneId " + phoneId + " is not valid.");
5347 return null;
5348 }
5349 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005350 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005351 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005352 return null ;
5353 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005354 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005355 }
5356
Amith Yamasani6e118872016-02-19 12:53:51 -08005357 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005358 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005359 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005360 List<String> privilegedPackages = new ArrayList<>();
5361 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005362 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5363 // has UICC in that slot.
5364 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005365 if (card.hasCarrierPrivilegeRules()) {
5366 if (packages == null) {
5367 // Only check packages in user 0 for now
5368 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005369 PackageManager.MATCH_DISABLED_COMPONENTS
5370 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005371 | PackageManager.GET_SIGNING_CERTIFICATES,
5372 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005373 }
5374 for (int p = packages.size() - 1; p >= 0; p--) {
5375 PackageInfo pkgInfo = packages.get(p);
5376 if (pkgInfo != null && pkgInfo.packageName != null
5377 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005378 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005379 privilegedPackages.add(pkgInfo.packageName);
5380 }
5381 }
5382 }
5383 }
5384 return privilegedPackages;
5385 }
5386
chen xuf7e9fe82019-05-09 19:31:02 -07005387 @Override
5388 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005389 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5390
5391 final long identity = Binder.clearCallingIdentity();
5392
chen xuf7e9fe82019-05-09 19:31:02 -07005393 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005394 try {
5395 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5396 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5397 }
5398 } finally {
5399 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005400 }
5401 return privilegedPackages;
5402 }
5403
Wink Savilleb564aae2014-10-23 10:18:09 -07005404 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005405 final Phone phone = getPhone(subId);
5406 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005407 if (card == null) {
5408 loge("getIccId: No UICC");
5409 return null;
5410 }
5411 String iccId = card.getIccId();
5412 if (TextUtils.isEmpty(iccId)) {
5413 loge("getIccId: ICC ID is null or empty.");
5414 return null;
5415 }
5416 return iccId;
5417 }
5418
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005419 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005420 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5421 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005422 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005423 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 final long identity = Binder.clearCallingIdentity();
5426 try {
5427 final String iccId = getIccId(subId);
5428 final Phone phone = getPhone(subId);
5429 if (phone == null) {
5430 return false;
5431 }
5432 final String subscriberId = phone.getSubscriberId();
5433
5434 if (DBG_MERGE) {
5435 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5436 + subscriberId + " to " + number);
5437 }
5438
5439 if (TextUtils.isEmpty(iccId)) {
5440 return false;
5441 }
5442
5443 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5444
5445 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5446 if (alphaTag == null) {
5447 editor.remove(alphaTagPrefKey);
5448 } else {
5449 editor.putString(alphaTagPrefKey, alphaTag);
5450 }
5451
5452 // Record both the line number and IMSI for this ICCID, since we need to
5453 // track all merged IMSIs based on line number
5454 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5455 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5456 if (number == null) {
5457 editor.remove(numberPrefKey);
5458 editor.remove(subscriberPrefKey);
5459 } else {
5460 editor.putString(numberPrefKey, number);
5461 editor.putString(subscriberPrefKey, subscriberId);
5462 }
5463
5464 editor.commit();
5465 return true;
5466 } finally {
5467 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005468 }
Derek Tan7226c842014-07-02 17:42:23 -07005469 }
5470
5471 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005472 public String getLine1NumberForDisplay(int subId, String callingPackage,
5473 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005474 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005476 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005477 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005478 return null;
5479 }
Derek Tan97ebb422014-09-05 16:55:38 -07005480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481 final long identity = Binder.clearCallingIdentity();
5482 try {
5483 String iccId = getIccId(subId);
5484 if (iccId != null) {
5485 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5486 if (DBG_MERGE) {
5487 log("getLine1NumberForDisplay returning "
5488 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5489 }
5490 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005491 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5493 return null;
5494 } finally {
5495 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005496 }
Derek Tan7226c842014-07-02 17:42:23 -07005497 }
5498
5499 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005500 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5501 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005503 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005504 return null;
5505 }
Derek Tan97ebb422014-09-05 16:55:38 -07005506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 String iccId = getIccId(subId);
5510 if (iccId != null) {
5511 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5512 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5513 }
5514 return null;
5515 } finally {
5516 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005517 }
Derek Tan7226c842014-07-02 17:42:23 -07005518 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005519
5520 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005521 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5522 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005523 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5524 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005525 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005526 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005527 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005528 return null;
5529 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005530
Jordan Liub49b04b2019-05-06 14:45:15 -07005531 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5532 // the process, where TelephonyManager was instantiated.
5533 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005534 final long identity = Binder.clearCallingIdentity();
5535 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005536 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005537 final TelephonyManager tele = TelephonyManager.from(context);
5538 final SubscriptionManager sub = SubscriptionManager.from(context);
5539
5540 // Figure out what subscribers are currently active
5541 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005542
Jordan Liub49b04b2019-05-06 14:45:15 -07005543 // Only consider subs which match the current subId
5544 // This logic can be simplified. See b/131189269 for progress.
5545 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005546 activeSubscriberIds.add(tele.getSubscriberId(subId));
5547 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548
5549 // First pass, find a number override for an active subscriber
5550 String mergeNumber = null;
5551 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5552 for (String key : prefs.keySet()) {
5553 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5554 final String subscriberId = (String) prefs.get(key);
5555 if (activeSubscriberIds.contains(subscriberId)) {
5556 final String iccId = key.substring(
5557 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5558 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5559 mergeNumber = (String) prefs.get(numberKey);
5560 if (DBG_MERGE) {
5561 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5562 + " for active subscriber " + subscriberId);
5563 }
5564 if (!TextUtils.isEmpty(mergeNumber)) {
5565 break;
5566 }
5567 }
5568 }
5569 }
5570
5571 // Shortcut when no active merged subscribers
5572 if (TextUtils.isEmpty(mergeNumber)) {
5573 return null;
5574 }
5575
5576 // Second pass, find all subscribers under that line override
5577 final ArraySet<String> result = new ArraySet<>();
5578 for (String key : prefs.keySet()) {
5579 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5580 final String number = (String) prefs.get(key);
5581 if (mergeNumber.equals(number)) {
5582 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5583 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5584 final String subscriberId = (String) prefs.get(subscriberKey);
5585 if (!TextUtils.isEmpty(subscriberId)) {
5586 result.add(subscriberId);
5587 }
5588 }
5589 }
5590 }
5591
5592 final String[] resultArray = result.toArray(new String[result.size()]);
5593 Arrays.sort(resultArray);
5594 if (DBG_MERGE) {
5595 Slog.d(LOG_TAG,
5596 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5597 }
5598 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005599 } finally {
5600 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005601 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005602 }
5603
5604 @Override
zoey chen38003472019-12-13 17:16:31 +08005605 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5606 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005607
5608 final long identity = Binder.clearCallingIdentity();
5609 try {
5610 final TelephonyManager telephonyManager = mApp.getSystemService(
5611 TelephonyManager.class);
5612 String subscriberId = telephonyManager.getSubscriberId(subId);
5613 if (subscriberId == null) {
5614 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005615 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005616 + subId);
5617 }
5618 return null;
5619 }
5620
5621 final SubscriptionInfo info = SubscriptionController.getInstance()
5622 .getSubscriptionInfo(subId);
5623 final ParcelUuid groupUuid = info.getGroupUuid();
5624 // If it doesn't belong to any group, return just subscriberId of itself.
5625 if (groupUuid == null) {
5626 return new String[]{subscriberId};
5627 }
5628
5629 // Get all subscriberIds from the group.
5630 final List<String> mergedSubscriberIds = new ArrayList<>();
5631 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005632 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5633 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005634 for (SubscriptionInfo subInfo : groupInfos) {
5635 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5636 if (subscriberId != null) {
5637 mergedSubscriberIds.add(subscriberId);
5638 }
5639 }
5640
5641 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5642 } finally {
5643 Binder.restoreCallingIdentity(identity);
5644
5645 }
5646 }
5647
5648 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005649 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005650 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005651 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005652
5653 final long identity = Binder.clearCallingIdentity();
5654 try {
5655 final Phone phone = getPhone(subId);
5656 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5657 } finally {
5658 Binder.restoreCallingIdentity(identity);
5659 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005660 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005661
5662 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005663 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005664 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5665 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005666 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5667 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668
5669 final long identity = Binder.clearCallingIdentity();
5670 try {
5671 final Phone phone = getPhone(subId);
5672 if (phone == null) {
5673 return false;
5674 }
5675 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5676 cdmaNonRoamingList);
5677 } finally {
5678 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005679 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005680 }
5681
5682 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005683 @Deprecated
5684 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5685 enforceModifyPermission();
5686
5687 int returnValue = 0;
5688 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005689 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005690 if(result.exception == null) {
5691 if (result.result != null) {
5692 byte[] responseData = (byte[])(result.result);
5693 if(responseData.length > oemResp.length) {
5694 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5695 responseData.length + "bytes. Buffer Size is " +
5696 oemResp.length + "bytes.");
5697 }
5698 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5699 returnValue = responseData.length;
5700 }
5701 } else {
5702 CommandException ex = (CommandException) result.exception;
5703 returnValue = ex.getCommandError().ordinal();
5704 if(returnValue > 0) returnValue *= -1;
5705 }
5706 } catch (RuntimeException e) {
5707 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5708 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5709 if(returnValue > 0) returnValue *= -1;
5710 }
5711
5712 return returnValue;
5713 }
5714
5715 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005716 public void setRadioCapability(RadioAccessFamily[] rafs) {
5717 try {
5718 ProxyController.getInstance().setRadioCapability(rafs);
5719 } catch (RuntimeException e) {
5720 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5721 }
5722 }
5723
5724 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005725 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005726 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005727 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005728 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005729 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005730 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 final long identity = Binder.clearCallingIdentity();
5732 try {
chen xub97461a2018-10-26 14:17:57 -07005733 TelephonyPermissions
5734 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5735 mApp, phone.getSubId(), "getRadioAccessFamily");
5736 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
chen xub97461a2018-10-26 14:17:57 -07005740 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005741 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005742
5743 @Override
5744 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005745 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005746 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747
5748 final long identity = Binder.clearCallingIdentity();
5749 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005750 ImsManager.getInstance(defaultPhone.getContext(),
5751 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 } finally {
5753 Binder.restoreCallingIdentity(identity);
5754 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005755 }
5756
5757 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005758 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005759 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5761 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005762 return false;
5763 }
Svet Ganovb320e182015-04-16 12:30:10 -07005764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 final long identity = Binder.clearCallingIdentity();
5766 try {
5767 // Check the user preference and the system-level IMS setting. Even if the user has
5768 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5769 // In the long run, we may instead need to check if there exists a connection service
5770 // which can support video calling.
5771 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005772 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 return imsManager.isVtEnabledByPlatform()
5774 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5775 && imsManager.isVtEnabledByUser();
5776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005779 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005780
Andrew Leea1239f22015-03-02 17:44:07 -08005781 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005782 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5783 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005784 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005785 mApp, subId, callingPackage, callingFeatureId,
5786 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 return false;
5788 }
5789
5790 final long identity = Binder.clearCallingIdentity();
5791 try {
5792 CarrierConfigManager configManager =
5793 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005794 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5796 } finally {
5797 Binder.restoreCallingIdentity(identity);
5798 }
Andrew Leea1239f22015-03-02 17:44:07 -08005799 }
5800
5801 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005802 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005804 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 return false;
5806 }
5807
5808 final long identity = Binder.clearCallingIdentity();
5809 try {
5810 CarrierConfigManager configManager =
5811 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005812 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5814 } finally {
5815 Binder.restoreCallingIdentity(identity);
5816 }
Andrew Leea1239f22015-03-02 17:44:07 -08005817 }
5818
Andrew Lee9431b832015-03-09 18:46:45 -07005819 @Override
5820 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005821 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005822 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005823 }
5824
5825 @Override
5826 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 final long identity = Binder.clearCallingIdentity();
5828 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005829 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830 } finally {
5831 Binder.restoreCallingIdentity(identity);
5832 }
Andrew Lee9431b832015-03-09 18:46:45 -07005833 }
5834
Hall Liuf6668912018-10-31 17:05:23 -07005835 /**
5836 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5837 * support for the feature and device firmware support.
5838 *
5839 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5840 */
5841 @Override
5842 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005843 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005844 final Phone phone = getPhone(subscriptionId);
5845 if (phone == null) {
5846 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5847 return false;
5848 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005849 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005850 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5852 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005853 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005854 return isCarrierSupported && isDeviceSupported;
5855 } finally {
5856 Binder.restoreCallingIdentity(identity);
5857 }
Hall Liu98187582018-01-22 19:15:32 -08005858 }
5859
Hall Liuf6668912018-10-31 17:05:23 -07005860 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005861 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5862 * RTT setting, will return true if the device and carrier both support RTT.
5863 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005864 */
5865 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866 final long identity = Binder.clearCallingIdentity();
5867 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00005868 boolean isRttSupported = isRttSupported(subscriptionId);
5869 boolean isUserRttSettingOn = Settings.Secure.getInt(
5870 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5871 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5872 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5873 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 } finally {
5875 Binder.restoreCallingIdentity(identity);
5876 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005877 }
5878
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005879 @Deprecated
5880 @Override
5881 public String getDeviceId(String callingPackage) {
5882 return getDeviceIdWithFeature(callingPackage, null);
5883 }
5884
Sanket Padawe7310cc72015-01-14 09:53:20 -08005885 /**
5886 * Returns the unique device ID of phone, for example, the IMEI for
5887 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5888 *
5889 * <p>Requires Permission:
5890 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5891 */
5892 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005893 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005894 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005895 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005896 return null;
5897 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005898 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005899 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005900 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005901 return null;
5902 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903
5904 final long identity = Binder.clearCallingIdentity();
5905 try {
5906 return phone.getDeviceId();
5907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005910 }
5911
Ping Sunc67b7c22016-03-02 19:16:45 +08005912 /**
5913 * {@hide}
5914 * Returns the IMS Registration Status on a particular subid
5915 *
5916 * @param subId
5917 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005918 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005919 Phone phone = getPhone(subId);
5920 if (phone != null) {
5921 return phone.isImsRegistered();
5922 } else {
5923 return false;
5924 }
5925 }
5926
Santos Cordon7a1885b2015-02-03 11:15:19 -08005927 @Override
5928 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 final long identity = Binder.clearCallingIdentity();
5930 try {
5931 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5932 } finally {
5933 Binder.restoreCallingIdentity(identity);
5934 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005935 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005936
Tyler Gunnf70ed162019-04-03 15:28:53 -07005937 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005938 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005939 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005941 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005942 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5943 }
5944 final long identity = Binder.clearCallingIdentity();
5945 try {
5946 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5947 } finally {
5948 Binder.restoreCallingIdentity(identity);
5949 }
5950 }
5951
5952 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005953 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5954 final long identity = Binder.clearCallingIdentity();
5955 try {
5956 Phone phone = getPhone(subscriptionId);
5957 if (phone == null) {
5958 return null;
5959 }
5960 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5961 } finally {
5962 Binder.restoreCallingIdentity(identity);
5963 }
5964 }
5965
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005966 /**
5967 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005968 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005969 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 final long identity = Binder.clearCallingIdentity();
5971 try {
5972 Phone phone = getPhone(subId);
5973 if (phone != null) {
5974 return phone.isWifiCallingEnabled();
5975 } else {
5976 return false;
5977 }
5978 } finally {
5979 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005980 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005981 }
5982
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005983 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005984 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005985 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005986 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 final long identity = Binder.clearCallingIdentity();
5988 try {
5989 Phone phone = getPhone(subId);
5990 if (phone != null) {
5991 return phone.isVideoEnabled();
5992 } else {
5993 return false;
5994 }
5995 } finally {
5996 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005997 }
5998 }
5999
6000 /**
6001 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6002 * defined in {@link ImsRegistrationImplBase}.
6003 */
6004 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005 final long identity = Binder.clearCallingIdentity();
6006 try {
6007 Phone phone = getPhone(subId);
6008 if (phone != null) {
6009 return phone.getImsRegistrationTech();
6010 } else {
6011 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6012 }
6013 } finally {
6014 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006015 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006016 }
6017
Stuart Scott8eef64f2015-04-08 15:13:54 -07006018 @Override
6019 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006020 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006021 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6022 return;
6023 }
6024
Svet Ganovcc087f82015-05-12 20:35:54 -07006025 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006026
Svet Ganovcc087f82015-05-12 20:35:54 -07006027 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006028 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6029 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006030 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006031 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006032 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006033 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6034 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006035 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006036 // There has been issues when Sms raw table somehow stores orphan
6037 // fragments. They lead to garbled message when new fragments come
6038 // in and combined with those stale ones. In case this happens again,
6039 // user can reset all network settings which will clean up this table.
6040 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006041 // Clean up IMS settings as well here.
6042 int slotId = getSlotIndex(subId);
6043 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6044 ImsManager.getInstance(mApp, slotId).factoryReset();
6045 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006046
6047 // Erase modem config if erase modem on network setting is enabled.
6048 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6049 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6050 if (configValue != null && Boolean.parseBoolean(configValue)) {
6051 sendEraseModemConfig(getDefaultPhone());
6052 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006053 } finally {
6054 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006055 }
6056 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006057
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006058 private void cleanUpSmsRawTable(Context context) {
6059 ContentResolver resolver = context.getContentResolver();
6060 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6061 resolver.delete(uri, null, null);
6062 }
6063
Narayan Kamath1c496c22015-04-16 14:40:19 +01006064 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006065 public String getSimLocaleForSubscriber(int subId) {
6066 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6067 final Phone phone = getPhone(subId);
6068 if (phone == null) {
6069 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006070 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 final long identity = Binder.clearCallingIdentity();
6073 try {
chen xu5d3637b2019-01-21 23:31:38 -08006074 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006075 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006076 if (info == null) {
6077 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6078 return null;
6079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080 // Try and fetch the locale from the carrier properties or from the SIM language
6081 // preferences (EF-PL and EF-LI)...
6082 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006084 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6085 if (localeFromDefaultSim != null) {
6086 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6087 if (DBG) log("Using locale from subId: " + subId + " locale: "
6088 + localeFromDefaultSim);
6089 return localeFromDefaultSim.toLanguageTag();
6090 } else {
6091 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 }
6093 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006095 // The SIM language preferences only store a language (e.g. fr = French), not an
6096 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6097 // the SIM and carrier preferences does not include a country we add the country
6098 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006099 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006101 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006102 return mccLocale.toLanguageTag();
6103 }
6104
6105 if (DBG) log("No locale found - returning null");
6106 return null;
6107 } finally {
6108 Binder.restoreCallingIdentity(identity);
6109 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006110 }
6111
6112 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006113 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6114 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006115 }
6116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 /**
6118 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6119 */
6120 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006121 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6122 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006123 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006124
Chenjie Yu1ba97252018-01-11 18:16:20 -08006125 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006126 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006127
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006128 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006129 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6130 * representing the state of the modem.
6131 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006132 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6133 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006134 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006135 */
6136 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006137 public void requestModemActivityInfo(ResultReceiver result) {
6138 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006139 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140
6141 final long identity = Binder.clearCallingIdentity();
6142 try {
6143 ModemActivityInfo ret = null;
6144 synchronized (mLastModemActivityInfo) {
6145 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6146 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006147 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006148 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006150 int[] txTimeMs = info.getTransmitTimeMillis();
6151 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006152 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006153 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154 }
6155 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006156 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6157 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 mLastModemActivityInfo.setIdleTimeMillis(
6159 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006160 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6161 mLastModemActivityInfo.setReceiveTimeMillis(
6162 info.getReceiveTimeMillis() + mLastModemActivityInfo
6163 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006164 }
Chen Xud78231e2019-09-10 18:49:52 -07006165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6167 mLastModemActivityInfo.getSleepTimeMillis(),
6168 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006169 mLastModemActivityInfo.getTransmitTimeMillis(),
6170 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006171 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172 Bundle bundle = new Bundle();
6173 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6174 result.send(0, bundle);
6175 } finally {
6176 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006177 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006178 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006179
Siddharth Rayb8114062018-06-17 15:02:38 -07006180 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6181 // less than total activity duration.
6182 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6183 if (info == null) {
6184 return false;
6185 }
6186 int activityDurationMs =
6187 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6188 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006189 int[] txTimeMs = info.getTransmitTimeMillis();
6190 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6191 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006192 }
6193 return (info.isValid()
6194 && (info.getSleepTimeMillis() <= activityDurationMs)
6195 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006196 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006197 && (totalTxTimeMs <= activityDurationMs));
6198 }
6199
Jack Yu85bd38a2015-11-09 11:34:32 -08006200 /**
6201 * {@hide}
6202 * Returns the service state information on specified subscription.
6203 */
6204 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006205 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6206 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006208 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006209 return null;
6210 }
6211
Hall Liuf19c44f2018-11-27 14:38:17 -08006212 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6213 LocationAccessPolicy.checkLocationPermission(mApp,
6214 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6215 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006216 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006217 .setCallingPid(Binder.getCallingPid())
6218 .setCallingUid(Binder.getCallingUid())
6219 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006220 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006221 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6222 .build());
6223
6224 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6225 LocationAccessPolicy.checkLocationPermission(mApp,
6226 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6227 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006228 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006229 .setCallingPid(Binder.getCallingPid())
6230 .setCallingUid(Binder.getCallingUid())
6231 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006232 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006233 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6234 .build());
6235 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6236 boolean hasFinePermission =
6237 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6238 boolean hasCoarsePermission =
6239 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 final long identity = Binder.clearCallingIdentity();
6242 try {
6243 final Phone phone = getPhone(subId);
6244 if (phone == null) {
6245 return null;
6246 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006247
Hall Liuf19c44f2018-11-27 14:38:17 -08006248 ServiceState ss = phone.getServiceState();
6249
6250 // Scrub out the location info in ServiceState depending on what level of access
6251 // the caller has.
6252 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006253 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6254 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006255 } finally {
6256 Binder.restoreCallingIdentity(identity);
6257 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006258 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006259
6260 /**
6261 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6262 *
6263 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6264 * voicemail ringtone.
6265 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6266 * PhoneAccount.
6267 */
6268 @Override
6269 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 final long identity = Binder.clearCallingIdentity();
6271 try {
6272 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6273 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006274 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006277 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6278 } finally {
6279 Binder.restoreCallingIdentity(identity);
6280 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006281 }
6282
6283 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006284 * Sets the per-account voicemail ringtone.
6285 *
6286 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6287 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6288 *
6289 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6290 * voicemail ringtone.
6291 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6292 * PhoneAccount.
6293 */
6294 @Override
6295 public void setVoicemailRingtoneUri(String callingPackage,
6296 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006297 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006298 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006299 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6300 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6302 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6303 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305
6306 final long identity = Binder.clearCallingIdentity();
6307 try {
6308 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6309 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006310 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 }
6312 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6313 } finally {
6314 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006315 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006316 }
6317
6318 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006319 * Returns whether vibration is set for voicemail notification in Phone settings.
6320 *
6321 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6322 * voicemail vibration setting.
6323 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6324 */
6325 @Override
6326 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327 final long identity = Binder.clearCallingIdentity();
6328 try {
6329 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6330 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006331 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6335 } finally {
6336 Binder.restoreCallingIdentity(identity);
6337 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006338 }
6339
Youhan Wange64578a2016-05-02 15:32:42 -07006340 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006341 * Sets the per-account voicemail vibration.
6342 *
6343 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6344 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6345 *
6346 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6347 * voicemail vibration setting.
6348 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6349 * specific PhoneAccount.
6350 */
6351 @Override
6352 public void setVoicemailVibrationEnabled(String callingPackage,
6353 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006354 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006355 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006356 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6357 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6359 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6360 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006361 }
6362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363 final long identity = Binder.clearCallingIdentity();
6364 try {
6365 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6366 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006367 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 }
6369 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6370 } finally {
6371 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006372 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006373 }
6374
6375 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006376 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6377 *
6378 * @throws SecurityException if the caller does not have the required permission
6379 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006380 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006381 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006382 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006383 }
6384
6385 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006386 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6387 * permission.
6388 *
6389 * @throws SecurityException if the caller does not have the required permission
6390 */
6391 private void enforceSendSmsPermission() {
6392 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6393 }
6394
6395 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006396 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006397 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006398 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006399 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006400 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 final long identity = Binder.clearCallingIdentity();
6402 try {
6403 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006404 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 if (componentName == null) {
6406 throw new SecurityException(
6407 "Caller not current active visual voicemail package[null]");
6408 }
6409 String vvmPackage = componentName.getPackageName();
6410 if (!callingPackage.equals(vvmPackage)) {
6411 throw new SecurityException("Caller not current active visual voicemail package["
6412 + vvmPackage + "]");
6413 }
6414 } finally {
6415 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006416 }
6417 }
6418
6419 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006420 * Return the application ID for the app type.
6421 *
6422 * @param subId the subscription ID that this request applies to.
6423 * @param appType the uicc app type.
6424 * @return Application ID for specificied app type, or null if no uicc.
6425 */
6426 @Override
6427 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006428 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006429 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006430
6431 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006432 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006433 if (phone == null) {
6434 return null;
6435 }
6436 String aid = null;
6437 try {
6438 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6439 .getApplicationByType(appType).getAid();
6440 } catch (Exception e) {
6441 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6442 }
6443 return aid;
6444 } finally {
6445 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006446 }
Youhan Wange64578a2016-05-02 15:32:42 -07006447 }
6448
Youhan Wang4001d252016-05-11 10:29:41 -07006449 /**
6450 * Return the Electronic Serial Number.
6451 *
6452 * @param subId the subscription ID that this request applies to.
6453 * @return ESN or null if error.
6454 */
6455 @Override
6456 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006457 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006458 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006459
6460 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006461 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006462 if (phone == null) {
6463 return null;
6464 }
6465 String esn = null;
6466 try {
6467 esn = phone.getEsn();
6468 } catch (Exception e) {
6469 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6470 }
6471 return esn;
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006474 }
Youhan Wang4001d252016-05-11 10:29:41 -07006475 }
6476
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006477 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006478 * Return the Preferred Roaming List Version.
6479 *
6480 * @param subId the subscription ID that this request applies to.
6481 * @return PRLVersion or null if error.
6482 */
6483 @Override
6484 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006485 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006486 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487
6488 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006489 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490 if (phone == null) {
6491 return null;
6492 }
6493 String cdmaPrlVersion = null;
6494 try {
6495 cdmaPrlVersion = phone.getCdmaPrlVersion();
6496 } catch (Exception e) {
6497 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6498 }
6499 return cdmaPrlVersion;
6500 } finally {
6501 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006502 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006503 }
6504
6505 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006506 * Get snapshot of Telephony histograms
6507 * @return List of Telephony histograms
6508 * @hide
6509 */
6510 @Override
6511 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6513 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514
6515 final long identity = Binder.clearCallingIdentity();
6516 try {
6517 return RIL.getTelephonyRILTimingHistograms();
6518 } finally {
6519 Binder.restoreCallingIdentity(identity);
6520 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006521 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006522
6523 /**
6524 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006525 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6526 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006527 * Require system privileges. In the future we may add this to carrier APIs.
6528 *
Michele Berionne482f8202018-11-27 18:57:59 -08006529 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006530 */
6531 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006532 @TelephonyManager.SetCarrierRestrictionResult
6533 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006534 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006535 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006536
Michele Berionne482f8202018-11-27 18:57:59 -08006537 if (carrierRestrictionRules == null) {
6538 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006539 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006540
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006541 final long identity = Binder.clearCallingIdentity();
6542 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006543 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006544 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545 } finally {
6546 Binder.restoreCallingIdentity(identity);
6547 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006548 }
6549
6550 /**
6551 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006552 * Get the allowed carrier list and the excluded carrier list, including the priority between
6553 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006554 * Require system privileges. In the future we may add this to carrier APIs.
6555 *
Michele Berionne482f8202018-11-27 18:57:59 -08006556 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006557 */
6558 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006559 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006560 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006561 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562
6563 final long identity = Binder.clearCallingIdentity();
6564 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006565 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6566 if (response instanceof CarrierRestrictionRules) {
6567 return (CarrierRestrictionRules) response;
6568 }
6569 // Response is an Exception of some kind,
6570 // which is signalled to the user as a NULL retval
6571 return null;
6572 } catch (Exception e) {
6573 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6574 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006575 } finally {
6576 Binder.restoreCallingIdentity(identity);
6577 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006578 }
6579
fionaxu59545b42016-05-25 15:53:37 -07006580 /**
6581 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6582 * @param subId the subscription ID that this action applies to.
6583 * @param enabled control enable or disable metered apns.
6584 * {@hide}
6585 */
6586 @Override
6587 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6588 enforceModifyPermission();
6589 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590
6591 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006592 if (phone == null) {
6593 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6594 return;
6595 }
6596 try {
6597 phone.carrierActionSetMeteredApnsEnabled(enabled);
6598 } catch (Exception e) {
6599 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006600 } finally {
6601 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006602 }
6603 }
6604
6605 /**
6606 * Action set from carrier signalling broadcast receivers to enable/disable radio
6607 * @param subId the subscription ID that this action applies to.
6608 * @param enabled control enable or disable radio.
6609 * {@hide}
6610 */
6611 @Override
6612 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6613 enforceModifyPermission();
6614 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006615
6616 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006617 if (phone == null) {
6618 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6619 return;
6620 }
6621 try {
6622 phone.carrierActionSetRadioEnabled(enabled);
6623 } catch (Exception e) {
6624 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006625 } finally {
6626 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006627 }
6628 }
6629
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006630 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006631 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6632 * network status based on which carrier apps could apply actions accordingly,
6633 * enable/disable default url handler for example.
6634 *
6635 * @param subId the subscription ID that this action applies to.
6636 * @param report control start/stop reporting the default network status.
6637 * {@hide}
6638 */
6639 @Override
6640 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6641 enforceModifyPermission();
6642 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643
6644 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006645 if (phone == null) {
6646 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6647 return;
6648 }
6649 try {
6650 phone.carrierActionReportDefaultNetworkStatus(report);
6651 } catch (Exception e) {
6652 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006653 } finally {
6654 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006655 }
6656 }
6657
6658 /**
fionaxud9622282017-07-17 17:51:30 -07006659 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6660 * @param subId the subscription ID that this action applies to.
6661 * {@hide}
6662 */
6663 @Override
6664 public void carrierActionResetAll(int subId) {
6665 enforceModifyPermission();
6666 final Phone phone = getPhone(subId);
6667 if (phone == null) {
6668 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6669 return;
6670 }
6671 try {
6672 phone.carrierActionResetAll();
6673 } catch (Exception e) {
6674 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6675 }
6676 }
6677
6678 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006679 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6680 * bug report is being generated.
6681 */
6682 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006683 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006684 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6685 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006686 writer.println("Permission Denial: can't dump Phone from pid="
6687 + Binder.getCallingPid()
6688 + ", uid=" + Binder.getCallingUid()
6689 + "without permission "
6690 + android.Manifest.permission.DUMP);
6691 return;
6692 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006693 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006694 }
Jack Yueb89b242016-06-22 13:27:47 -07006695
Brad Ebingerdac2f002018-04-03 15:17:52 -07006696 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006697 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6698 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6699 @NonNull String[] args) {
6700 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6701 this, in.getFileDescriptor(), out.getFileDescriptor(),
6702 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006703 }
6704
Jack Yueb89b242016-06-22 13:27:47 -07006705 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006706 * Get aggregated video call data usage since boot.
6707 *
6708 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6709 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006710 * {@hide}
6711 */
6712 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006713 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006714 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6715 null);
6716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006717 final long identity = Binder.clearCallingIdentity();
6718 try {
6719 // NetworkStatsService keeps tracking the active network interface and identity. It
6720 // records the delta with the corresponding network identity.
6721 // We just return the total video call data usage snapshot since boot.
6722 Phone phone = getPhone(subId);
6723 if (phone != null) {
6724 return phone.getVtDataUsage(perUidStats);
6725 }
6726 return null;
6727 } finally {
6728 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006729 }
Jack Yueb89b242016-06-22 13:27:47 -07006730 }
Jack Yu75ab2952016-07-08 14:29:33 -07006731
6732 /**
6733 * Policy control of data connection. Usually used when data limit is passed.
6734 * @param enabled True if enabling the data, otherwise disabling.
6735 * @param subId Subscription index
6736 * {@hide}
6737 */
6738 @Override
6739 public void setPolicyDataEnabled(boolean enabled, int subId) {
6740 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741
6742 final long identity = Binder.clearCallingIdentity();
6743 try {
6744 Phone phone = getPhone(subId);
6745 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006746 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747 }
6748 } finally {
6749 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006750 }
6751 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006752
6753 /**
6754 * Get Client request stats
6755 * @return List of Client Request Stats
6756 * @hide
6757 */
6758 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006759 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6760 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006761 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006762 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006763 return null;
6764 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006765 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 final long identity = Binder.clearCallingIdentity();
6768 try {
6769 if (phone != null) {
6770 return phone.getClientRequestStats();
6771 }
6772
6773 return null;
6774 } finally {
6775 Binder.restoreCallingIdentity(identity);
6776 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006777 }
6778
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006779 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006780 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006781 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006782 }
Jack Yueb4124c2017-02-16 15:32:43 -08006783
6784 /**
Grace Chen70990072017-03-24 17:21:30 -07006785 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006786 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006787 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006788 * @param state State of SIM (power down, power up, pass through)
6789 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6790 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6791 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006792 *
6793 **/
6794 @Override
Grace Chen70990072017-03-24 17:21:30 -07006795 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006796 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006797 Phone phone = PhoneFactory.getPhone(slotIndex);
6798
vagdeviaf9a5b92018-08-15 16:01:53 -07006799 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6800
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801 final long identity = Binder.clearCallingIdentity();
6802 try {
6803 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006804 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 }
6806 } finally {
6807 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006808 }
6809 }
Shuo Qiandd210312017-04-12 22:11:33 +00006810
Tyler Gunn65d45c22017-06-05 11:22:26 -07006811 private boolean isUssdApiAllowed(int subId) {
6812 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006813 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006814 if (configManager == null) {
6815 return false;
6816 }
6817 PersistableBundle pb = configManager.getConfigForSubId(subId);
6818 if (pb == null) {
6819 return false;
6820 }
6821 return pb.getBoolean(
6822 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6823 }
6824
Shuo Qiandd210312017-04-12 22:11:33 +00006825 /**
6826 * Check if phone is in emergency callback mode
6827 * @return true if phone is in emergency callback mode
6828 * @param subId sub id
6829 */
goneil9c5f4872017-12-05 14:07:56 -08006830 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006831 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006832 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006833 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006834
6835 final long identity = Binder.clearCallingIdentity();
6836 try {
6837 if (phone != null) {
6838 return phone.isInEcm();
6839 } else {
6840 return false;
6841 }
6842 } finally {
6843 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006844 }
6845 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006846
6847 /**
6848 * Get the current signal strength information for the given subscription.
6849 * Because this information is not updated when the device is in a low power state
6850 * it should not be relied-upon to be current.
6851 * @param subId Subscription index
6852 * @return the most recent cached signal strength info from the modem
6853 */
6854 @Override
6855 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006856 final long identity = Binder.clearCallingIdentity();
6857 try {
6858 Phone p = getPhone(subId);
6859 if (p == null) {
6860 return null;
6861 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863 return p.getSignalStrength();
6864 } finally {
6865 Binder.restoreCallingIdentity(identity);
6866 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006867 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006868
Pengquan Meng77b7f132018-08-22 14:49:57 -07006869 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006870 * Get the current modem radio state for the given slot.
6871 * @param slotIndex slot index.
6872 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006873 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006874 * @return the current radio power state from the modem
6875 */
6876 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006877 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006878 Phone phone = PhoneFactory.getPhone(slotIndex);
6879 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006880 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6881 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006882 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6883 }
6884
6885 final long identity = Binder.clearCallingIdentity();
6886 try {
6887 return phone.getRadioPowerState();
6888 } finally {
6889 Binder.restoreCallingIdentity(identity);
6890 }
6891 }
6892 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6893 }
6894
6895 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006896 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6897 *
6898 * <p>Requires one of the following permissions:
6899 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6900 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6901 * privileges.
6902 *
6903 * @param subId subscription id
6904 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6905 * {@code false}.
6906 */
6907 @Override
6908 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006909 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6910 null /* message */);
6911
Pengquan Menga1bb6272018-09-06 09:59:22 -07006912 boolean isEnabled = false;
6913 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006914 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006915 Phone phone = getPhone(subId);
6916 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006917 } catch (Exception e) {
6918 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6919 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006920 } finally {
6921 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006922 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006923 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006924 }
6925
6926
6927 /**
6928 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6929 *
6930 * <p> Requires permission:
6931 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6932 * privileges.
6933 *
6934 * @param subId subscription id
6935 * @param isEnabled {@code true} means enable, {@code false} means disable.
6936 */
6937 @Override
6938 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6940 mApp, subId, "setDataRoamingEnabled");
6941
Pengquan Menga1bb6272018-09-06 09:59:22 -07006942 final long identity = Binder.clearCallingIdentity();
6943 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006944 Phone phone = getPhone(subId);
6945 if (phone != null) {
6946 phone.setDataRoamingEnabled(isEnabled);
6947 }
6948 } finally {
6949 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006950 }
6951 }
6952
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006953 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006954 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006955 TelephonyPermissions
6956 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006957 mApp, subId, "isManualNetworkSelectionAllowed");
6958
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006959 boolean isAllowed = true;
6960 final long identity = Binder.clearCallingIdentity();
6961 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006962 Phone phone = getPhone(subId);
6963 if (phone != null) {
6964 isAllowed = phone.isCspPlmnEnabled();
6965 }
6966 } finally {
6967 Binder.restoreCallingIdentity(identity);
6968 }
6969 return isAllowed;
6970 }
6971
6972 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006973 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006974 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006975 try {
6976 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006977 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006978 } catch (SecurityException e) {
6979 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6980 // has carrier privileges on an active UICC
6981 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6982 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006983 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006984 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006985 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006986
6987 final long identity = Binder.clearCallingIdentity();
6988 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006989 UiccController uiccController = UiccController.getInstance();
6990 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006991 if (hasReadPermission) {
6992 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006993 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006994
6995 // Remove private info if the caller doesn't have access
6996 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6997 for (UiccCardInfo cardInfo : cardInfos) {
6998 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6999 // is available
7000 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7001 if (card == null || card.getUiccProfile() == null) {
7002 // assume no access if the card or profile is unavailable
7003 filteredInfos.add(cardInfo.getUnprivileged());
7004 continue;
7005 }
7006 UiccProfile profile = card.getUiccProfile();
7007 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7008 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7009 filteredInfos.add(cardInfo);
7010 } else {
7011 filteredInfos.add(cardInfo.getUnprivileged());
7012 }
7013 }
7014 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007015 } finally {
7016 Binder.restoreCallingIdentity(identity);
7017 }
7018 }
7019
7020 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007021 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007022 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 final long identity = Binder.clearCallingIdentity();
7025 try {
7026 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7027 if (slots == null) {
7028 Rlog.i(LOG_TAG, "slots is null.");
7029 return null;
7030 }
7031
7032 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7033 for (int i = 0; i < slots.length; i++) {
7034 UiccSlot slot = slots[i];
7035 if (slot == null) {
7036 continue;
7037 }
7038
Jordan Liu7be7e652019-05-06 18:55:02 +00007039 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 UiccCard card = slot.getUiccCard();
7041 if (card != null) {
7042 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007043 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007044 cardId = slot.getEid();
7045 if (TextUtils.isEmpty(cardId)) {
7046 cardId = slot.getIccId();
7047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048 }
7049
Jordan Liu857451f2019-05-09 16:35:35 -07007050 if (cardId != null) {
7051 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7052 // if cardId is an EID, it's all digits so this is fine
7053 cardId = IccUtils.stripTrailingFs(cardId);
7054 }
7055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007056 int cardState = 0;
7057 switch (slot.getCardState()) {
7058 case CARDSTATE_ABSENT:
7059 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7060 break;
7061 case CARDSTATE_PRESENT:
7062 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7063 break;
7064 case CARDSTATE_ERROR:
7065 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7066 break;
7067 case CARDSTATE_RESTRICTED:
7068 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7069 break;
7070 default:
7071 break;
7072
7073 }
7074
7075 infos[i] = new UiccSlotInfo(
7076 slot.isActive(),
7077 slot.isEuicc(),
7078 cardId,
7079 cardState,
7080 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007081 slot.isExtendedApduSupported(),
7082 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 }
7084 return infos;
7085 } finally {
7086 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007087 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007088 }
7089
7090 @Override
7091 public boolean switchSlots(int[] physicalSlots) {
7092 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007093
7094 final long identity = Binder.clearCallingIdentity();
7095 try {
7096 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7097 } finally {
7098 Binder.restoreCallingIdentity(identity);
7099 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007100 }
Jack Yu4c988042018-02-27 15:30:01 -08007101
7102 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007103 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007104 final long identity = Binder.clearCallingIdentity();
7105 try {
7106 return UiccController.getInstance().getCardIdForDefaultEuicc();
7107 } finally {
7108 Binder.restoreCallingIdentity(identity);
7109 }
7110 }
7111
7112 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007113 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7114 enforceModifyPermission();
7115 final Phone phone = getPhone(subId);
7116 if (phone == null) {
7117 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7118 return;
7119 }
7120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121 final long identity = Binder.clearCallingIdentity();
7122 try {
7123 phone.setRadioIndicationUpdateMode(filters, mode);
7124 } finally {
7125 Binder.restoreCallingIdentity(identity);
7126 }
Jack Yu4c988042018-02-27 15:30:01 -08007127 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007128
7129 /**
goneil47ffb6e2018-04-06 15:40:58 -07007130 * A test API to reload the UICC profile.
7131 *
7132 * <p>Requires that the calling app has permission
7133 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7134 * @hide
7135 */
7136 @Override
7137 public void refreshUiccProfile(int subId) {
7138 enforceModifyPermission();
7139
7140 final long identity = Binder.clearCallingIdentity();
7141 try {
7142 Phone phone = getPhone(subId);
7143 if (phone == null) {
7144 return;
7145 }
7146 UiccCard uiccCard = phone.getUiccCard();
7147 if (uiccCard == null) {
7148 return;
7149 }
7150 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7151 if (uiccProfile == null) {
7152 return;
7153 }
7154 uiccProfile.refresh();
7155 } finally {
7156 Binder.restoreCallingIdentity(identity);
7157 }
7158 }
7159
7160 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007161 * Returns false if the mobile data is disabled by default, otherwise return true.
7162 */
7163 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007164 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007165 }
7166
7167 /**
7168 * Returns true if the data roaming is enabled by default, i.e the system property
7169 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7170 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7171 */
7172 private boolean getDefaultDataRoamingEnabled(int subId) {
7173 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007174 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007175 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007176 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7177 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7178 return isDataRoamingEnabled;
7179 }
7180
7181 /**
7182 * Returns the default network type for the given {@code subId}, if the default network type is
7183 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7184 */
7185 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007186 List<Integer> list = TelephonyProperties.default_network();
7187 int phoneId = mSubscriptionController.getPhoneId(subId);
7188 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7189 return list.get(phoneId);
7190 }
7191 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007192 }
fionaxua13278b2018-03-21 00:08:13 -07007193
7194 @Override
7195 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007196 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007197 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007198
7199 final long identity = Binder.clearCallingIdentity();
7200 try {
7201 final Phone phone = getPhone(subId);
7202 if (phone == null) {
7203 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7204 return;
7205 }
chen xueaba88a2019-03-15 13:15:10 -07007206 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7207 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007208 } finally {
7209 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007210 }
fionaxua13278b2018-03-21 00:08:13 -07007211 }
7212
7213 @Override
7214 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007215 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007216
7217 final long identity = Binder.clearCallingIdentity();
7218 try {
7219 final Phone phone = getPhone(subId);
7220 if (phone == null) {
7221 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7222 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7223 }
7224 return phone.getCarrierIdListVersion();
7225 } finally {
7226 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007227 }
fionaxua13278b2018-03-21 00:08:13 -07007228 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007229
7230 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007231 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7232 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007233 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007234 mApp, subId, callingPackage, callingFeatureId,
7235 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007236 return -1;
7237 }
7238
7239 final long identity = Binder.clearCallingIdentity();
7240 try {
7241 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7242 } finally {
7243 Binder.restoreCallingIdentity(identity);
7244 }
7245 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007246
7247 @Override
7248 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007249 TelephonyPermissions
7250 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007251 mApp, subId, "getCdmaRoamingMode");
7252
7253 final long identity = Binder.clearCallingIdentity();
7254 try {
7255 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7256 } finally {
7257 Binder.restoreCallingIdentity(identity);
7258 }
7259 }
7260
7261 @Override
7262 public boolean setCdmaRoamingMode(int subId, int mode) {
7263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7264 mApp, subId, "setCdmaRoamingMode");
7265
7266 final long identity = Binder.clearCallingIdentity();
7267 try {
7268 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7269 } finally {
7270 Binder.restoreCallingIdentity(identity);
7271 }
7272 }
7273
7274 @Override
7275 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7277 mApp, subId, "setCdmaSubscriptionMode");
7278
7279 final long identity = Binder.clearCallingIdentity();
7280 try {
7281 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7282 } finally {
7283 Binder.restoreCallingIdentity(identity);
7284 }
7285 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007286
sqianc5eccab2018-10-19 18:46:41 -07007287 @Override
sqian8c685422019-02-22 15:55:18 -08007288 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007289 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007291 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7292 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007293 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7294 }
7295 final long identity = Binder.clearCallingIdentity();
7296 try {
sqian854d44b2018-12-12 16:48:18 -08007297 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7298 for (Phone phone: PhoneFactory.getPhones()) {
7299 if (phone.getEmergencyNumberTracker() != null
7300 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7301 emergencyNumberListInternal.put(
7302 phone.getSubId(),
7303 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7304 }
sqian11b7a0e2018-12-05 18:48:28 -08007305 }
sqian854d44b2018-12-12 16:48:18 -08007306 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007307 } finally {
7308 Binder.restoreCallingIdentity(identity);
7309 }
sqianc5eccab2018-10-19 18:46:41 -07007310 }
7311
7312 @Override
sqian8c685422019-02-22 15:55:18 -08007313 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007314 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007315 if (!exactMatch) {
7316 TelephonyPermissions
7317 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007318 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007319 }
7320 final long identity = Binder.clearCallingIdentity();
7321 try {
sqian854d44b2018-12-12 16:48:18 -08007322 for (Phone phone: PhoneFactory.getPhones()) {
7323 if (phone.getEmergencyNumberTracker() != null
7324 && phone.getEmergencyNumberTracker() != null) {
7325 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7326 number, exactMatch)) {
7327 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007328 }
7329 }
sqian11b7a0e2018-12-05 18:48:28 -08007330 }
7331 return false;
7332 } finally {
7333 Binder.restoreCallingIdentity(identity);
7334 }
7335 }
7336
sqianf4ca7ed2019-01-15 18:32:07 -08007337 /**
7338 * Update emergency number list for test mode.
7339 */
7340 @Override
7341 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7342 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7343 "updateEmergencyNumberListTestMode");
7344
7345 final long identity = Binder.clearCallingIdentity();
7346 try {
7347 for (Phone phone: PhoneFactory.getPhones()) {
7348 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7349 if (tracker != null) {
7350 tracker.executeEmergencyNumberTestModeCommand(action, num);
7351 }
7352 }
7353 } finally {
7354 Binder.restoreCallingIdentity(identity);
7355 }
7356 }
7357
7358 /**
7359 * Get the full emergency number list for test mode.
7360 */
7361 @Override
7362 public List<String> getEmergencyNumberListTestMode() {
7363 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7364 "getEmergencyNumberListTestMode");
7365
7366 final long identity = Binder.clearCallingIdentity();
7367 try {
7368 Set<String> emergencyNumbers = new HashSet<>();
7369 for (Phone phone: PhoneFactory.getPhones()) {
7370 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7371 if (tracker != null) {
7372 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7373 emergencyNumbers.add(num.getNumber());
7374 }
7375 }
7376 }
7377 return new ArrayList<>(emergencyNumbers);
7378 } finally {
7379 Binder.restoreCallingIdentity(identity);
7380 }
7381 }
7382
chen xud6b45bd2018-10-30 22:27:10 -07007383 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007384 public int getEmergencyNumberDbVersion(int subId) {
7385 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7386
7387 final long identity = Binder.clearCallingIdentity();
7388 try {
7389 final Phone phone = getPhone(subId);
7390 if (phone == null) {
7391 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7392 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7393 }
7394 return phone.getEmergencyNumberDbVersion();
7395 } finally {
7396 Binder.restoreCallingIdentity(identity);
7397 }
7398 }
7399
7400 @Override
7401 public void notifyOtaEmergencyNumberDbInstalled() {
7402 enforceModifyPermission();
7403
7404 final long identity = Binder.clearCallingIdentity();
7405 try {
7406 for (Phone phone: PhoneFactory.getPhones()) {
7407 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7408 if (tracker != null) {
7409 tracker.updateOtaEmergencyNumberDatabase();
7410 }
7411 }
7412 } finally {
7413 Binder.restoreCallingIdentity(identity);
7414 }
7415 }
7416
7417 @Override
7418 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7419 enforceActiveEmergencySessionPermission();
7420
7421 final long identity = Binder.clearCallingIdentity();
7422 try {
7423 for (Phone phone: PhoneFactory.getPhones()) {
7424 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7425 if (tracker != null) {
7426 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7427 }
7428 }
7429 } finally {
7430 Binder.restoreCallingIdentity(identity);
7431 }
7432 }
7433
7434 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007435 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7436 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7437 Phone phone = getPhone(subId);
7438 if (phone == null) {
7439 return null;
7440 }
7441 final long identity = Binder.clearCallingIdentity();
7442 try {
7443 UiccProfile profile = UiccController.getInstance()
7444 .getUiccProfileForPhone(phone.getPhoneId());
7445 if (profile != null) {
7446 return profile.getCertsFromCarrierPrivilegeAccessRules();
7447 }
7448 } finally {
7449 Binder.restoreCallingIdentity(identity);
7450 }
7451 return null;
7452 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007453
7454 /**
7455 * Enable or disable a modem stack.
7456 */
7457 @Override
7458 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7459 enforceModifyPermission();
7460
7461 final long identity = Binder.clearCallingIdentity();
7462 try {
7463 Phone phone = PhoneFactory.getPhone(slotIndex);
7464 if (phone == null) {
7465 return false;
7466 } else {
7467 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7468 }
7469 } finally {
7470 Binder.restoreCallingIdentity(identity);
7471 }
7472 }
Michelecea4cf22018-12-21 15:00:11 -08007473
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007474 /**
7475 * Whether a modem stack is enabled or not.
7476 */
7477 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007478 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7479 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007480 Phone phone = PhoneFactory.getPhone(slotIndex);
7481 if (phone == null) return false;
7482
7483 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007484 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7485 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007486 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7487 }
7488
7489 final long identity = Binder.clearCallingIdentity();
7490 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007491 try {
7492 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7493 } catch (NoSuchElementException ex) {
7494 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7495 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007496 } finally {
7497 Binder.restoreCallingIdentity(identity);
7498 }
7499 }
7500
Michelecea4cf22018-12-21 15:00:11 -08007501 @Override
Michele0ea7d782019-03-19 14:58:42 -07007502 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007503 enforceModifyPermission();
7504
7505 final long identity = Binder.clearCallingIdentity();
7506 try {
7507 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007508 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007509 .commit();
7510 } finally {
7511 Binder.restoreCallingIdentity(identity);
7512 }
7513 }
7514
7515 @Override
Michele0ea7d782019-03-19 14:58:42 -07007516 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007517 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007518 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007519 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7520 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007521 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007522 }
Michelecea4cf22018-12-21 15:00:11 -08007523
7524 final long identity = Binder.clearCallingIdentity();
7525 try {
Michele0ea7d782019-03-19 14:58:42 -07007526 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007527 } finally {
7528 Binder.restoreCallingIdentity(identity);
7529 }
7530 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007531
Michele0ea7d782019-03-19 14:58:42 -07007532 @TelephonyManager.IsMultiSimSupportedResult
7533 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007534 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7535 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7536 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007537 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7538 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007539 }
7540 // Check if the hardware supports multisim functionality. If usage of multisim is not
7541 // supported by the modem, indicate that it is restricted.
7542 PhoneCapability staticCapability =
7543 mPhoneConfigurationManager.getStaticPhoneCapability();
7544 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007545 loge("isMultiSimSupportedInternal: no static configuration available");
7546 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007547 }
7548 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007549 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7550 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007551 }
7552 // Check if support of multiple SIMs is restricted by carrier
7553 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007554 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007555 }
7556
Michele0ea7d782019-03-19 14:58:42 -07007557 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007558 }
7559
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007560 /**
7561 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007562 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7563 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7564 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007565 * @param numOfSims number of active sims we want to switch to
7566 */
7567 @Override
7568 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007569 if (numOfSims == 1) {
7570 enforceModifyPermission();
7571 } else {
7572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7573 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7574 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007575 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007576
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007577 try {
Michele30b57b22019-03-01 12:01:14 -08007578 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007579 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007580 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7581 return;
7582 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007583 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7584 } finally {
7585 Binder.restoreCallingIdentity(identity);
7586 }
7587 }
7588
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007589 @Override
7590 public boolean isApplicationOnUicc(int subId, int appType) {
7591 enforceReadPrivilegedPermission("isApplicationOnUicc");
7592 Phone phone = getPhone(subId);
7593 if (phone == null) {
7594 return false;
7595 }
7596 final long identity = Binder.clearCallingIdentity();
7597 try {
7598 UiccCard uiccCard = phone.getUiccCard();
7599 if (uiccCard == null) {
7600 return false;
7601 }
7602 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7603 if (uiccProfile == null) {
7604 return false;
7605 }
7606 if (TelephonyManager.APPTYPE_SIM <= appType
7607 && appType <= TelephonyManager.APPTYPE_ISIM) {
7608 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7609 }
7610 return false;
7611 } finally {
7612 Binder.restoreCallingIdentity(identity);
7613 }
7614 }
7615
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007616 /**
chen xub4baa772019-04-03 10:23:41 -07007617 * Get whether making changes to modem configurations will trigger reboot.
7618 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007619 */
7620 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007621 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7622 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007624 mApp, subId, callingPackage, callingFeatureId,
7625 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007626 return false;
7627 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007628 final long identity = Binder.clearCallingIdentity();
7629 try {
7630 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7631 } finally {
7632 Binder.restoreCallingIdentity(identity);
7633 }
7634 }
7635
Nathan Harold29f5f052019-02-15 13:41:57 -08007636 private void updateModemStateMetrics() {
7637 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7638 // TODO: check the state for each modem if the api is ready.
7639 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7640 }
7641
Pengquan Meng3889a572019-01-23 11:16:29 -08007642 @Override
7643 public int[] getSlotsMapping() {
7644 enforceReadPrivilegedPermission("getSlotsMapping");
7645
7646 final long identity = Binder.clearCallingIdentity();
7647 try {
7648 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7649 // All logical slots should have a mapping to a physical slot.
7650 int[] logicalSlotsMapping = new int[phoneCount];
7651 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7652 for (int i = 0; i < slotInfos.length; i++) {
7653 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7654 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7655 }
7656 }
7657 return logicalSlotsMapping;
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
7660 }
7661 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007662
7663 /**
7664 * Get the IRadio HAL Version
7665 */
7666 @Override
7667 public int getRadioHalVersion() {
7668 Phone phone = getDefaultPhone();
7669 if (phone == null) return -1;
7670 HalVersion hv = phone.getHalVersion();
7671 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7672 return hv.major * 100 + hv.minor;
7673 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007674
7675 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007676 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7677 * corresponding network requests on a subId.
7678 *
7679 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007680 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007681 * 2) APN is un-metered for this subscription, or
7682 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007683 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007684 *
7685 * @return whether data is allowed for a apn type.
7686 *
7687 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007688 */
7689 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007690 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007691 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7692 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007693
7694 // Now that all security checks passes, perform the operation as ourselves.
7695 final long identity = Binder.clearCallingIdentity();
7696 try {
7697 Phone phone = getPhone(subId);
7698 if (phone == null) return false;
7699
Jack Yu41407ee2019-05-13 16:54:09 -07007700 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007701 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7702 } finally {
7703 Binder.restoreCallingIdentity(identity);
7704 }
7705 }
7706
7707 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007708 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007709 enforceReadPrivilegedPermission("isApnMetered");
7710
7711 // Now that all security checks passes, perform the operation as ourselves.
7712 final long identity = Binder.clearCallingIdentity();
7713 try {
7714 Phone phone = getPhone(subId);
7715 if (phone == null) return true; // By default return true.
7716
Jack Yu41407ee2019-05-13 16:54:09 -07007717 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007718 } finally {
7719 Binder.restoreCallingIdentity(identity);
7720 }
7721 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007722
7723 @Override
changbetty7157e9e2019-12-06 18:16:37 +08007724 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7725 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7726 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7727 if (iccRecords == null) {
7728 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7729 return false;
7730 }
7731 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7732 }
7733
7734 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007735 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7736 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7737 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7738 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7739 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7740 }
7741 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7742 Intent intent = new Intent();
7743 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7744 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7745 // Bring up choose default SMS subscription dialog right now
7746 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7747 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7748 mApp.startActivity(intent);
7749 }
chen xud5ca2d52019-05-28 15:20:57 -07007750
7751 @Override
7752 public String getMmsUAProfUrl(int subId) {
7753 //TODO investigate if this API should require proper permission check in R b/133791609
7754 final long identity = Binder.clearCallingIdentity();
7755 try {
7756 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7757 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7758 } finally {
7759 Binder.restoreCallingIdentity(identity);
7760 }
7761 }
7762
7763 @Override
7764 public String getMmsUserAgent(int subId) {
7765 //TODO investigate if this API should require proper permission check in R b/133791609
7766 final long identity = Binder.clearCallingIdentity();
7767 try {
7768 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7769 .getString(com.android.internal.R.string.config_mms_user_agent);
7770 } finally {
7771 Binder.restoreCallingIdentity(identity);
7772 }
7773 }
Jack Yub07d4972019-05-28 16:12:25 -07007774
7775 @Override
7776 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7777 enforceModifyPermission();
7778
7779 // Now that all security checks passes, perform the operation as ourselves.
7780 final long identity = Binder.clearCallingIdentity();
7781 try {
7782 Phone phone = getPhone(subId);
7783 if (phone == null) return false;
7784
7785 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7786 } finally {
7787 Binder.restoreCallingIdentity(identity);
7788 }
7789 }
7790
7791 @Override
7792 public boolean isDataAllowedInVoiceCall(int subId) {
7793 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7794
7795 // Now that all security checks passes, perform the operation as ourselves.
7796 final long identity = Binder.clearCallingIdentity();
7797 try {
7798 Phone phone = getPhone(subId);
7799 if (phone == null) return false;
7800
7801 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7802 } finally {
7803 Binder.restoreCallingIdentity(identity);
7804 }
7805 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007806
changbettyd5c246e2019-12-24 15:40:37 +08007807 @Override
7808 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
7809 enforceModifyPermission();
7810
7811 // Now that all security checks passes, perform the operation as ourselves.
7812 final long identity = Binder.clearCallingIdentity();
7813 try {
7814 Phone phone = getPhone(subId);
7815 if (phone == null) return false;
7816
7817 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
7818 } finally {
7819 Binder.restoreCallingIdentity(identity);
7820 }
7821 }
7822
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007823 /**
7824 * Updates whether conference event pacakge handling is enabled.
7825 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7826 * otherwise.
7827 */
7828 @Override
7829 public void setCepEnabled(boolean isCepEnabled) {
7830 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7831
7832 final long identity = Binder.clearCallingIdentity();
7833 try {
7834 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7835 for (Phone phone : PhoneFactory.getPhones()) {
7836 Phone defaultPhone = phone.getImsPhone();
7837 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7838 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7839 ImsPhoneCallTracker imsPhoneCallTracker =
7840 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7841 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7842 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7843 + imsPhone.getMsisdn());
7844 }
7845 }
7846 } finally {
7847 Binder.restoreCallingIdentity(identity);
7848 }
7849 }
allenwtsu46dcc572020-01-08 18:24:03 +08007850
7851 /**
7852 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
7853 *
7854 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
7855 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
7856 * before being read.
7857 */
7858 @Override
7859 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
7860 isCompressed) {
7861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7862 mApp, subId, "notifyRcsAutoConfigurationReceived");
7863 try {
7864 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
7865 if (configBinder == null) {
7866 Rlog.e(LOG_TAG, "null result for getImsConfig");
7867 } else {
7868 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
7869 }
7870 } catch (RemoteException e) {
7871 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
7872 }
7873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007874}