blob: 096d14faff5e558fdf35b892b2fc9aa7c1ed2dfe [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;
changbetty363e8ac2019-12-06 18:16:37 +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;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070055import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
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 Ebinger774ba362019-10-22 17:36:18 -0700102import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800104import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700105import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsMmTelFeature;
107import android.telephony.ims.aidl.IImsRcsFeature;
108import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700109import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700110import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.feature.MmTelFeature;
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;
Taesu Leef8fbed92019-10-07 18:47:02 +0900158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-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 chen84e2b212019-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 Wang050bb052020-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 zhaod698b842019-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 Nalluri8ff344d2019-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 Ebinger05f52c22019-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 Nalluri8ff344d2019-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) {
Chen Xu13851032019-09-10 18:49:52 -0700883 request.result = new ModemActivityInfo(0, 0, 0, null, 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 Wang6c08ecd2019-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 Wang6c08ecd2019-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 Wangd64acad2019-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 Wangd64acad2019-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 zhaod698b842019-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 Nalluri8ff344d2019-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 zhaod698b842019-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 Ebinger05f52c22019-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
1416 ServiceManager.addService("phone", this);
1417 }
1418
Stuart Scott584921c2015-01-15 17:10:34 -08001419 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001420 if (request.phone != null) {
1421 return request.phone;
1422 } else {
1423 return getPhoneFromSubId(request.subId);
1424 }
1425 }
1426
1427 private Phone getPhoneFromSubId(int subId) {
1428 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1429 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001430 }
1431
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001432 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1433 Phone phone = getPhoneFromRequest(request);
1434 return phone == null ? null :
1435 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1436 }
1437
Wink Saville36469e72014-06-11 15:17:00 -07001438 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001439 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001440 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001443 private void sendEraseModemConfig(Phone phone) {
1444 if (phone != null) {
1445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1446 mApp, phone.getSubId(), "eraseModemConfig");
1447 final long identity = Binder.clearCallingIdentity();
1448 try {
1449 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1450 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1451 } finally {
1452 Binder.restoreCallingIdentity(identity);
1453 }
1454 }
1455 }
1456
Peter Wang050bb052020-01-13 23:33:09 -08001457 private boolean isImsAvailableOnDevice() {
1458 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1459 if (pm == null) {
1460 // For some reason package manger is not available.. This will fail internally anyway,
1461 // so do not throw error and allow.
1462 return true;
1463 }
1464 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1465 }
1466
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001467 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001468 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001469 }
1470
Wink Savilleb564aae2014-10-23 10:18:09 -07001471 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472 if (DBG) log("dial: " + number);
1473 // No permission check needed here: This is just a wrapper around the
1474 // ACTION_DIAL intent, which is available to any app since it puts up
1475 // the UI before it does anything.
1476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001477 final long identity = Binder.clearCallingIdentity();
1478 try {
1479 String url = createTelUrl(number);
1480 if (url == null) {
1481 return;
1482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001484 // PENDING: should we just silently fail if phone is offhook or ringing?
1485 PhoneConstants.State state = mCM.getState(subId);
1486 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1487 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1488 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1489 mApp.startActivity(intent);
1490 }
1491 } finally {
1492 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001493 }
1494 }
1495
1496 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001497 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001498 }
1499
Wink Savilleb564aae2014-10-23 10:18:09 -07001500 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 if (DBG) log("call: " + number);
1502
1503 // This is just a wrapper around the ACTION_CALL intent, but we still
1504 // need to do a permission check since we're calling startActivity()
1505 // from the context of the phone app.
1506 enforceCallPermission();
1507
Jordan Liu1617b712019-07-10 15:06:26 -07001508 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 != AppOpsManager.MODE_ALLOWED) {
1510 return;
1511 }
1512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001513 final long identity = Binder.clearCallingIdentity();
1514 try {
1515 String url = createTelUrl(number);
1516 if (url == null) {
1517 return;
1518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001520 boolean isValid = false;
1521 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1522 if (slist != null) {
1523 for (SubscriptionInfo subInfoRecord : slist) {
1524 if (subInfoRecord.getSubscriptionId() == subId) {
1525 isValid = true;
1526 break;
1527 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001528 }
Wink Saville08874612014-08-31 19:19:58 -07001529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001530 if (!isValid) {
1531 return;
1532 }
Wink Saville08874612014-08-31 19:19:58 -07001533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001534 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1535 intent.putExtra(SUBSCRIPTION_KEY, subId);
1536 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1537 mApp.startActivity(intent);
1538 } finally {
1539 Binder.restoreCallingIdentity(identity);
1540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001544 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001545 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1546 }
1547
Wink Savilleb564aae2014-10-23 10:18:09 -07001548 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001549 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001550 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1551 }
1552
Wink Savilleb564aae2014-10-23 10:18:09 -07001553 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001555
1556 final long identity = Binder.clearCallingIdentity();
1557 try {
1558 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1559 checkSimPin.start();
1560 return checkSimPin.unlockSim(null, pin);
1561 } finally {
1562 Binder.restoreCallingIdentity(identity);
1563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
1565
Wink Savilleb564aae2014-10-23 10:18:09 -07001566 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001568
1569 final long identity = Binder.clearCallingIdentity();
1570 try {
1571 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1572 checkSimPuk.start();
1573 return checkSimPuk.unlockSim(puk, pin);
1574 } finally {
1575 Binder.restoreCallingIdentity(identity);
1576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 }
1578
1579 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001580 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 * a synchronous one.
1582 */
1583 private static class UnlockSim extends Thread {
1584
1585 private final IccCard mSimCard;
1586
1587 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001588 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1589 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590
1591 // For replies from SimCard interface
1592 private Handler mHandler;
1593
1594 // For async handler to identify request type
1595 private static final int SUPPLY_PIN_COMPLETE = 100;
1596
1597 public UnlockSim(IccCard simCard) {
1598 mSimCard = simCard;
1599 }
1600
1601 @Override
1602 public void run() {
1603 Looper.prepare();
1604 synchronized (UnlockSim.this) {
1605 mHandler = new Handler() {
1606 @Override
1607 public void handleMessage(Message msg) {
1608 AsyncResult ar = (AsyncResult) msg.obj;
1609 switch (msg.what) {
1610 case SUPPLY_PIN_COMPLETE:
1611 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1612 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001613 mRetryCount = msg.arg1;
1614 if (ar.exception != null) {
1615 if (ar.exception instanceof CommandException &&
1616 ((CommandException)(ar.exception)).getCommandError()
1617 == CommandException.Error.PASSWORD_INCORRECT) {
1618 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1619 } else {
1620 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1621 }
1622 } else {
1623 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 mDone = true;
1626 UnlockSim.this.notifyAll();
1627 }
1628 break;
1629 }
1630 }
1631 };
1632 UnlockSim.this.notifyAll();
1633 }
1634 Looper.loop();
1635 }
1636
1637 /*
1638 * Use PIN or PUK to unlock SIM card
1639 *
1640 * If PUK is null, unlock SIM card with PIN
1641 *
1642 * If PUK is not null, unlock SIM card with PUK and set PIN code
1643 */
Wink Saville9de0f752013-10-22 19:04:03 -07001644 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645
1646 while (mHandler == null) {
1647 try {
1648 wait();
1649 } catch (InterruptedException e) {
1650 Thread.currentThread().interrupt();
1651 }
1652 }
1653 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1654
1655 if (puk == null) {
1656 mSimCard.supplyPin(pin, callback);
1657 } else {
1658 mSimCard.supplyPuk(puk, pin, callback);
1659 }
1660
1661 while (!mDone) {
1662 try {
1663 Log.d(LOG_TAG, "wait for done");
1664 wait();
1665 } catch (InterruptedException e) {
1666 // Restore the interrupted status
1667 Thread.currentThread().interrupt();
1668 }
1669 }
1670 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001671 int[] resultArray = new int[2];
1672 resultArray[0] = mResult;
1673 resultArray[1] = mRetryCount;
1674 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 }
1676 }
1677
1678 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001679 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001680
1681 }
1682
Wink Savilleb564aae2014-10-23 10:18:09 -07001683 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 // No permission check needed here: this call is harmless, and it's
1685 // needed for the ServiceState.requestStateUpdate() call (which is
1686 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001687 final long identity = Binder.clearCallingIdentity();
1688 try {
1689 final Phone phone = getPhone(subId);
1690 if (phone != null) {
1691 phone.updateServiceLocation();
1692 }
1693 } finally {
1694 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001695 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001696 }
1697
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001698 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001699 @Override
1700 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001701 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001702 }
1703
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001704 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001705 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1706 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1707 callingFeatureId);
1708 }
1709
1710 @Deprecated
1711 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001712 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001713 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1714 }
1715
1716 @Override
1717 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1718 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001720 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001721 return false;
1722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001723
1724 final long identity = Binder.clearCallingIdentity();
1725 try {
1726 return isRadioOnForSubscriber(subId);
1727 } finally {
1728 Binder.restoreCallingIdentity(identity);
1729 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001730 }
1731
1732 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001733 final long identity = Binder.clearCallingIdentity();
1734 try {
1735 final Phone phone = getPhone(subId);
1736 if (phone != null) {
1737 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1738 } else {
1739 return false;
1740 }
1741 } finally {
1742 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 }
1745
1746 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001747 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 }
Wink Saville36469e72014-06-11 15:17:00 -07001749
Wink Savilleb564aae2014-10-23 10:18:09 -07001750 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001752
1753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 final Phone phone = getPhone(subId);
1756 if (phone != null) {
1757 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1758 }
1759 } finally {
1760 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001761 }
Wink Saville36469e72014-06-11 15:17:00 -07001762 }
1763
1764 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001765 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001766 }
1767
Wink Savilleb564aae2014-10-23 10:18:09 -07001768 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001769 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001770
1771 final long identity = Binder.clearCallingIdentity();
1772 try {
1773 final Phone phone = getPhone(subId);
1774 if (phone == null) {
1775 return false;
1776 }
1777 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1778 toggleRadioOnOffForSubscriber(subId);
1779 }
1780 return true;
1781 } finally {
1782 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784 }
Wink Saville36469e72014-06-11 15:17:00 -07001785
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001786 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001787 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001788 /*
1789 * If any of the Radios are available, it will need to be
1790 * shutdown. So return true if any Radio is available.
1791 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1795 Phone phone = PhoneFactory.getPhone(i);
1796 if (phone != null && phone.isRadioAvailable()) return true;
1797 }
1798 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1799 return false;
1800 } finally {
1801 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001802 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001803 }
1804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001805 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001806 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001807 enforceModifyPermission();
1808
1809 final long identity = Binder.clearCallingIdentity();
1810 try {
1811 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1812 logv("Shutting down Phone " + i);
1813 shutdownRadioUsingPhoneId(i);
1814 }
1815 } finally {
1816 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001817 }
1818 }
1819
1820 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001821 Phone phone = PhoneFactory.getPhone(phoneId);
1822 if (phone != null && phone.isRadioAvailable()) {
1823 phone.shutdownRadio();
1824 }
1825 }
1826
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001828 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001829
1830 final long identity = Binder.clearCallingIdentity();
1831 try {
1832 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1833 if (defaultPhone != null) {
1834 defaultPhone.setRadioPower(turnOn);
1835 return true;
1836 } else {
1837 loge("There's no default phone.");
1838 return false;
1839 }
1840 } finally {
1841 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001842 }
Wink Saville36469e72014-06-11 15:17:00 -07001843 }
1844
Wink Savilleb564aae2014-10-23 10:18:09 -07001845 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001847
1848 final long identity = Binder.clearCallingIdentity();
1849 try {
1850 final Phone phone = getPhone(subId);
1851 if (phone != null) {
1852 phone.setRadioPower(turnOn);
1853 return true;
1854 } else {
1855 return false;
1856 }
1857 } finally {
1858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 }
1861
Wink Saville36469e72014-06-11 15:17:00 -07001862 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001863 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001864 public boolean enableDataConnectivity() {
1865 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001866
1867 final long identity = Binder.clearCallingIdentity();
1868 try {
1869 int subId = mSubscriptionController.getDefaultDataSubId();
1870 final Phone phone = getPhone(subId);
1871 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001872 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001873 return true;
1874 } else {
1875 return false;
1876 }
1877 } finally {
1878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 }
1881
Wink Saville36469e72014-06-11 15:17:00 -07001882 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001883 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 public boolean disableDataConnectivity() {
1885 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001886
1887 final long identity = Binder.clearCallingIdentity();
1888 try {
1889 int subId = mSubscriptionController.getDefaultDataSubId();
1890 final Phone phone = getPhone(subId);
1891 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001892 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001893 return true;
1894 } else {
1895 return false;
1896 }
1897 } finally {
1898 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001899 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001900 }
1901
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001903 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001904 final long identity = Binder.clearCallingIdentity();
1905 try {
1906 final Phone phone = getPhone(subId);
1907 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001908 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001909 } else {
1910 return false;
1911 }
1912 } finally {
1913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 }
1916
1917 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001918 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001919 }
1920
pkanwarae03a6b2016-11-06 20:37:09 -08001921 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001922 enforceCallPermission();
1923
1924 final long identity = Binder.clearCallingIdentity();
1925 try {
1926 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1927 return;
1928 }
1929 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1930 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1931 } finally {
1932 Binder.restoreCallingIdentity(identity);
1933 }
pkanwar32d516d2016-10-14 19:37:38 -07001934 };
1935
Wink Savilleb564aae2014-10-23 10:18:09 -07001936 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001938
1939 final long identity = Binder.clearCallingIdentity();
1940 try {
1941 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1942 return false;
1943 }
1944 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1945 } finally {
1946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948 }
1949
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001951 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001952 }
1953
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001954 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001955 final long identity = Binder.clearCallingIdentity();
1956 try {
1957 Phone phone = PhoneFactory.getPhone(slotIndex);
1958 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1959 PhoneConstantConversions.convertCallState(phone.getState());
1960 } finally {
1961 Binder.restoreCallingIdentity(identity);
1962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963 }
1964
Sanket Padawe356d7632015-06-22 14:03:32 -07001965 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001966 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001967 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1968 }
1969
1970 @Override
1971 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001972 final long identity = Binder.clearCallingIdentity();
1973 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001974 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001975 if (phone != null) {
1976 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1977 } else {
1978 return PhoneConstantConversions.convertDataState(
1979 PhoneConstants.DataState.DISCONNECTED);
1980 }
1981 } finally {
1982 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 }
1985
Sanket Padawe356d7632015-06-22 14:03:32 -07001986 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001987 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001988 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1989 }
1990
1991 @Override
1992 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001993 final long identity = Binder.clearCallingIdentity();
1994 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001995 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001996 if (phone != null) {
1997 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1998 } else {
1999 return TelephonyManager.DATA_ACTIVITY_NONE;
2000 }
2001 } finally {
2002 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002003 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002004 }
2005
2006 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002007 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002008 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002009 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002010
2011 LocationAccessPolicy.LocationPermissionResult locationResult =
2012 LocationAccessPolicy.checkLocationPermission(mApp,
2013 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2014 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002015 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002016 .setCallingPid(Binder.getCallingPid())
2017 .setCallingUid(Binder.getCallingUid())
2018 .setMethod("getCellLocation")
2019 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2020 .build());
2021 switch (locationResult) {
2022 case DENIED_HARD:
2023 throw new SecurityException("Not allowed to access cell location");
2024 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002025 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2026 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 }
2028
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002029 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002030 final long identity = Binder.clearCallingIdentity();
2031 try {
2032 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002033 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002034 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002035 } finally {
2036 Binder.restoreCallingIdentity(identity);
2037 }
Svetoslav64fad262015-04-14 14:35:21 -07002038 }
2039
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002041 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2042 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002043 if (!TextUtils.isEmpty(callingPackage)) {
2044 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2046 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002047 return "";
2048 }
2049 }
2050
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002051 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2052 // registered cell info, so return a NULL country instead.
2053 final long identity = Binder.clearCallingIdentity();
2054 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002055 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2056 // Get default phone in this case.
2057 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2058 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002059 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002060 // Todo: fix this when we can get the actual cellular network info when the device
2061 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002062 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002063 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2064 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002065 return "";
2066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002067 Phone phone = PhoneFactory.getPhone(phoneId);
2068 if (phone != null) {
2069 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002070 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002071 if (sst != null) {
2072 LocaleTracker lt = sst.getLocaleTracker();
2073 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002074 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2075 return lt.getCurrentCountry();
2076 } else if (emergencyNumberTracker != null) {
2077 return emergencyNumberTracker.getEmergencyCountryIso();
2078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002079 }
2080 }
2081 }
2082 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002083 } finally {
2084 Binder.restoreCallingIdentity(identity);
2085 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002086 }
2087
2088 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002090 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002091 }
2092
Sanket Padawe356d7632015-06-22 14:03:32 -07002093 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002094 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 mApp.enforceCallingOrSelfPermission(
2096 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002097
2098 final long identity = Binder.clearCallingIdentity();
2099 try {
2100 final Phone phone = getPhone(subId);
2101 if (phone != null) {
2102 phone.enableLocationUpdates();
2103 }
2104 } finally {
2105 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 }
2108
2109 @Override
2110 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002111 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002112 }
2113
Sanket Padawe356d7632015-06-22 14:03:32 -07002114 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002115 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 mApp.enforceCallingOrSelfPermission(
2117 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002118
2119 final long identity = Binder.clearCallingIdentity();
2120 try {
2121 final Phone phone = getPhone(subId);
2122 if (phone != null) {
2123 phone.disableLocationUpdates();
2124 }
2125 } finally {
2126 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 }
2129
Nathan Harold31d7ff32018-10-15 20:20:30 -07002130 /**
2131 * Returns the target SDK version number for a given package name.
2132 *
Nathan Haroldec184742019-07-10 17:04:16 -07002133 * This call MUST be invoked before clearing the calling UID.
2134 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002135 * @return target SDK if the package is found or INT_MAX.
2136 */
2137 private int getTargetSdk(String packageName) {
2138 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002139 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002140 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002141 if (ai != null) return ai.targetSdkVersion;
2142 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002143 loge("Failed to get package info for pkg="
2144 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002145 }
2146 return Integer.MAX_VALUE;
2147 }
2148
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 @Override
2150 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002151 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2152 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002153 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002154 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2155 throw new SecurityException(
2156 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2157 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002158
Jordan Liu1617b712019-07-10 15:06:26 -07002159 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2161 return null;
2162 }
Svetoslav64fad262015-04-14 14:35:21 -07002163
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002164 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002166 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002167 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168
Nathan Haroldf180aac2018-06-01 18:43:55 -07002169 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2170 for (CellInfo ci : info) {
2171 if (ci instanceof CellInfoGsm) {
2172 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2173 } else if (ci instanceof CellInfoWcdma) {
2174 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002177 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 }
2179
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002180 private List<CellInfo> getCachedCellInfo() {
2181 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2182 for (Phone phone : PhoneFactory.getPhones()) {
2183 List<CellInfo> info = phone.getAllCellInfo();
2184 if (info != null) cellInfos.addAll(info);
2185 }
2186 return cellInfos;
2187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188
2189 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002190 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002191 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002192 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002193
2194 LocationAccessPolicy.LocationPermissionResult locationResult =
2195 LocationAccessPolicy.checkLocationPermission(mApp,
2196 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2197 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002198 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002199 .setCallingPid(Binder.getCallingPid())
2200 .setCallingUid(Binder.getCallingUid())
2201 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002202 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002203 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2204 .build());
2205 switch (locationResult) {
2206 case DENIED_HARD:
2207 throw new SecurityException("Not allowed to access cell info");
2208 case DENIED_SOFT:
2209 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 }
2211
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002212 final int targetSdk = getTargetSdk(callingPackage);
2213 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2214 return getCachedCellInfo();
2215 }
2216
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002217 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002218 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002219 final long identity = Binder.clearCallingIdentity();
2220 try {
2221 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2222 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002223 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002224 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002225 if (info != null) cellInfos.addAll(info);
2226 }
2227 return cellInfos;
2228 } finally {
2229 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 }
2231 }
2232
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002233 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002234 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2235 String callingFeatureId) {
2236 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2237 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002238 }
2239
2240 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002241 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2242 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002243 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002244 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002245 }
2246
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002247 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2248 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002249 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002250 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002251
2252 LocationAccessPolicy.LocationPermissionResult locationResult =
2253 LocationAccessPolicy.checkLocationPermission(mApp,
2254 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2255 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002256 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002257 .setCallingPid(Binder.getCallingPid())
2258 .setCallingUid(Binder.getCallingUid())
2259 .setMethod("requestCellInfoUpdate")
2260 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2261 .build());
2262 switch (locationResult) {
2263 case DENIED_HARD:
2264 throw new SecurityException("Not allowed to access cell info");
2265 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002266 try {
2267 cb.onCellInfo(new ArrayList<CellInfo>());
2268 } catch (RemoteException re) {
2269 // Drop without consequences
2270 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002271 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002272 }
2273
Nathan Harolda939a962019-05-09 10:13:47 -07002274
2275 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002276 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2277
2278 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2279 }
2280
2281 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002283 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002284 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002285
2286 final long identity = Binder.clearCallingIdentity();
2287 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002288 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002289 } finally {
2290 Binder.restoreCallingIdentity(identity);
2291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 }
2293
Shishir Agrawala9f32182016-04-12 12:00:16 -07002294 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002295 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002296 Phone phone = PhoneFactory.getPhone(slotIndex);
2297 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002298 return null;
2299 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002300 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002301 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002302 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002303 return null;
2304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305
2306 final long identity = Binder.clearCallingIdentity();
2307 try {
2308 return phone.getImei();
2309 } finally {
2310 Binder.restoreCallingIdentity(identity);
2311 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002312 }
2313
2314 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002315 public String getTypeAllocationCodeForSlot(int slotIndex) {
2316 Phone phone = PhoneFactory.getPhone(slotIndex);
2317 String tac = null;
2318 if (phone != null) {
2319 String imei = phone.getImei();
2320 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2321 }
2322 return tac;
2323 }
2324
2325 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002326 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002327 Phone phone = PhoneFactory.getPhone(slotIndex);
2328 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002329 return null;
2330 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002331
Jeff Davidson913390f2018-02-23 17:11:49 -08002332 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002333 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002334 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002335 return null;
2336 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002337
2338 final long identity = Binder.clearCallingIdentity();
2339 try {
2340 return phone.getMeid();
2341 } finally {
2342 Binder.restoreCallingIdentity(identity);
2343 }
Jack Yu2af8d712017-03-15 17:14:14 -07002344 }
2345
2346 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002347 public String getManufacturerCodeForSlot(int slotIndex) {
2348 Phone phone = PhoneFactory.getPhone(slotIndex);
2349 String manufacturerCode = null;
2350 if (phone != null) {
2351 String meid = phone.getMeid();
2352 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2353 }
2354 return manufacturerCode;
2355 }
2356
2357 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002358 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2359 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002360 Phone phone = PhoneFactory.getPhone(slotIndex);
2361 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002362 return null;
2363 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002364 int subId = phone.getSubId();
2365 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002366 mApp, subId, callingPackage, callingFeatureId,
2367 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002368 return null;
2369 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002370
2371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 return phone.getDeviceSvn();
2374 } finally {
2375 Binder.restoreCallingIdentity(identity);
2376 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002377 }
2378
fionaxu43304da2017-11-27 22:51:16 -08002379 @Override
2380 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002381 final long identity = Binder.clearCallingIdentity();
2382 try {
2383 final Phone phone = getPhone(subId);
2384 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2385 } finally {
2386 Binder.restoreCallingIdentity(identity);
2387 }
fionaxu43304da2017-11-27 22:51:16 -08002388 }
2389
2390 @Override
2391 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002392 final long identity = Binder.clearCallingIdentity();
2393 try {
2394 final Phone phone = getPhone(subId);
2395 return phone == null ? null : phone.getCarrierName();
2396 } finally {
2397 Binder.restoreCallingIdentity(identity);
2398 }
fionaxu43304da2017-11-27 22:51:16 -08002399 }
2400
calvinpanffe225e2018-11-01 19:43:06 +08002401 @Override
chen xu0026ca62019-03-06 15:28:50 -08002402 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002403 final long identity = Binder.clearCallingIdentity();
2404 try {
2405 final Phone phone = getPhone(subId);
2406 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002407 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002408 } finally {
2409 Binder.restoreCallingIdentity(identity);
2410 }
2411 }
2412
2413 @Override
chen xu0026ca62019-03-06 15:28:50 -08002414 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002415 final long identity = Binder.clearCallingIdentity();
2416 try {
2417 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002418 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002419 } finally {
2420 Binder.restoreCallingIdentity(identity);
2421 }
2422 }
2423
chen xu651eec72018-11-11 19:03:44 -08002424 @Override
chen xu864e11c2018-12-06 22:10:03 -08002425 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2426 if (!isSubscriptionMccMnc) {
2427 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2428 }
chen xu651eec72018-11-11 19:03:44 -08002429 final Phone phone = PhoneFactory.getPhone(slotIndex);
2430 if (phone == null) {
2431 return TelephonyManager.UNKNOWN_CARRIER_ID;
2432 }
2433 final long identity = Binder.clearCallingIdentity();
2434 try {
2435 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2436 } finally {
2437 Binder.restoreCallingIdentity(identity);
2438 }
2439 }
2440
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 //
2442 // Internal helper methods.
2443 //
2444
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002445 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2447 *
2448 * @throws SecurityException if the caller does not have the required permission
2449 */
2450 private void enforceModifyPermission() {
2451 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2452 }
2453
Shuo Qianf2b2df42019-11-13 17:43:31 -08002454 private void enforceActiveEmergencySessionPermission() {
2455 mApp.enforceCallingOrSelfPermission(
2456 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2457 }
2458
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 /**
2460 * Make sure the caller has the CALL_PHONE permission.
2461 *
2462 * @throws SecurityException if the caller does not have the required permission
2463 */
2464 private void enforceCallPermission() {
2465 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2466 }
2467
paulhu423b5f22019-08-23 19:17:33 +08002468 private void enforceSettingsPermission() {
2469 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002470 }
2471
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472 private String createTelUrl(String number) {
2473 if (TextUtils.isEmpty(number)) {
2474 return null;
2475 }
2476
Jake Hambye994d462014-02-03 13:10:13 -08002477 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 }
2479
Ihab Awadf9e92732013-12-05 18:02:52 -08002480 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2482 }
2483
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002484 private static void logv(String msg) {
2485 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2486 }
2487
Ihab Awadf9e92732013-12-05 18:02:52 -08002488 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2490 }
2491
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002492 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002494 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002495 }
2496
Sanket Padawe356d7632015-06-22 14:03:32 -07002497 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002498 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499 final long identity = Binder.clearCallingIdentity();
2500 try {
2501 final Phone phone = PhoneFactory.getPhone(slotIndex);
2502 if (phone == null) {
2503 return PhoneConstants.PHONE_TYPE_NONE;
2504 } else {
2505 return phone.getPhoneType();
2506 }
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002510 }
2511
2512 /**
2513 * Returns the CDMA ERI icon index to display
2514 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002515 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002516 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2517 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2518 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002519 }
2520
Sanket Padawe356d7632015-06-22 14:03:32 -07002521 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002522 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2523 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002525 mApp, subId, callingPackage, callingFeatureId,
2526 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002527 return -1;
2528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002529
2530 final long identity = Binder.clearCallingIdentity();
2531 try {
2532 final Phone phone = getPhone(subId);
2533 if (phone != null) {
2534 return phone.getCdmaEriIconIndex();
2535 } else {
2536 return -1;
2537 }
2538 } finally {
2539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 }
2542
2543 /**
2544 * Returns the CDMA ERI icon mode,
2545 * 0 - ON
2546 * 1 - FLASHING
2547 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002548 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002549 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2550 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2551 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002552 }
2553
Sanket Padawe356d7632015-06-22 14:03:32 -07002554 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002555 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2556 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002558 mApp, subId, callingPackage, callingFeatureId,
2559 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002560 return -1;
2561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562
2563 final long identity = Binder.clearCallingIdentity();
2564 try {
2565 final Phone phone = getPhone(subId);
2566 if (phone != null) {
2567 return phone.getCdmaEriIconMode();
2568 } else {
2569 return -1;
2570 }
2571 } finally {
2572 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 }
2575
2576 /**
2577 * Returns the CDMA ERI text,
2578 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002579 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002580 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2581 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2582 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002583 }
2584
Sanket Padawe356d7632015-06-22 14:03:32 -07002585 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002586 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2587 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002589 mApp, subId, callingPackage, callingFeatureId,
2590 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002591 return null;
2592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002593
2594 final long identity = Binder.clearCallingIdentity();
2595 try {
2596 final Phone phone = getPhone(subId);
2597 if (phone != null) {
2598 return phone.getCdmaEriText();
2599 } else {
2600 return null;
2601 }
2602 } finally {
2603 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 }
2606
2607 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002608 * Returns the CDMA MDN.
2609 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002610 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002611 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2613 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614
2615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002618 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 return phone.getLine1Number();
2620 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002621 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 return null;
2623 }
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002626 }
2627 }
2628
2629 /**
2630 * Returns the CDMA MIN.
2631 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002632 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002633 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2635 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636
2637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 final Phone phone = getPhone(subId);
2640 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2641 return phone.getCdmaMin();
2642 } else {
2643 return null;
2644 }
2645 } finally {
2646 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002647 }
2648 }
2649
Hall Liud892bec2018-11-30 14:51:45 -08002650 @Override
2651 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2652 INumberVerificationCallback callback, String callingPackage) {
2653 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2654 != PERMISSION_GRANTED) {
2655 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2656 }
2657 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2658
2659 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2660 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2661 throw new SecurityException("Calling package must be configured in the device config");
2662 }
2663
2664 if (range == null) {
2665 throw new NullPointerException("Range must be non-null");
2666 }
2667
2668 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002669 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002670
2671 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2672 }
2673
Junda Liuca05d5d2014-08-14 22:36:34 -07002674 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 * Returns true if CDMA provisioning needs to run.
2676 */
2677 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002678 final long identity = Binder.clearCallingIdentity();
2679 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002680 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681 } finally {
2682 Binder.restoreCallingIdentity(identity);
2683 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 }
2685
2686 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002687 * Sets the voice mail number of a given subId.
2688 */
2689 @Override
2690 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002691 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2692 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693
2694 final long identity = Binder.clearCallingIdentity();
2695 try {
2696 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2697 new Pair<String, String>(alphaTag, number), new Integer(subId));
2698 return success;
2699 } finally {
2700 Binder.restoreCallingIdentity(identity);
2701 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002702 }
2703
Ta-wei Yen87c49842016-05-13 21:19:52 -07002704 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002705 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2706 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002707 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2708 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002709 if (!TextUtils.equals(callingPackage, systemDialer)) {
2710 throw new SecurityException("caller must be system dialer");
2711 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712
2713 final long identity = Binder.clearCallingIdentity();
2714 try {
2715 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2716 if (phoneAccountHandle == null) {
2717 return null;
2718 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002719 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 } finally {
2721 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002722 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002723 }
2724
2725 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002726 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2727 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002729 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002730 mApp, subId, callingPackage, callingFeatureId,
2731 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002732 return null;
2733 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002735 final long identity = Binder.clearCallingIdentity();
2736 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002737 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002738 } finally {
2739 Binder.restoreCallingIdentity(identity);
2740 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002741 }
2742
2743 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002744 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2745 VisualVoicemailSmsFilterSettings settings) {
2746 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747
2748 final long identity = Binder.clearCallingIdentity();
2749 try {
2750 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002751 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002752 } finally {
2753 Binder.restoreCallingIdentity(identity);
2754 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002755 }
2756
2757 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002758 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2759 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760
2761 final long identity = Binder.clearCallingIdentity();
2762 try {
2763 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002764 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765 } finally {
2766 Binder.restoreCallingIdentity(identity);
2767 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002768 }
2769
2770 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002771 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2772 String callingPackage, int subId) {
2773 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774
2775 final long identity = Binder.clearCallingIdentity();
2776 try {
2777 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002778 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779 } finally {
2780 Binder.restoreCallingIdentity(identity);
2781 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002782 }
2783
2784 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002785 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002786 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787
2788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002791 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002792 } finally {
2793 Binder.restoreCallingIdentity(identity);
2794 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002795 }
2796
2797 @Override
2798 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2799 String number, int port, String text, PendingIntent sentIntent) {
2800 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002801 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002802 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002803 SmsController smsController = PhoneFactory.getSmsController();
2804 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2805 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002806 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002807
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002808 /**
fionaxu0152e512016-11-14 13:36:14 -08002809 * Sets the voice activation state of a given subId.
2810 */
2811 @Override
2812 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2814 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815
2816 final long identity = Binder.clearCallingIdentity();
2817 try {
2818 final Phone phone = getPhone(subId);
2819 if (phone != null) {
2820 phone.setVoiceActivationState(activationState);
2821 } else {
2822 loge("setVoiceActivationState fails with invalid subId: " + subId);
2823 }
2824 } finally {
2825 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002826 }
2827 }
2828
2829 /**
2830 * Sets the data activation state of a given subId.
2831 */
2832 @Override
2833 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2835 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836
2837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 final Phone phone = getPhone(subId);
2840 if (phone != null) {
2841 phone.setDataActivationState(activationState);
2842 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002843 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844 }
2845 } finally {
2846 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002847 }
2848 }
2849
2850 /**
2851 * Returns the voice activation state of a given subId.
2852 */
2853 @Override
2854 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002855 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856
fionaxu0152e512016-11-14 13:36:14 -08002857 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 if (phone != null) {
2861 return phone.getVoiceActivationState();
2862 } else {
2863 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2864 }
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002867 }
2868 }
2869
2870 /**
2871 * Returns the data activation state of a given subId.
2872 */
2873 @Override
2874 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002875 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876
fionaxu0152e512016-11-14 13:36:14 -08002877 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 if (phone != null) {
2881 return phone.getDataActivationState();
2882 } else {
2883 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2884 }
2885 } finally {
2886 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002887 }
2888 }
2889
2890 /**
Wink Saville36469e72014-06-11 15:17:00 -07002891 * Returns the unread count of voicemails for a subId
2892 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002893 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002894 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2895 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002896 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002897 mApp, subId, callingPackage, callingFeatureId,
2898 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002899 return 0;
2900 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 final Phone phone = getPhone(subId);
2904 if (phone != null) {
2905 return phone.getVoiceMessageCount();
2906 } else {
2907 return 0;
2908 }
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 }
2913
2914 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002915 * returns true, if the device is in a state where both voice and data
2916 * are supported simultaneously. This can change based on location or network condition.
2917 */
2918 @Override
2919 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920 final long identity = Binder.clearCallingIdentity();
2921 try {
2922 final Phone phone = getPhone(subId);
2923 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
2926 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002927 }
2928
2929 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002930 * Send the dialer code if called from the current default dialer or the caller has
2931 * carrier privilege.
2932 * @param inputCode The dialer code to send
2933 */
2934 @Override
2935 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002936 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002937 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002938 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2939 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002940 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08002941 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002942 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002943 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002944
2945 final long identity = Binder.clearCallingIdentity();
2946 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002947 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948 } finally {
2949 Binder.restoreCallingIdentity(identity);
2950 }
fionaxu235cc5e2017-03-06 22:25:57 -08002951 }
2952
Pengquan Menga1bb6272018-09-06 09:59:22 -07002953 @Override
2954 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08002955 TelephonyPermissions
2956 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
2957 mApp, subId, "getNetworkSelectionMode");
2958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 if (!isActiveSubscription(subId)) {
2961 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2962 }
2963 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2964 } finally {
2965 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07002966 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002967 }
2968
Brad Ebinger35c841c2018-10-01 10:40:55 -07002969 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002970 public boolean isInEmergencySmsMode() {
2971 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 for (Phone phone : PhoneFactory.getPhones()) {
2975 if (phone.isInEmergencySmsMode()) {
2976 return true;
2977 }
2978 }
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 return false;
2983 }
2984
shilu366312e2019-12-17 09:28:10 -08002985 /**
2986 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
2987 * @param subId The subscription to use to check the configuration.
2988 * @param c The callback that will be used to send the result.
2989 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07002990 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002991 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2992 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08002993 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002994 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08002995
Brad Ebinger77b832e2019-10-17 17:03:22 -07002996 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2997 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2998 "IMS not available on device.");
2999 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003000 final long token = Binder.clearCallingIdentity();
3001 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003002 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003003 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003004 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003005 } catch (ImsException e) {
3006 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003007 } finally {
3008 Binder.restoreCallingIdentity(token);
3009 }
3010 }
3011
shilu366312e2019-12-17 09:28:10 -08003012 /**
3013 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3014 * @param subId The subscription to use to check the configuration.
3015 * @param c The callback that will be used to send the result.
3016 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003017 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003018 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003019 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003020 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003021 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3022 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3023 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003024 final long token = Binder.clearCallingIdentity();
3025 try {
3026 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3027 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3028 .removeRegistrationCallbackForSubscription(c, subId);
3029 } catch (ImsException e) {
3030 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3031 + "is inactive, ignoring unregister.");
3032 // If the subscription is no longer active, just return, since the callback
3033 // will already have been removed internally.
3034 } finally {
3035 Binder.restoreCallingIdentity(token);
3036 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003037 }
3038
Brad Ebinger774ba362019-10-22 17:36:18 -07003039 /**
3040 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3041 */
3042 @Override
3043 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3044 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3045 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3046 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3047 "IMS not available on device.");
3048 }
3049 final long token = Binder.clearCallingIdentity();
3050 try {
3051 Phone phone = getPhone(subId);
3052 if (phone == null) {
3053 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3054 + subId + "'");
3055 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3056 }
3057 phone.getImsRegistrationState(regState -> {
3058 try {
3059 consumer.accept((regState == null)
3060 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3061 } catch (RemoteException e) {
3062 // Ignore if the remote process is no longer available to call back.
3063 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3064 }
3065 });
3066 } finally {
3067 Binder.restoreCallingIdentity(token);
3068 }
3069 }
3070
3071 /**
3072 * Get the transport type for the IMS service registration state.
3073 */
3074 @Override
3075 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003076 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger774ba362019-10-22 17:36:18 -07003077 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3078 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3079 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3080 "IMS not available on device.");
3081 }
3082 final long token = Binder.clearCallingIdentity();
3083 try {
3084 Phone phone = getPhone(subId);
3085 if (phone == null) {
3086 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3087 + subId + "'");
3088 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3089 }
3090 phone.getImsRegistrationTech(regTech -> {
3091 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3092 int regTechConverted = (regTech == null)
3093 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3094 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3095 regTechConverted);
3096 try {
3097 consumer.accept(regTechConverted);
3098 } catch (RemoteException e) {
3099 // Ignore if the remote process is no longer available to call back.
3100 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3101 }
3102 });
3103 } finally {
3104 Binder.restoreCallingIdentity(token);
3105 }
3106 }
3107
shilu366312e2019-12-17 09:28:10 -08003108 /**
3109 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3110 * @param subId The subscription to use to check the configuration.
3111 * @param c The callback that will be used to send the result.
3112 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003113 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003114 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3115 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003116 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003117 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003118 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3119 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3120 "IMS not available on device.");
3121 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003122 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3123 final long token = Binder.clearCallingIdentity();
3124 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003125 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003126 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003127 } catch (ImsException e) {
3128 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003129 } finally {
3130 Binder.restoreCallingIdentity(token);
3131 }
3132 }
3133
shilu366312e2019-12-17 09:28:10 -08003134 /**
3135 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3136 * @param subId The subscription to use to check the configuration.
3137 * @param c The callback that will be used to send the result.
3138 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003139 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003140 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003141 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003142 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003143 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3144 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3145 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003146
3147 final long token = Binder.clearCallingIdentity();
3148 try {
3149 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3150 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003151 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003152 } catch (ImsException e) {
3153 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3154 + "is inactive, ignoring unregister.");
3155 // If the subscription is no longer active, just return, since the callback
3156 // will already have been removed internally.
3157 } finally {
3158 Binder.restoreCallingIdentity(token);
3159 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003160 }
3161
3162 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003163 public boolean isCapable(int subId, int capability, int regTech) {
3164 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003165 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3166 final long token = Binder.clearCallingIdentity();
3167 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003168 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003169 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003170 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003171 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3172 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003173 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003174 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3175 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003176 } finally {
3177 Binder.restoreCallingIdentity(token);
3178 }
3179 }
3180
3181 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003182 public boolean isAvailable(int subId, int capability, int regTech) {
3183 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003184 final long token = Binder.clearCallingIdentity();
3185 try {
3186 Phone phone = getPhone(subId);
3187 if (phone == null) return false;
3188 return phone.isImsCapabilityAvailable(capability, regTech);
3189 } finally {
3190 Binder.restoreCallingIdentity(token);
3191 }
3192 }
3193
Brad Ebinger77b832e2019-10-17 17:03:22 -07003194 /**
3195 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3196 * subscription.
3197 * @param subId The subscription to use to check the configuration.
3198 * @param callback The callback that will be used to send the result.
3199 * @param capability The MmTelFeature capability that will be used to send the result.
3200 * @param transportType The transport type of the MmTelFeature capability.
3201 */
3202 @Override
3203 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3204 int transportType) {
3205 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3206 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3207 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3208 "IMS not available on device.");
3209 }
3210 final long token = Binder.clearCallingIdentity();
3211 try {
3212 int slotId = getSlotIndex(subId);
3213 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3214 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3215 + subId + "'");
3216 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3217 }
3218 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3219 transportType, aBoolean -> {
3220 try {
3221 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3222 } catch (RemoteException e) {
3223 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3224 + "running. Ignore");
3225 }
3226 });
3227 } finally {
3228 Binder.restoreCallingIdentity(token);
3229 }
3230 }
3231
shilu366312e2019-12-17 09:28:10 -08003232 /**
3233 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3234 * @param subId The subscription to use to check the configuration.
3235 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003236 @Override
3237 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003238 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3239 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3240
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3242 final long token = Binder.clearCallingIdentity();
3243 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003244 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003245 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003246 } catch (ImsException e) {
3247 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 } finally {
3249 Binder.restoreCallingIdentity(token);
3250 }
3251 }
3252
3253 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003254 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003256 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003257 final long identity = Binder.clearCallingIdentity();
3258 try {
3259 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003260 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003261 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003262 } catch (ImsException e) {
3263 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003264 } finally {
3265 Binder.restoreCallingIdentity(identity);
3266 }
3267 }
3268
shilu366312e2019-12-17 09:28:10 -08003269 /**
3270 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3271 * @param subId The subscription to use to check the configuration.
3272 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003274 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003275 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003276 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003277 final long identity = Binder.clearCallingIdentity();
3278 try {
3279 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003280 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3281 } catch (ImsException e) {
3282 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003283 } finally {
3284 Binder.restoreCallingIdentity(identity);
3285 }
3286 }
3287
3288 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003289 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003291 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003295 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003296 } catch (ImsException e) {
3297 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003298 } finally {
3299 Binder.restoreCallingIdentity(identity);
3300 }
3301 }
3302
shilu366312e2019-12-17 09:28:10 -08003303 /**
3304 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3305 * @param subId The subscription to use to check the configuration.
3306 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003307 @Override
3308 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003309 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003310 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003314 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003315 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003316 } catch (ImsException e) {
3317 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
3321 }
3322
3323 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003324 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003326 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003330 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003331 } catch (ImsException e) {
3332 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003333 } finally {
3334 Binder.restoreCallingIdentity(identity);
3335 }
3336 }
3337
shilu366312e2019-12-17 09:28:10 -08003338 /**
3339 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3340 * @param subId The subscription to use to check the configuration.
3341 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003342 @Override
3343 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003344 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003345 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3346 final long identity = Binder.clearCallingIdentity();
3347 try {
3348 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003349 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003350 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003351 } catch (ImsException e) {
3352 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003353 } finally {
3354 Binder.restoreCallingIdentity(identity);
3355 }
3356 }
3357
3358 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003359 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003361 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003362 final long identity = Binder.clearCallingIdentity();
3363 try {
3364 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003365 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003367 } catch (ImsException e) {
3368 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003369 } finally {
3370 Binder.restoreCallingIdentity(identity);
3371 }
3372 }
3373
3374 @Override
3375 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3377 "setVoWiFiNonPersistent");
3378 final long identity = Binder.clearCallingIdentity();
3379 try {
3380 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003381 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003382 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003383 } catch (ImsException e) {
3384 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003385 } finally {
3386 Binder.restoreCallingIdentity(identity);
3387 }
3388 }
3389
shilu366312e2019-12-17 09:28:10 -08003390 /**
3391 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3392 * @param subId The subscription to use to check the configuration.
3393 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003394 @Override
3395 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003396 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003397 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3398 final long identity = Binder.clearCallingIdentity();
3399 try {
3400 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003401 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003402 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003403 } catch (ImsException e) {
3404 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003405 } finally {
3406 Binder.restoreCallingIdentity(identity);
3407 }
3408 }
3409
3410 @Override
3411 public void setVoWiFiModeSetting(int subId, int mode) {
3412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3413 "setVoWiFiModeSetting");
3414 final long identity = Binder.clearCallingIdentity();
3415 try {
3416 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003417 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003418 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003419 } catch (ImsException e) {
3420 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003421 } finally {
3422 Binder.restoreCallingIdentity(identity);
3423 }
3424 }
3425
3426 @Override
3427 public int getVoWiFiRoamingModeSetting(int subId) {
3428 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3429 final long identity = Binder.clearCallingIdentity();
3430 try {
3431 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003432 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003433 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003434 } catch (ImsException e) {
3435 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003436 } finally {
3437 Binder.restoreCallingIdentity(identity);
3438 }
3439 }
3440
3441 @Override
3442 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3444 "setVoWiFiRoamingModeSetting");
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003448 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003449 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003450 } catch (ImsException e) {
3451 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003452 } finally {
3453 Binder.restoreCallingIdentity(identity);
3454 }
3455 }
3456
3457 @Override
3458 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3460 "setRttCapabilityEnabled");
3461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003464 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3465 } catch (ImsException e) {
3466 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003467 } finally {
3468 Binder.restoreCallingIdentity(identity);
3469 }
3470 }
3471
shilu366312e2019-12-17 09:28:10 -08003472 /**
3473 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3474 * @param subId The subscription to use to check the configuration.
3475 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003476 @Override
3477 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003478 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003479 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3480 final long identity = Binder.clearCallingIdentity();
3481 try {
3482 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003483 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003484 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003485 } catch (ImsException e) {
3486 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003487 } finally {
3488 Binder.restoreCallingIdentity(identity);
3489 }
3490 }
3491
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003492 @Override
3493 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3494 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3495 final long identity = Binder.clearCallingIdentity();
3496 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003497 if (!isImsAvailableOnDevice()) {
3498 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3499 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003500 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003501 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003502 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003503 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003504 } catch (ImsException e) {
3505 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003506 } finally {
3507 Binder.restoreCallingIdentity(identity);
3508 }
3509 }
3510
3511 @Override
3512 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3513 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3514 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003515 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3516 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3517 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003518 try {
3519 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003520 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003521 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003522 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003523 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3524 + "is inactive, ignoring unregister.");
3525 // If the subscription is no longer active, just return, since the callback will already
3526 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
3530 }
3531
allenwtsu99c623b2020-01-03 18:24:23 +08003532
3533 private void checkModifyPhoneStatePermission(int subId, String message) {
3534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3535 message);
3536 }
3537
3538 private boolean isImsProvisioningRequired(int subId, int capability,
3539 boolean isMmtelCapability) {
3540 Phone phone = getPhone(subId);
3541 if (phone == null) {
3542 loge("phone instance null for subid " + subId);
3543 return false;
3544 }
3545 if (isMmtelCapability) {
3546 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3547 return false;
3548 }
3549 } else {
3550 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3551 return false;
3552 }
3553 }
3554 return true;
3555 }
3556
3557 @Override
3558 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3559 boolean isProvisioned) {
3560 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3561
3562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3565 if (!isImsProvisioningRequired(subId, capability, false)) {
3566 return;
3567 }
3568
3569 // this capability requires provisioning, route to the correct API.
3570 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3571 switch (capability) {
3572 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3573 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3574 ims.setEabProvisioned(isProvisioned);
3575 break;
3576 default: {
3577 throw new IllegalArgumentException("Tried to set provisioning for "
3578 + "rcs capability '" + capability + "', which does not require "
3579 + "provisioning.");
3580 }
3581 }
3582 } finally {
3583 Binder.restoreCallingIdentity(identity);
3584 }
3585
3586 }
3587
3588
3589 @Override
3590 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3591 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3592 final long identity = Binder.clearCallingIdentity();
3593 try {
3594 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3595 if (!isImsProvisioningRequired(subId, capability, false)) {
3596 return true;
3597 }
3598
3599 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3600 switch (capability) {
3601 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3602 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3603 return ims.isEabProvisionedOnDevice();
3604
3605 default: {
3606 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3607 + "capability '" + capability + "', which does not require "
3608 + "provisioning.");
3609 }
3610 }
3611
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
3614 }
3615 }
3616
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003617 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003618 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3619 boolean isProvisioned) {
3620 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3621 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3622 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3623 }
allenwtsu99c623b2020-01-03 18:24:23 +08003624 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003625 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;
3630 }
3631
3632 // this capability requires provisioning, route to the correct API.
3633 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3634 switch (capability) {
3635 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3636 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3637 ims.setVolteProvisioned(isProvisioned);
3638 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3639 ims.setWfcProvisioned(isProvisioned);
3640 }
3641 break;
3642 }
3643 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3644 // There is currently no difference in VT provisioning type.
3645 ims.setVtProvisioned(isProvisioned);
3646 break;
3647 }
3648 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3649 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3650 // change the capability of the feature instead if needed.
3651 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3652 == isProvisioned) {
3653 // No change in provisioning.
3654 return;
3655 }
3656 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3657 try {
3658 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003659 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003660 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3661 + ", Exception" + e.getMessage());
3662 }
3663 break;
3664 }
3665 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003666 throw new IllegalArgumentException("Tried to set provisioning for "
3667 + "MmTel capability '" + capability + "', which does not require "
3668 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003669 }
3670 }
3671
3672 } finally {
3673 Binder.restoreCallingIdentity(identity);
3674 }
3675 }
3676
3677 @Override
3678 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3679 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3680 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3681 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3682 }
3683 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3684 final long identity = Binder.clearCallingIdentity();
3685 try {
3686 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003687 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003688 return true;
3689 }
3690
3691 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3692 switch (capability) {
3693 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3694 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3695 return ims.isVolteProvisionedOnDevice();
3696 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3697 return ims.isWfcProvisionedOnDevice();
3698 }
3699 // This should never happen, since we are checking tech above to make sure it
3700 // is either LTE or IWLAN.
3701 throw new IllegalArgumentException("Invalid radio technology for voice "
3702 + "capability.");
3703 }
3704 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3705 // There is currently no difference in VT provisioning type.
3706 return ims.isVtProvisionedOnDevice();
3707 }
3708 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3709 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3710 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3711 }
3712 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003713 throw new IllegalArgumentException(
3714 "Tried to get provisioning for MmTel capability '" + capability
3715 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003716 }
3717 }
3718
3719 } finally {
3720 Binder.restoreCallingIdentity(identity);
3721 }
3722 }
3723
3724 @Override
3725 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3726 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3727 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3728 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3729 }
3730 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3731 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3732 return (provisionedBits & capability) > 0;
3733 }
3734
3735 @Override
3736 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3737 boolean isProvisioned) {
3738 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3739 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3740 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3741 }
3742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3743 "setProvisioningStatusForCapability");
3744 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3745 // If the current provisioning status for capability already matches isProvisioned,
3746 // do nothing.
3747 if (((provisionedBits & capability) > 0) == isProvisioned) {
3748 return;
3749 }
3750 if (isProvisioned) {
3751 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3752 } else {
3753 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3754 }
3755 }
3756
3757 /**
3758 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3759 * technology. The bitfield should mirror the bitfield defined by
3760 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3761 */
3762 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3763 String key = getMmTelProvisioningKey(subId, tech);
3764 // Default is no capabilities are provisioned.
3765 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3766 }
3767
3768 /**
3769 * Sets the MmTel capability provisioning bitfield (defined by
3770 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3771 * technology specified.
3772 *
3773 * Note: This is a synchronous command and should not be called on UI thread.
3774 */
3775 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3776 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3777 String key = getMmTelProvisioningKey(subId, tech);
3778 editor.putInt(key, newField);
3779 editor.commit();
3780 }
3781
3782 private static String getMmTelProvisioningKey(int subId, int tech) {
3783 // resulting key is provision_ims_mmtel_{subId}_{tech}
3784 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3785 }
3786
3787 /**
3788 * Query CarrierConfig to see if the specified capability requires provisioning for the
3789 * carrier associated with the subscription id.
3790 */
3791 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3792 int capability) {
3793 CarrierConfigManager configManager = new CarrierConfigManager(context);
3794 PersistableBundle c = configManager.getConfigForSubId(subId);
3795 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003796 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003797 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3798 false);
3799 boolean requireVoiceVtProvisioning = c.getBoolean(
3800 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3801
3802 // First check to make sure that the capability requires provisioning.
3803 switch (capability) {
3804 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3805 // intentional fallthrough
3806 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3807 if (requireVoiceVtProvisioning) {
3808 // Voice and Video requires provisioning
3809 return true;
3810 }
3811 break;
3812 }
3813 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3814 if (requireUtProvisioning) {
3815 // UT requires provisioning
3816 return true;
3817 }
3818 break;
3819 }
3820 }
3821 return false;
3822 }
3823
allenwtsu99c623b2020-01-03 18:24:23 +08003824 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3825 int capability) {
3826 CarrierConfigManager configManager = new CarrierConfigManager(context);
3827 PersistableBundle c = configManager.getConfigForSubId(subId);
3828
3829 boolean requireRcsProvisioning = c.getBoolean(
3830 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3831
3832 // First check to make sure that the capability requires provisioning.
3833 switch (capability) {
3834 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3835 // intentional fallthrough
3836 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3837 if (requireRcsProvisioning) {
3838 // OPTION or PRESENCE requires provisioning
3839 return true;
3840 }
3841 break;
3842 }
3843 }
3844 return false;
3845 }
3846
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003847 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003848 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003849 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3850 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3851 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003852 enforceReadPrivilegedPermission("getImsProvisioningInt");
3853 final long identity = Binder.clearCallingIdentity();
3854 try {
3855 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003856 int slotId = getSlotIndex(subId);
3857 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3858 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3859 + subId + "' for key:" + key);
3860 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3861 }
3862 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003863 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003864 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3865 + subId + "' for key:" + key);
3866 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003867 } finally {
3868 Binder.restoreCallingIdentity(identity);
3869 }
3870 }
3871
3872 @Override
3873 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003874 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3875 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3876 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003877 enforceReadPrivilegedPermission("getImsProvisioningString");
3878 final long identity = Binder.clearCallingIdentity();
3879 try {
3880 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003881 int slotId = getSlotIndex(subId);
3882 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3883 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3884 + subId + "' for key:" + key);
3885 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3886 }
3887 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003888 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003889 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3890 + subId + "' for key:" + key);
3891 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003892 } finally {
3893 Binder.restoreCallingIdentity(identity);
3894 }
3895 }
3896
3897 @Override
3898 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003899 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3900 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3901 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3903 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003904 final long identity = Binder.clearCallingIdentity();
3905 try {
3906 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003907 int slotId = getSlotIndex(subId);
3908 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3909 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3910 + subId + "' for key:" + key);
3911 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3912 }
3913 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003914 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003915 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3916 + "' for key:" + key);
3917 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003918 } finally {
3919 Binder.restoreCallingIdentity(identity);
3920 }
3921 }
3922
3923 @Override
3924 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003925 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3926 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3927 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3929 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003930 final long identity = Binder.clearCallingIdentity();
3931 try {
3932 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003933 int slotId = getSlotIndex(subId);
3934 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3935 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3936 + subId + "' for key:" + key);
3937 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3938 }
3939 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003940 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003941 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3942 + "' for key:" + key);
3943 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003944 } finally {
3945 Binder.restoreCallingIdentity(identity);
3946 }
3947 }
3948
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003949 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003950 int slotId = SubscriptionManager.getSlotIndex(subId);
3951 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003952 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3953 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003954 }
3955 return slotId;
3956 }
3957
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003958 private int getSlotIndex(int subId) {
3959 int slotId = SubscriptionManager.getSlotIndex(subId);
3960 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3961 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3962 }
3963 return slotId;
3964 }
3965
Wink Saville36469e72014-06-11 15:17:00 -07003966 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003967 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003968 */
3969 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003970 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3971 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003972 final int targetSdk = getTargetSdk(callingPackage);
3973 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003974 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003975 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003976 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003977 mApp, subId, callingPackage, callingFeatureId,
3978 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003979 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3980 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003981
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().getDataNetworkType();
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 * Returns the data network type
3997 */
3998 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003999 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4000 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4001 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004002 }
4003
4004 /**
4005 * Returns the data network type for a subId
4006 */
4007 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004008 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4009 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004010 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004011 mApp, subId, callingPackage, callingFeatureId,
4012 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004013 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4014 }
4015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 final Phone phone = getPhone(subId);
4019 if (phone != null) {
4020 return phone.getServiceState().getDataNetworkType();
4021 } else {
4022 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4023 }
4024 } finally {
4025 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004026 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004027 }
4028
4029 /**
Wink Saville36469e72014-06-11 15:17:00 -07004030 * Returns the Voice network type for a subId
4031 */
4032 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004033 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4034 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004036 mApp, subId, callingPackage, callingFeatureId,
4037 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004038 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4039 }
4040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004041 final long identity = Binder.clearCallingIdentity();
4042 try {
4043 final Phone phone = getPhone(subId);
4044 if (phone != null) {
4045 return phone.getServiceState().getVoiceNetworkType();
4046 } else {
4047 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4048 }
4049 } finally {
4050 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004051 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004052 }
4053
4054 /**
4055 * @return true if a ICC card is present
4056 */
4057 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004058 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004059 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4060 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004061 }
4062
4063 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004064 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004065 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004066 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004067 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 final Phone phone = PhoneFactory.getPhone(slotIndex);
4071 if (phone != null) {
4072 return phone.getIccCard().hasIccCard();
4073 } else {
4074 return false;
4075 }
4076 } finally {
4077 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004078 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004079 }
4080
4081 /**
4082 * Return if the current radio is LTE on CDMA. This
4083 * is a tri-state return value as for a period of time
4084 * the mode may be unknown.
4085 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004086 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004087 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004088 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004089 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004090 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004091 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4092 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4093 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004094 }
4095
Sanket Padawe356d7632015-06-22 14:03:32 -07004096 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004097 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4098 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004100 mApp, subId, callingPackage, callingFeatureId,
4101 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004102 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4103 }
4104
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004105 final long identity = Binder.clearCallingIdentity();
4106 try {
4107 final Phone phone = getPhone(subId);
4108 if (phone == null) {
4109 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4110 } else {
4111 return phone.getLteOnCdmaMode();
4112 }
4113 } finally {
4114 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004115 }
Wink Saville36469e72014-06-11 15:17:00 -07004116 }
4117
Wink Saville36469e72014-06-11 15:17:00 -07004118 /**
4119 * {@hide}
4120 * Returns Default subId, 0 in the case of single standby.
4121 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004122 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004123 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004124 }
4125
Shishir Agrawala9f32182016-04-12 12:00:16 -07004126 private int getSlotForDefaultSubscription() {
4127 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4128 }
4129
Wink Savilleb564aae2014-10-23 10:18:09 -07004130 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004131 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004132 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004133
Pengquan Menge92a50d2018-09-21 15:54:48 -07004134 private boolean isActiveSubscription(int subId) {
4135 return mSubscriptionController.isActiveSubId(subId);
4136 }
4137
Ihab Awadf2177b72013-11-25 13:33:23 -08004138 /**
4139 * @see android.telephony.TelephonyManager.WifiCallingChoices
4140 */
4141 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004142 final long identity = Binder.clearCallingIdentity();
4143 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004144 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004145 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4146 getWhenToMakeWifiCallsDefaultPreference());
4147 } finally {
4148 Binder.restoreCallingIdentity(identity);
4149 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004150 }
4151
4152 /**
4153 * @see android.telephony.TelephonyManager.WifiCallingChoices
4154 */
4155 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004156 final long identity = Binder.clearCallingIdentity();
4157 try {
4158 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004159 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4161 } finally {
4162 Binder.restoreCallingIdentity(identity);
4163 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004164 }
4165
Sailesh Nepald1e68152013-12-12 19:08:02 -08004166 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004167 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004168 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004169 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004170
Jordan Liu4c733742019-02-28 12:03:40 -08004171 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4172 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4173 if (phoneId == -1) {
4174 throw new IllegalArgumentException("Given slot index: " + slotIndex
4175 + " does not correspond to an active phone");
4176 }
4177 return PhoneFactory.getPhone(phoneId);
4178 }
4179
Shishir Agrawal566b7612013-10-28 14:41:00 -07004180 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004181 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4182 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4184 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004185 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004186 if (DBG) {
4187 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4188 }
4189 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4190 p2);
4191 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004192
Jordan Liu4c733742019-02-28 12:03:40 -08004193
4194 @Override
4195 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4196 int slotIndex, String callingPackage, String aid, int p2) {
4197 enforceModifyPermission();
4198 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4199 if (DBG) {
4200 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4201 }
4202 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4203 callingPackage, aid, p2);
4204 }
4205
4206 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4207 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004208 final long identity = Binder.clearCallingIdentity();
4209 try {
4210 if (TextUtils.equals(ISDR_AID, aid)) {
4211 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004212 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4213 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214 if (bestComponent == null
4215 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4216 loge("The calling package is not allowed to access ISD-R.");
4217 throw new SecurityException(
4218 "The calling package is not allowed to access ISD-R.");
4219 }
Derek Tan740e1672017-06-27 14:56:27 -07004220 }
Derek Tan740e1672017-06-27 14:56:27 -07004221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004222 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004223 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4224 null /* workSource */);
4225 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226 return response;
4227 } finally {
4228 Binder.restoreCallingIdentity(identity);
4229 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004230 }
4231
4232 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004233 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4235 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004236 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4237 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4238 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004239
Jordan Liu4c733742019-02-28 12:03:40 -08004240 @Override
4241 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4242 enforceModifyPermission();
4243 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4244 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4245 channel);
4246 }
4247
4248 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004249 final long identity = Binder.clearCallingIdentity();
4250 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004251 if (channel < 0) {
4252 return false;
4253 }
Jordan Liu4c733742019-02-28 12:03:40 -08004254 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4255 null /* workSource */);
4256 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257 return success;
4258 } finally {
4259 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004260 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004261 }
4262
4263 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004264 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004265 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4267 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004268 if (DBG) {
4269 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4270 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4271 + p3 + " data=" + data);
4272 }
4273 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4274 command, p1, p2, p3, data);
4275 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004276
Jordan Liu4c733742019-02-28 12:03:40 -08004277 @Override
4278 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4279 int command, int p1, int p2, int p3, String data) {
4280 enforceModifyPermission();
4281 if (DBG) {
4282 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4283 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4284 + p3 + " data=" + data);
4285 }
4286 return iccTransmitApduLogicalChannelWithPermission(
4287 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4288 data);
4289 }
4290
4291 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4292 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 final long identity = Binder.clearCallingIdentity();
4294 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004295 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296 return "";
4297 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004299 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004300 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4301 null /* workSource */);
4302 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004304 // Append the returned status code to the end of the response payload.
4305 String s = Integer.toHexString(
4306 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4307 if (response.payload != null) {
4308 s = IccUtils.bytesToHexString(response.payload) + s;
4309 }
4310 return s;
4311 } finally {
4312 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004313 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004314 }
Jake Hambye994d462014-02-03 13:10:13 -08004315
Evan Charltonc66da362014-05-16 14:06:40 -07004316 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004317 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4318 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4320 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004321 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004322 if (DBG) {
4323 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4324 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4325 }
4326 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4327 cla, command, p1, p2, p3, data);
4328 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004329
Jordan Liu4c733742019-02-28 12:03:40 -08004330 @Override
4331 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4332 int command, int p1, int p2, int p3, String data) {
4333 enforceModifyPermission();
4334 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4335 if (DBG) {
4336 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4337 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4338 + " data=" + data);
4339 }
4340
4341 return iccTransmitApduBasicChannelWithPermission(
4342 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4343 p2, p3, data);
4344 }
4345
4346 // open APDU basic channel assuming the caller has sufficient permissions
4347 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4348 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004349 final long identity = Binder.clearCallingIdentity();
4350 try {
4351 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4352 && TextUtils.equals(ISDR_AID, data)) {
4353 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004354 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4355 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356 if (bestComponent == null
4357 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4358 loge("The calling package is not allowed to select ISD-R.");
4359 throw new SecurityException(
4360 "The calling package is not allowed to select ISD-R.");
4361 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004362 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004364 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004365 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4366 null /* workSource */);
4367 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004369 // Append the returned status code to the end of the response payload.
4370 String s = Integer.toHexString(
4371 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4372 if (response.payload != null) {
4373 s = IccUtils.bytesToHexString(response.payload) + s;
4374 }
4375 return s;
4376 } finally {
4377 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004378 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004379 }
4380
4381 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004382 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004383 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4385 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387 final long identity = Binder.clearCallingIdentity();
4388 try {
4389 if (DBG) {
4390 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4391 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4392 }
4393
4394 IccIoResult response =
4395 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4396 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4397 subId);
4398
4399 if (DBG) {
4400 log("Exchange SIM_IO [R]" + response);
4401 }
4402
4403 byte[] result = null;
4404 int length = 2;
4405 if (response.payload != null) {
4406 length = 2 + response.payload.length;
4407 result = new byte[length];
4408 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4409 } else {
4410 result = new byte[length];
4411 }
4412
4413 result[length - 1] = (byte) response.sw2;
4414 result[length - 2] = (byte) response.sw1;
4415 return result;
4416 } finally {
4417 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004418 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004419 }
4420
Nathan Haroldb3014052017-01-25 15:57:32 -08004421 /**
4422 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4423 * on a particular subscription
4424 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004425 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4426 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004427 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004428 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004429 return null;
4430 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004431
4432 final long identity = Binder.clearCallingIdentity();
4433 try {
4434 if (appType != TelephonyManager.APPTYPE_USIM
4435 && appType != TelephonyManager.APPTYPE_SIM) {
4436 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4437 return null;
4438 }
4439 Object response = sendRequest(
4440 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4441 if (response instanceof String[]) {
4442 return (String[]) response;
4443 }
yincheng zhaod698b842019-09-06 17:06:54 -07004444 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004446 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 } finally {
4448 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004449 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004450 }
4451
yincheng zhaod698b842019-09-06 17:06:54 -07004452 /**
4453 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4454 * subscription.
4455 *
4456 * @param subId the id of the subscription.
4457 * @param appType the uicc app type, must be USIM or SIM.
4458 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4459 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004460 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004461 * @return number of fplmns that is successfully written to the SIM.
4462 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004463 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4464 String callingFeatureId) {
4465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4466 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004467 if (DBG) logv("no permissions for setForbiddenplmns");
4468 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4469 }
4470 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4471 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4472 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4473 }
4474 if (fplmns == null) {
4475 throw new IllegalArgumentException("Fplmn List provided is null");
4476 }
4477 for (String fplmn : fplmns) {
4478 if (!CellIdentity.isValidPlmn(fplmn)) {
4479 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4480 }
4481 }
4482 final long identity = Binder.clearCallingIdentity();
4483 try {
4484 Object response = sendRequest(
4485 CMD_SET_FORBIDDEN_PLMNS,
4486 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4487 subId);
4488 return (int) response;
4489 } finally {
4490 Binder.restoreCallingIdentity(identity);
4491 }
4492 }
4493
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004494 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004495 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4497 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499 final long identity = Binder.clearCallingIdentity();
4500 try {
4501 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4502 if (response.payload == null) {
4503 return "";
4504 }
Evan Charltonc66da362014-05-16 14:06:40 -07004505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004506 // Append the returned status code to the end of the response payload.
4507 String s = Integer.toHexString(
4508 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4509 s = IccUtils.bytesToHexString(response.payload) + s;
4510 return s;
4511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
Evan Charltonc66da362014-05-16 14:06:40 -07004514 }
4515
Jake Hambye994d462014-02-03 13:10:13 -08004516 /**
4517 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4518 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4519 *
4520 * @param itemID the ID of the item to read
4521 * @return the NV item as a String, or null on error.
4522 */
4523 @Override
4524 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004525 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4527 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528
4529 final long identity = Binder.clearCallingIdentity();
4530 try {
4531 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004532 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4534 return value;
4535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
Jake Hambye994d462014-02-03 13:10:13 -08004538 }
4539
4540 /**
4541 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4542 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4543 *
4544 * @param itemID the ID of the item to read
4545 * @param itemValue the value to write, as a String
4546 * @return true on success; false on any failure
4547 */
4548 @Override
4549 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004550 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4552 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553
4554 final long identity = Binder.clearCallingIdentity();
4555 try {
4556 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4557 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004558 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4560 return success;
4561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
Jake Hambye994d462014-02-03 13:10:13 -08004564 }
4565
4566 /**
4567 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4568 * Used for device configuration by some CDMA operators.
4569 *
4570 * @param preferredRoamingList byte array containing the new PRL
4571 * @return true on success; false on any failure
4572 */
4573 @Override
4574 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4576 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004577
4578 final long identity = Binder.clearCallingIdentity();
4579 try {
4580 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4581 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4582 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4583 return success;
4584 } finally {
4585 Binder.restoreCallingIdentity(identity);
4586 }
Jake Hambye994d462014-02-03 13:10:13 -08004587 }
4588
4589 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004590 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004591 * Used for device configuration by some CDMA operators.
4592 *
chen xu6dac5ab2018-10-26 17:39:23 -07004593 * @param slotIndex - device slot.
4594 *
Jake Hambye994d462014-02-03 13:10:13 -08004595 * @return true on success; false on any failure
4596 */
4597 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004598 public boolean resetModemConfig(int slotIndex) {
4599 Phone phone = PhoneFactory.getPhone(slotIndex);
4600 if (phone != null) {
4601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4602 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004603
chen xu6dac5ab2018-10-26 17:39:23 -07004604 final long identity = Binder.clearCallingIdentity();
4605 try {
4606 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4607 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4608 return success;
4609 } finally {
4610 Binder.restoreCallingIdentity(identity);
4611 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004612 }
chen xu6dac5ab2018-10-26 17:39:23 -07004613 return false;
4614 }
4615
4616 /**
4617 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4618 *
4619 * @param slotIndex - device slot.
4620 *
4621 * @return true on success; false on any failure
4622 */
4623 @Override
4624 public boolean rebootModem(int slotIndex) {
4625 Phone phone = PhoneFactory.getPhone(slotIndex);
4626 if (phone != null) {
4627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4628 mApp, phone.getSubId(), "rebootModem");
4629
4630 final long identity = Binder.clearCallingIdentity();
4631 try {
4632 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4633 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4634 return success;
4635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
4638 }
4639 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004640 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004641
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004642 public String[] getPcscfAddress(String apnType, String callingPackage,
4643 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004644 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004645 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4646 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004647 return new String[0];
4648 }
4649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650 final long identity = Binder.clearCallingIdentity();
4651 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004652 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 } finally {
4654 Binder.restoreCallingIdentity(identity);
4655 }
Wink Saville36469e72014-06-11 15:17:00 -07004656 }
4657
Brad Ebinger51f743a2017-01-23 13:50:20 -08004658 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004659 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4660 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004661 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004662 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004663 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664
4665 final long identity = Binder.clearCallingIdentity();
4666 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004667 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004668 // may happen if the device does not support IMS.
4669 return;
4670 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004671 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004672 } finally {
4673 Binder.restoreCallingIdentity(identity);
4674 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004675 }
4676
4677 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004678 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4679 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004680 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004681 public void disableIms(int slotId) {
4682 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683
4684 final long identity = Binder.clearCallingIdentity();
4685 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004686 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004687 // may happen if the device does not support IMS.
4688 return;
4689 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004690 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691 } finally {
4692 Binder.restoreCallingIdentity(identity);
4693 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004694 }
4695
4696 /**
4697 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4698 * feature or {@link null} if the service is not available. If the feature is available, the
4699 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4700 */
4701 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004702 IImsServiceFeatureCallback callback) {
4703 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704
4705 final long identity = Binder.clearCallingIdentity();
4706 try {
Brad Ebinger05f52c22019-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 Ebinger05f52c22019-12-05 13:03:21 -08004711 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004712 } finally {
4713 Binder.restoreCallingIdentity(identity);
4714 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004715 }
4716
4717 /**
4718 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4719 * feature during emergency calling or {@link null} if the service is not available. If the
4720 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4721 * listener for feature updates.
4722 */
4723 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4724 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004725
4726 final long identity = Binder.clearCallingIdentity();
4727 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004728 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004729 // may happen if the device does not support IMS.
4730 return null;
4731 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004732 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004733 } finally {
4734 Binder.restoreCallingIdentity(identity);
4735 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004736 }
4737
Brad Ebinger5f64b052017-12-14 14:26:15 -08004738 /**
4739 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004740 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004741 */
4742 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4743 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744
4745 final long identity = Binder.clearCallingIdentity();
4746 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004747 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004748 // may happen if the device does not support IMS.
4749 return null;
4750 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004751 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004752 } finally {
4753 Binder.restoreCallingIdentity(identity);
4754 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004755 }
4756
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004757 /**
4758 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004759 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004760 */
4761 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763
4764 final long identity = Binder.clearCallingIdentity();
4765 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004766 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004767 // may happen if the device does not support IMS.
4768 return null;
4769 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004770 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004771 } finally {
4772 Binder.restoreCallingIdentity(identity);
4773 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004774 }
4775
Brad Ebinger884c07b2018-02-15 16:17:40 -08004776 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004777 * Sets the ImsService Package Name that Telephony will bind to.
4778 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004779 * @param slotIndex the slot ID that the ImsService should bind for.
4780 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004781 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004782 * @param featureTypes An integer array of feature types associated with a packageName.
4783 * @param packageName The name of the package that the current configuration will be replaced
4784 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004785 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004786 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004787 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4788 int[] featureTypes, String packageName) {
4789 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4790 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4792 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004793 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004795 final long identity = Binder.clearCallingIdentity();
4796 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004797 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004798 // may happen if the device does not support IMS.
4799 return false;
4800 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004801 Map<Integer, String> featureConfig = new HashMap<>();
4802 for (int featureType : featureTypes) {
4803 featureConfig.put(featureType, packageName);
4804 }
4805 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4806 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004807 } finally {
4808 Binder.restoreCallingIdentity(identity);
4809 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004810 }
4811
4812 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08004813 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004814 *
4815 * @param slotId The slot that the ImsService is associated with.
4816 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4817 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004818 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004819 * @return the package name of the ImsService configuration.
4820 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004821 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4822 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004823 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08004824 TelephonyPermissions
4825 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4826 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4827 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004829 final long identity = Binder.clearCallingIdentity();
4830 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004831 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004832 // may happen if the device does not support IMS.
4833 return "";
4834 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004835 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004836 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4837 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004838 } finally {
4839 Binder.restoreCallingIdentity(identity);
4840 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004841 }
4842
Brad Ebinger77b832e2019-10-17 17:03:22 -07004843 /**
4844 * Get the MmTelFeature state associated with the requested subscription id.
4845 * @param subId The subscription that the MmTelFeature is associated with.
4846 * @param callback A callback with an integer containing the
4847 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4848 */
4849 @Override
4850 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4851 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4852 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4853 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4854 "IMS not available on device.");
4855 }
4856 final long token = Binder.clearCallingIdentity();
4857 try {
4858 int slotId = getSlotIndex(subId);
4859 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4860 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4861 + subId + "'");
4862 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4863 }
4864 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4865 try {
4866 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4867 } catch (RemoteException e) {
4868 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4869 + "Ignore");
4870 }
4871 });
4872 } finally {
4873 Binder.restoreCallingIdentity(token);
4874 }
4875 }
4876
Wink Saville36469e72014-06-11 15:17:00 -07004877 public void setImsRegistrationState(boolean registered) {
4878 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004879
4880 final long identity = Binder.clearCallingIdentity();
4881 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004882 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004883 } finally {
4884 Binder.restoreCallingIdentity(identity);
4885 }
Wink Saville36469e72014-06-11 15:17:00 -07004886 }
4887
4888 /**
Stuart Scott54788802015-03-30 13:18:01 -07004889 * Set the network selection mode to automatic.
4890 *
4891 */
4892 @Override
4893 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4895 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004896
4897 final long identity = Binder.clearCallingIdentity();
4898 try {
shilufc958392020-01-20 11:36:01 -08004899 if (!isActiveSubscription(subId)) {
4900 return;
4901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4903 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4904 } finally {
4905 Binder.restoreCallingIdentity(identity);
4906 }
Stuart Scott54788802015-03-30 13:18:01 -07004907 }
4908
Pengquan Mengea84e042018-09-20 14:57:26 -07004909 /**
4910 * Ask the radio to connect to the input network and change selection mode to manual.
4911 *
4912 * @param subId the id of the subscription.
4913 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4914 * the operator to attach to.
4915 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4916 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4917 * normal network selection next time.
4918 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004919 */
4920 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004921 public boolean setNetworkSelectionModeManual(
4922 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4924 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004925
4926 if (!isActiveSubscription(subId)) {
4927 return false;
4928 }
4929
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004930 final long identity = Binder.clearCallingIdentity();
4931 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004932 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004934 if (DBG) {
4935 log("setNetworkSelectionModeManual: subId: " + subId
4936 + " operator: " + operatorInfo);
4937 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004938 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4939 } finally {
4940 Binder.restoreCallingIdentity(identity);
4941 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004942 }
4943
4944 /**
4945 * Scans for available networks.
4946 */
4947 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004948 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4949 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4951 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004952 LocationAccessPolicy.LocationPermissionResult locationResult =
4953 LocationAccessPolicy.checkLocationPermission(mApp,
4954 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4955 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004956 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004957 .setCallingPid(Binder.getCallingPid())
4958 .setCallingUid(Binder.getCallingUid())
4959 .setMethod("getCellNetworkScanResults")
4960 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4961 .build());
4962 switch (locationResult) {
4963 case DENIED_HARD:
4964 throw new SecurityException("Not allowed to access scan results -- location");
4965 case DENIED_SOFT:
4966 return null;
4967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968
Pengquan Menga1bb6272018-09-06 09:59:22 -07004969 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 try {
4971 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004972 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 } finally {
4975 Binder.restoreCallingIdentity(identity);
4976 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004977 }
4978
4979 /**
yinxub1bed742017-04-17 11:45:04 -07004980 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004981 *
yinxub1bed742017-04-17 11:45:04 -07004982 * @param subId id of the subscription
4983 * @param request contains the radio access networks with bands/channels to scan
4984 * @param messenger callback messenger for scan results or errors
4985 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004986 * @return the id of the requested scan which can be used to stop the scan.
4987 */
4988 @Override
4989 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004990 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4992 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004993 LocationAccessPolicy.LocationPermissionResult locationResult =
4994 LocationAccessPolicy.checkLocationPermission(mApp,
4995 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4996 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004997 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004998 .setCallingPid(Binder.getCallingPid())
4999 .setCallingUid(Binder.getCallingUid())
5000 .setMethod("requestNetworkScan")
5001 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5002 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005003 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005004 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005005 if (e != null) {
5006 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5007 throw e;
5008 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005009 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005010 return TelephonyScanManager.INVALID_SCAN_ID;
5011 }
5012 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 }
Hall Liu912dfd32019-04-25 14:02:26 -07005014 int callingUid = Binder.getCallingUid();
5015 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005016 final long identity = Binder.clearCallingIdentity();
5017 try {
5018 return mNetworkScanRequestTracker.startNetworkScan(
5019 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005020 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005021 } finally {
5022 Binder.restoreCallingIdentity(identity);
5023 }
yinxu504e1392017-04-12 16:03:22 -07005024 }
5025
Hall Liub2ac8ef2019-02-28 15:56:23 -08005026 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005027 NetworkScanRequest request, int subId) {
5028 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5029 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5030 boolean hasNetworkScanPermission =
5031 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5032 == PERMISSION_GRANTED;
5033
5034 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5035 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5036 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005037 }
5038
5039 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5040 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005041 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5042 return new SecurityException("Specific channels must not be"
5043 + " scanned without location access.");
5044 }
5045 }
5046 }
5047
Hall Liub2ac8ef2019-02-28 15:56:23 -08005048 return null;
5049 }
5050
yinxu504e1392017-04-12 16:03:22 -07005051 /**
5052 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005053 *
5054 * @param subId id of the subscription
5055 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005056 */
5057 @Override
5058 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5060 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005061
Hall Liu912dfd32019-04-25 14:02:26 -07005062 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063 final long identity = Binder.clearCallingIdentity();
5064 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005065 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 } finally {
5067 Binder.restoreCallingIdentity(identity);
5068 }
yinxu504e1392017-04-12 16:03:22 -07005069 }
5070
5071 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005072 * Get the calculated preferred network type.
5073 * Used for debugging incorrect network type.
5074 *
5075 * @return the preferred network type, defined in RILConstants.java.
5076 */
5077 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005078 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005079 final Phone defaultPhone = getDefaultPhone();
5080 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005081 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005082 return RILConstants.PREFERRED_NETWORK_MODE;
5083 }
5084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 final long identity = Binder.clearCallingIdentity();
5086 try {
5087 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005088 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 } finally {
5090 Binder.restoreCallingIdentity(identity);
5091 }
Junda Liu84d15a22014-07-02 11:21:04 -07005092 }
5093
5094 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005095 * Get the preferred network type.
5096 * Used for device configuration by some CDMA operators.
5097 *
5098 * @return the preferred network type, defined in RILConstants.java.
5099 */
5100 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005101 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005102 TelephonyPermissions
5103 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5104 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105
5106 final long identity = Binder.clearCallingIdentity();
5107 try {
5108 if (DBG) log("getPreferredNetworkType");
5109 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5110 int networkType = (result != null ? result[0] : -1);
5111 if (DBG) log("getPreferredNetworkType: " + networkType);
5112 return networkType;
5113 } finally {
5114 Binder.restoreCallingIdentity(identity);
5115 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005116 }
5117
5118 /**
5119 * Set the preferred network type.
5120 * Used for device configuration by some CDMA operators.
5121 *
5122 * @param networkType the preferred network type, defined in RILConstants.java.
5123 * @return true on success; false on any failure.
5124 */
5125 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005126 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005127 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5128 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005129
5130 final long identity = Binder.clearCallingIdentity();
5131 try {
5132 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
5133 Boolean success = (Boolean) sendRequest(
5134 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5135 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5136 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005137 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5139 }
5140 return success;
5141 } finally {
5142 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005143 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005144 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005145
5146 /**
Miaoa84611c2019-03-15 09:21:10 +08005147 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005148 *
Miaoa84611c2019-03-15 09:21:10 +08005149 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005150 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005151 * @hide
5152 */
5153 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005154 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005155 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005157 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 try {
Miaoa84611c2019-03-15 09:21:10 +08005159 if (phone != null) {
5160 return phone.hasMatchedTetherApnSetting();
5161 } else {
5162 return false;
5163 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164 } finally {
5165 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005166 }
Junda Liu475951f2014-11-07 16:45:03 -08005167 }
5168
5169 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005170 * Set mobile data enabled
5171 * Used by the user through settings etc to turn on/off mobile data
5172 *
5173 * @param enable {@code true} turn turn data on, else {@code false}
5174 */
5175 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005176 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5178 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179
5180 final long identity = Binder.clearCallingIdentity();
5181 try {
5182 int phoneId = mSubscriptionController.getPhoneId(subId);
5183 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5184 Phone phone = PhoneFactory.getPhone(phoneId);
5185 if (phone != null) {
5186 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005187 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005189 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 }
5191 } finally {
5192 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005193 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005194 }
5195
5196 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005197 * Get the user enabled state of Mobile Data.
5198 *
5199 * TODO: remove and use isUserDataEnabled.
5200 * This can't be removed now because some vendor codes
5201 * calls through ITelephony directly while they should
5202 * use TelephonyManager.
5203 *
5204 * @return true on enabled
5205 */
5206 @Override
5207 public boolean getDataEnabled(int subId) {
5208 return isUserDataEnabled(subId);
5209 }
5210
5211 /**
5212 * Get whether mobile data is enabled per user setting.
5213 *
5214 * There are other factors deciding whether mobile data is actually enabled, but they are
5215 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005216 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005217 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005218 *
5219 * @return {@code true} if data is enabled else {@code false}
5220 */
5221 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005222 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005223 try {
5224 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5225 null);
5226 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005227 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5228 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230
5231 final long identity = Binder.clearCallingIdentity();
5232 try {
5233 int phoneId = mSubscriptionController.getPhoneId(subId);
5234 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5235 Phone phone = PhoneFactory.getPhone(phoneId);
5236 if (phone != null) {
5237 boolean retVal = phone.isUserDataEnabled();
5238 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5239 return retVal;
5240 } else {
5241 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5242 return false;
5243 }
5244 } finally {
5245 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005246 }
5247 }
5248
5249 /**
5250 * Get whether mobile data is enabled.
5251 *
5252 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5253 * whether mobile data is actually enabled.
5254 *
5255 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5256 *
5257 * @return {@code true} if data is enabled else {@code false}
5258 */
5259 @Override
5260 public boolean isDataEnabled(int subId) {
5261 try {
5262 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5263 null);
5264 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5266 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005267 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268
5269 final long identity = Binder.clearCallingIdentity();
5270 try {
5271 int phoneId = mSubscriptionController.getPhoneId(subId);
5272 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5273 Phone phone = PhoneFactory.getPhone(phoneId);
5274 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005275 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5277 return retVal;
5278 } else {
5279 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5280 return false;
5281 }
5282 } finally {
5283 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005284 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005285 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005286
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005287 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5288 Phone phone) {
5289 //load access rules from carrier configs, and check those as well: b/139133814
5290 SubscriptionController subController = SubscriptionController.getInstance();
5291 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5292 || subController == null) return privilegeFromSim;
5293
5294 int uid = Binder.getCallingUid();
5295 PackageManager pkgMgr = phone.getContext().getPackageManager();
5296 String[] packages = pkgMgr.getPackagesForUid(uid);
5297
5298 final long identity = Binder.clearCallingIdentity();
5299 try {
5300 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5301 SubscriptionManager subManager = (SubscriptionManager)
5302 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5303 for (String pkg : packages) {
5304 if (subManager.canManageSubscription(subInfo, pkg)) {
5305 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5306 }
5307 }
5308 return privilegeFromSim;
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
5311 }
5312 }
5313
5314 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5315 String pkgName) {
5316 //load access rules from carrier configs, and check those as well: b/139133814
5317 SubscriptionController subController = SubscriptionController.getInstance();
5318 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5319 || subController == null) return privilegeFromSim;
5320
5321 final long identity = Binder.clearCallingIdentity();
5322 try {
5323 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5324 SubscriptionManager subManager = (SubscriptionManager)
5325 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5326 return subManager.canManageSubscription(subInfo, pkgName)
5327 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5328 } finally {
5329 Binder.restoreCallingIdentity(identity);
5330 }
5331 }
5332
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005333 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005334 public int getCarrierPrivilegeStatus(int subId) {
5335 final Phone phone = getPhone(subId);
5336 if (phone == null) {
5337 loge("getCarrierPrivilegeStatus: Invalid subId");
5338 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5339 }
5340 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005341 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005342 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005343 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5344 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005345
5346 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5347 card.getCarrierPrivilegeStatusForCurrentTransaction(
5348 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005349 }
Junda Liu29340342014-07-10 15:23:27 -07005350
5351 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005352 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005353 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005354 final Phone phone = getPhone(subId);
5355 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005356 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005357 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5358 }
5359 UiccProfile profile =
5360 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5361 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005362 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005363 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5364 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005365 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005366 profile.getCarrierPrivilegeStatusForUid(
5367 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005368 }
5369
5370 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005371 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5372 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005373 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005374 }
5375
5376 int phoneId = SubscriptionManager.getPhoneId(subId);
5377 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005378 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005379 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005380 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5381 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005382 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5383 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5384 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005385 }
5386
5387 @Override
5388 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005389 if (TextUtils.isEmpty(pkgName))
5390 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005391 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5392 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5393 UiccCard card = UiccController.getInstance().getUiccCard(i);
5394 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005395 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005396 continue;
5397 }
5398
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005399 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5400 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5401 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005402 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5403 break;
5404 }
5405 }
5406
5407 return result;
Junda Liu29340342014-07-10 15:23:27 -07005408 }
Derek Tan89e89d42014-07-08 17:00:10 -07005409
5410 @Override
Junda Liue64de782015-04-16 17:19:16 -07005411 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5412 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5413 loge("phoneId " + phoneId + " is not valid.");
5414 return null;
5415 }
5416 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005417 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005418 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005419 return null ;
5420 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005421 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005422 }
5423
Amith Yamasani6e118872016-02-19 12:53:51 -08005424 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005425 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005426 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005427 List<String> privilegedPackages = new ArrayList<>();
5428 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005429 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5430 // has UICC in that slot.
5431 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005432 if (card.hasCarrierPrivilegeRules()) {
5433 if (packages == null) {
5434 // Only check packages in user 0 for now
5435 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005436 PackageManager.MATCH_DISABLED_COMPONENTS
5437 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005438 | PackageManager.GET_SIGNING_CERTIFICATES,
5439 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005440 }
5441 for (int p = packages.size() - 1; p >= 0; p--) {
5442 PackageInfo pkgInfo = packages.get(p);
5443 if (pkgInfo != null && pkgInfo.packageName != null
5444 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005445 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005446 privilegedPackages.add(pkgInfo.packageName);
5447 }
5448 }
5449 }
5450 }
5451 return privilegedPackages;
5452 }
5453
chen xuf7e9fe82019-05-09 19:31:02 -07005454 @Override
5455 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005456 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5457
5458 final long identity = Binder.clearCallingIdentity();
5459
chen xuf7e9fe82019-05-09 19:31:02 -07005460 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005461 try {
5462 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5463 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5464 }
5465 } finally {
5466 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005467 }
5468 return privilegedPackages;
5469 }
5470
Wink Savilleb564aae2014-10-23 10:18:09 -07005471 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005472 final Phone phone = getPhone(subId);
5473 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005474 if (card == null) {
5475 loge("getIccId: No UICC");
5476 return null;
5477 }
5478 String iccId = card.getIccId();
5479 if (TextUtils.isEmpty(iccId)) {
5480 loge("getIccId: ICC ID is null or empty.");
5481 return null;
5482 }
5483 return iccId;
5484 }
5485
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005486 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005487 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5488 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005489 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005490 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005491
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492 final long identity = Binder.clearCallingIdentity();
5493 try {
5494 final String iccId = getIccId(subId);
5495 final Phone phone = getPhone(subId);
5496 if (phone == null) {
5497 return false;
5498 }
5499 final String subscriberId = phone.getSubscriberId();
5500
5501 if (DBG_MERGE) {
5502 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5503 + subscriberId + " to " + number);
5504 }
5505
5506 if (TextUtils.isEmpty(iccId)) {
5507 return false;
5508 }
5509
5510 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5511
5512 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5513 if (alphaTag == null) {
5514 editor.remove(alphaTagPrefKey);
5515 } else {
5516 editor.putString(alphaTagPrefKey, alphaTag);
5517 }
5518
5519 // Record both the line number and IMSI for this ICCID, since we need to
5520 // track all merged IMSIs based on line number
5521 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5522 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5523 if (number == null) {
5524 editor.remove(numberPrefKey);
5525 editor.remove(subscriberPrefKey);
5526 } else {
5527 editor.putString(numberPrefKey, number);
5528 editor.putString(subscriberPrefKey, subscriberId);
5529 }
5530
5531 editor.commit();
5532 return true;
5533 } finally {
5534 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005535 }
Derek Tan7226c842014-07-02 17:42:23 -07005536 }
5537
5538 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005539 public String getLine1NumberForDisplay(int subId, String callingPackage,
5540 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005541 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005543 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005544 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005545 return null;
5546 }
Derek Tan97ebb422014-09-05 16:55:38 -07005547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548 final long identity = Binder.clearCallingIdentity();
5549 try {
5550 String iccId = getIccId(subId);
5551 if (iccId != null) {
5552 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5553 if (DBG_MERGE) {
5554 log("getLine1NumberForDisplay returning "
5555 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5556 }
5557 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005558 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5560 return null;
5561 } finally {
5562 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005563 }
Derek Tan7226c842014-07-02 17:42:23 -07005564 }
5565
5566 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005567 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5568 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005570 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005571 return null;
5572 }
Derek Tan97ebb422014-09-05 16:55:38 -07005573
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 final long identity = Binder.clearCallingIdentity();
5575 try {
5576 String iccId = getIccId(subId);
5577 if (iccId != null) {
5578 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5579 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5580 }
5581 return null;
5582 } finally {
5583 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005584 }
Derek Tan7226c842014-07-02 17:42:23 -07005585 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005586
5587 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005588 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5589 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005590 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5591 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005593 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005594 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005595 return null;
5596 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005597
Jordan Liub49b04b2019-05-06 14:45:15 -07005598 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5599 // the process, where TelephonyManager was instantiated.
5600 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005601 final long identity = Binder.clearCallingIdentity();
5602 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005603 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604 final TelephonyManager tele = TelephonyManager.from(context);
5605 final SubscriptionManager sub = SubscriptionManager.from(context);
5606
5607 // Figure out what subscribers are currently active
5608 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609
Jordan Liub49b04b2019-05-06 14:45:15 -07005610 // Only consider subs which match the current subId
5611 // This logic can be simplified. See b/131189269 for progress.
5612 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005613 activeSubscriberIds.add(tele.getSubscriberId(subId));
5614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615
5616 // First pass, find a number override for an active subscriber
5617 String mergeNumber = null;
5618 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5619 for (String key : prefs.keySet()) {
5620 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5621 final String subscriberId = (String) prefs.get(key);
5622 if (activeSubscriberIds.contains(subscriberId)) {
5623 final String iccId = key.substring(
5624 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5625 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5626 mergeNumber = (String) prefs.get(numberKey);
5627 if (DBG_MERGE) {
5628 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5629 + " for active subscriber " + subscriberId);
5630 }
5631 if (!TextUtils.isEmpty(mergeNumber)) {
5632 break;
5633 }
5634 }
5635 }
5636 }
5637
5638 // Shortcut when no active merged subscribers
5639 if (TextUtils.isEmpty(mergeNumber)) {
5640 return null;
5641 }
5642
5643 // Second pass, find all subscribers under that line override
5644 final ArraySet<String> result = new ArraySet<>();
5645 for (String key : prefs.keySet()) {
5646 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5647 final String number = (String) prefs.get(key);
5648 if (mergeNumber.equals(number)) {
5649 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5650 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5651 final String subscriberId = (String) prefs.get(subscriberKey);
5652 if (!TextUtils.isEmpty(subscriberId)) {
5653 result.add(subscriberId);
5654 }
5655 }
5656 }
5657 }
5658
5659 final String[] resultArray = result.toArray(new String[result.size()]);
5660 Arrays.sort(resultArray);
5661 if (DBG_MERGE) {
5662 Slog.d(LOG_TAG,
5663 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5664 }
5665 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005666 } finally {
5667 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005668 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005669 }
5670
5671 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005672 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5673 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5674
5675 final long identity = Binder.clearCallingIdentity();
5676 try {
5677 final TelephonyManager telephonyManager = mApp.getSystemService(
5678 TelephonyManager.class);
5679 String subscriberId = telephonyManager.getSubscriberId(subId);
5680 if (subscriberId == null) {
5681 if (DBG) {
5682 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5683 + subId);
5684 }
5685 return null;
5686 }
5687
5688 final SubscriptionInfo info = SubscriptionController.getInstance()
5689 .getSubscriptionInfo(subId);
5690 final ParcelUuid groupUuid = info.getGroupUuid();
5691 // If it doesn't belong to any group, return just subscriberId of itself.
5692 if (groupUuid == null) {
5693 return new String[]{subscriberId};
5694 }
5695
5696 // Get all subscriberIds from the group.
5697 final List<String> mergedSubscriberIds = new ArrayList<>();
5698 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005699 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5700 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07005701 for (SubscriptionInfo subInfo : groupInfos) {
5702 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5703 if (subscriberId != null) {
5704 mergedSubscriberIds.add(subscriberId);
5705 }
5706 }
5707
5708 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711
5712 }
5713 }
5714
5715 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005716 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08005717 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005718 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719
5720 final long identity = Binder.clearCallingIdentity();
5721 try {
5722 final Phone phone = getPhone(subId);
5723 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5724 } finally {
5725 Binder.restoreCallingIdentity(identity);
5726 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005727 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005728
5729 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005730 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005731 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5732 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08005733 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5734 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735
5736 final long identity = Binder.clearCallingIdentity();
5737 try {
5738 final Phone phone = getPhone(subId);
5739 if (phone == null) {
5740 return false;
5741 }
5742 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5743 cdmaNonRoamingList);
5744 } finally {
5745 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005746 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005747 }
5748
5749 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005750 @Deprecated
5751 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5752 enforceModifyPermission();
5753
5754 int returnValue = 0;
5755 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005756 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005757 if(result.exception == null) {
5758 if (result.result != null) {
5759 byte[] responseData = (byte[])(result.result);
5760 if(responseData.length > oemResp.length) {
5761 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5762 responseData.length + "bytes. Buffer Size is " +
5763 oemResp.length + "bytes.");
5764 }
5765 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5766 returnValue = responseData.length;
5767 }
5768 } else {
5769 CommandException ex = (CommandException) result.exception;
5770 returnValue = ex.getCommandError().ordinal();
5771 if(returnValue > 0) returnValue *= -1;
5772 }
5773 } catch (RuntimeException e) {
5774 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5775 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5776 if(returnValue > 0) returnValue *= -1;
5777 }
5778
5779 return returnValue;
5780 }
5781
5782 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005783 public void setRadioCapability(RadioAccessFamily[] rafs) {
5784 try {
5785 ProxyController.getInstance().setRadioCapability(rafs);
5786 } catch (RuntimeException e) {
5787 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5788 }
5789 }
5790
5791 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005792 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005793 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005794 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005795 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005796 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798 final long identity = Binder.clearCallingIdentity();
5799 try {
chen xub97461a2018-10-26 14:17:57 -07005800 TelephonyPermissions
5801 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5802 mApp, phone.getSubId(), "getRadioAccessFamily");
5803 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 } finally {
5805 Binder.restoreCallingIdentity(identity);
5806 }
chen xub97461a2018-10-26 14:17:57 -07005807 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005808 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005809
5810 @Override
5811 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005812 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005813 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814
5815 final long identity = Binder.clearCallingIdentity();
5816 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005817 ImsManager.getInstance(defaultPhone.getContext(),
5818 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819 } finally {
5820 Binder.restoreCallingIdentity(identity);
5821 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005822 }
5823
5824 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005825 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005826 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5828 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005829 return false;
5830 }
Svet Ganovb320e182015-04-16 12:30:10 -07005831
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832 final long identity = Binder.clearCallingIdentity();
5833 try {
5834 // Check the user preference and the system-level IMS setting. Even if the user has
5835 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5836 // In the long run, we may instead need to check if there exists a connection service
5837 // which can support video calling.
5838 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005839 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005840 return imsManager.isVtEnabledByPlatform()
5841 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5842 && imsManager.isVtEnabledByUser();
5843 } finally {
5844 Binder.restoreCallingIdentity(identity);
5845 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005846 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005847
Andrew Leea1239f22015-03-02 17:44:07 -08005848 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005849 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5850 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005852 mApp, subId, callingPackage, callingFeatureId,
5853 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005854 return false;
5855 }
5856
5857 final long identity = Binder.clearCallingIdentity();
5858 try {
5859 CarrierConfigManager configManager =
5860 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005861 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005862 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5863 } finally {
5864 Binder.restoreCallingIdentity(identity);
5865 }
Andrew Leea1239f22015-03-02 17:44:07 -08005866 }
5867
5868 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005869 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005870 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005871 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872 return false;
5873 }
5874
5875 final long identity = Binder.clearCallingIdentity();
5876 try {
5877 CarrierConfigManager configManager =
5878 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005879 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5881 } finally {
5882 Binder.restoreCallingIdentity(identity);
5883 }
Andrew Leea1239f22015-03-02 17:44:07 -08005884 }
5885
Andrew Lee9431b832015-03-09 18:46:45 -07005886 @Override
5887 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005888 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005889 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005890 }
5891
5892 @Override
5893 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 final long identity = Binder.clearCallingIdentity();
5895 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005896 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 } finally {
5898 Binder.restoreCallingIdentity(identity);
5899 }
Andrew Lee9431b832015-03-09 18:46:45 -07005900 }
5901
Hall Liuf6668912018-10-31 17:05:23 -07005902 /**
5903 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5904 * support for the feature and device firmware support.
5905 *
5906 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5907 */
5908 @Override
5909 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005910 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005911 final Phone phone = getPhone(subscriptionId);
5912 if (phone == null) {
5913 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5914 return false;
5915 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005917 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5919 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005920 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921 return isCarrierSupported && isDeviceSupported;
5922 } finally {
5923 Binder.restoreCallingIdentity(identity);
5924 }
Hall Liu98187582018-01-22 19:15:32 -08005925 }
5926
Hall Liuf6668912018-10-31 17:05:23 -07005927 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005928 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5929 * RTT setting, will return true if the device and carrier both support RTT.
5930 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005931 */
5932 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933 final long identity = Binder.clearCallingIdentity();
5934 try {
Hall Liu63767ec2019-12-11 23:58:20 +00005935 boolean isRttSupported = isRttSupported(subscriptionId);
5936 boolean isUserRttSettingOn = Settings.Secure.getInt(
5937 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5938 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5939 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5940 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 } finally {
5942 Binder.restoreCallingIdentity(identity);
5943 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005944 }
5945
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005946 @Deprecated
5947 @Override
5948 public String getDeviceId(String callingPackage) {
5949 return getDeviceIdWithFeature(callingPackage, null);
5950 }
5951
Sanket Padawe7310cc72015-01-14 09:53:20 -08005952 /**
5953 * Returns the unique device ID of phone, for example, the IMEI for
5954 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5955 *
5956 * <p>Requires Permission:
5957 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5958 */
5959 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005960 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005961 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005962 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005963 return null;
5964 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005965 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005966 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005967 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005968 return null;
5969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970
5971 final long identity = Binder.clearCallingIdentity();
5972 try {
5973 return phone.getDeviceId();
5974 } finally {
5975 Binder.restoreCallingIdentity(identity);
5976 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005977 }
5978
Ping Sunc67b7c22016-03-02 19:16:45 +08005979 /**
5980 * {@hide}
5981 * Returns the IMS Registration Status on a particular subid
5982 *
5983 * @param subId
5984 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005985 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005986 Phone phone = getPhone(subId);
5987 if (phone != null) {
5988 return phone.isImsRegistered();
5989 } else {
5990 return false;
5991 }
5992 }
5993
Santos Cordon7a1885b2015-02-03 11:15:19 -08005994 @Override
5995 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 final long identity = Binder.clearCallingIdentity();
5997 try {
5998 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5999 } finally {
6000 Binder.restoreCallingIdentity(identity);
6001 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006002 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006003
Tyler Gunnf70ed162019-04-03 15:28:53 -07006004 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006005 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006006 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006007 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006008 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006009 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6010 }
6011 final long identity = Binder.clearCallingIdentity();
6012 try {
6013 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6014 } finally {
6015 Binder.restoreCallingIdentity(identity);
6016 }
6017 }
6018
6019 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006020 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6021 final long identity = Binder.clearCallingIdentity();
6022 try {
6023 Phone phone = getPhone(subscriptionId);
6024 if (phone == null) {
6025 return null;
6026 }
6027 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6028 } finally {
6029 Binder.restoreCallingIdentity(identity);
6030 }
6031 }
6032
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006033 /**
6034 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006035 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006036 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037 final long identity = Binder.clearCallingIdentity();
6038 try {
6039 Phone phone = getPhone(subId);
6040 if (phone != null) {
6041 return phone.isWifiCallingEnabled();
6042 } else {
6043 return false;
6044 }
6045 } finally {
6046 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006047 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006048 }
6049
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006050 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006051 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006052 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006053 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006054 final long identity = Binder.clearCallingIdentity();
6055 try {
6056 Phone phone = getPhone(subId);
6057 if (phone != null) {
6058 return phone.isVideoEnabled();
6059 } else {
6060 return false;
6061 }
6062 } finally {
6063 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006064 }
6065 }
6066
6067 /**
6068 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6069 * defined in {@link ImsRegistrationImplBase}.
6070 */
6071 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 final long identity = Binder.clearCallingIdentity();
6073 try {
6074 Phone phone = getPhone(subId);
6075 if (phone != null) {
6076 return phone.getImsRegistrationTech();
6077 } else {
6078 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6079 }
6080 } finally {
6081 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006082 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006083 }
6084
Stuart Scott8eef64f2015-04-08 15:13:54 -07006085 @Override
6086 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006087 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006088 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6089 return;
6090 }
6091
Svet Ganovcc087f82015-05-12 20:35:54 -07006092 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006093
Svet Ganovcc087f82015-05-12 20:35:54 -07006094 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006095 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6096 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006097 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006098 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006099 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006100 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6101 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006102 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006103 // There has been issues when Sms raw table somehow stores orphan
6104 // fragments. They lead to garbled message when new fragments come
6105 // in and combined with those stale ones. In case this happens again,
6106 // user can reset all network settings which will clean up this table.
6107 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006108 // Clean up IMS settings as well here.
6109 int slotId = getSlotIndex(subId);
6110 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6111 ImsManager.getInstance(mApp, slotId).factoryReset();
6112 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006113
6114 // Erase modem config if erase modem on network setting is enabled.
6115 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6116 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6117 if (configValue != null && Boolean.parseBoolean(configValue)) {
6118 sendEraseModemConfig(getDefaultPhone());
6119 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006120 } finally {
6121 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006122 }
6123 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006124
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006125 private void cleanUpSmsRawTable(Context context) {
6126 ContentResolver resolver = context.getContentResolver();
6127 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6128 resolver.delete(uri, null, null);
6129 }
6130
Narayan Kamath1c496c22015-04-16 14:40:19 +01006131 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006132 public String getSimLocaleForSubscriber(int subId) {
6133 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6134 final Phone phone = getPhone(subId);
6135 if (phone == null) {
6136 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006137 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006138 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006139 final long identity = Binder.clearCallingIdentity();
6140 try {
chen xu5d3637b2019-01-21 23:31:38 -08006141 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006142 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006143 if (info == null) {
6144 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6145 return null;
6146 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006147 // Try and fetch the locale from the carrier properties or from the SIM language
6148 // preferences (EF-PL and EF-LI)...
6149 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006150 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006151 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6152 if (localeFromDefaultSim != null) {
6153 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6154 if (DBG) log("Using locale from subId: " + subId + " locale: "
6155 + localeFromDefaultSim);
6156 return localeFromDefaultSim.toLanguageTag();
6157 } else {
6158 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 }
6160 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162 // The SIM language preferences only store a language (e.g. fr = French), not an
6163 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6164 // the SIM and carrier preferences does not include a country we add the country
6165 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006166 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006167 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006168 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 return mccLocale.toLanguageTag();
6170 }
6171
6172 if (DBG) log("No locale found - returning null");
6173 return null;
6174 } finally {
6175 Binder.restoreCallingIdentity(identity);
6176 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006177 }
6178
6179 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006180 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6181 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006182 }
6183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006184 /**
6185 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6186 */
6187 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006188 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6189 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006190 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006191
Chenjie Yu1ba97252018-01-11 18:16:20 -08006192 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006193 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006194
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006195 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006196 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6197 * representing the state of the modem.
6198 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006199 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6200 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006201 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006202 */
6203 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006204 public void requestModemActivityInfo(ResultReceiver result) {
6205 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006206 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006207
6208 final long identity = Binder.clearCallingIdentity();
6209 try {
6210 ModemActivityInfo ret = null;
6211 synchronized (mLastModemActivityInfo) {
6212 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6213 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006214 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006215 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006216 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006217 int[] txTimeMs = info.getTransmitTimeMillis();
6218 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006220 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006221 }
6222 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006223 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6224 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006225 mLastModemActivityInfo.setIdleTimeMillis(
6226 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006227 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6228 mLastModemActivityInfo.setReceiveTimeMillis(
6229 info.getReceiveTimeMillis() + mLastModemActivityInfo
6230 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006231 }
Chen Xu13851032019-09-10 18:49:52 -07006232
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6234 mLastModemActivityInfo.getSleepTimeMillis(),
6235 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006236 mLastModemActivityInfo.getTransmitTimeMillis(),
6237 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006238 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 Bundle bundle = new Bundle();
6240 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6241 result.send(0, bundle);
6242 } finally {
6243 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006244 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006245 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006246
Siddharth Rayb8114062018-06-17 15:02:38 -07006247 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6248 // less than total activity duration.
6249 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6250 if (info == null) {
6251 return false;
6252 }
6253 int activityDurationMs =
6254 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6255 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006256 int[] txTimeMs = info.getTransmitTimeMillis();
6257 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6258 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006259 }
6260 return (info.isValid()
6261 && (info.getSleepTimeMillis() <= activityDurationMs)
6262 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006263 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006264 && (totalTxTimeMs <= activityDurationMs));
6265 }
6266
Jack Yu85bd38a2015-11-09 11:34:32 -08006267 /**
6268 * {@hide}
6269 * Returns the service state information on specified subscription.
6270 */
6271 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006272 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6273 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006274 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006275 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006276 return null;
6277 }
6278
Hall Liuf19c44f2018-11-27 14:38:17 -08006279 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6280 LocationAccessPolicy.checkLocationPermission(mApp,
6281 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6282 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006283 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006284 .setCallingPid(Binder.getCallingPid())
6285 .setCallingUid(Binder.getCallingUid())
6286 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006287 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006288 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6289 .build());
6290
6291 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6292 LocationAccessPolicy.checkLocationPermission(mApp,
6293 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6294 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006295 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006296 .setCallingPid(Binder.getCallingPid())
6297 .setCallingUid(Binder.getCallingUid())
6298 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006299 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006300 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6301 .build());
6302 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6303 boolean hasFinePermission =
6304 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6305 boolean hasCoarsePermission =
6306 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308 final long identity = Binder.clearCallingIdentity();
6309 try {
6310 final Phone phone = getPhone(subId);
6311 if (phone == null) {
6312 return null;
6313 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006314
Hall Liuf19c44f2018-11-27 14:38:17 -08006315 ServiceState ss = phone.getServiceState();
6316
6317 // Scrub out the location info in ServiceState depending on what level of access
6318 // the caller has.
6319 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006320 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6321 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006322 } finally {
6323 Binder.restoreCallingIdentity(identity);
6324 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006325 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006326
6327 /**
6328 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6329 *
6330 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6331 * voicemail ringtone.
6332 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6333 * PhoneAccount.
6334 */
6335 @Override
6336 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 final long identity = Binder.clearCallingIdentity();
6338 try {
6339 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6340 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006341 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006344 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6345 } finally {
6346 Binder.restoreCallingIdentity(identity);
6347 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006348 }
6349
6350 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006351 * Sets the per-account voicemail ringtone.
6352 *
6353 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6354 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6355 *
6356 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6357 * voicemail ringtone.
6358 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6359 * PhoneAccount.
6360 */
6361 @Override
6362 public void setVoicemailRingtoneUri(String callingPackage,
6363 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006364 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006365 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006366 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6367 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6369 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6370 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006372
6373 final long identity = Binder.clearCallingIdentity();
6374 try {
6375 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6376 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006377 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378 }
6379 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6380 } finally {
6381 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006382 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006383 }
6384
6385 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006386 * Returns whether vibration is set for voicemail notification in Phone settings.
6387 *
6388 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6389 * voicemail vibration setting.
6390 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6391 */
6392 @Override
6393 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394 final long identity = Binder.clearCallingIdentity();
6395 try {
6396 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6397 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006398 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6402 } finally {
6403 Binder.restoreCallingIdentity(identity);
6404 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006405 }
6406
Youhan Wange64578a2016-05-02 15:32:42 -07006407 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006408 * Sets the per-account voicemail vibration.
6409 *
6410 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6411 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6412 *
6413 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6414 * voicemail vibration setting.
6415 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6416 * specific PhoneAccount.
6417 */
6418 @Override
6419 public void setVoicemailVibrationEnabled(String callingPackage,
6420 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006421 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006422 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006423 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6424 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6426 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6427 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006428 }
6429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006430 final long identity = Binder.clearCallingIdentity();
6431 try {
6432 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6433 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006434 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006435 }
6436 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6437 } finally {
6438 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006439 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006440 }
6441
6442 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006443 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6444 *
6445 * @throws SecurityException if the caller does not have the required permission
6446 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006447 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006448 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006449 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006450 }
6451
6452 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006453 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6454 * permission.
6455 *
6456 * @throws SecurityException if the caller does not have the required permission
6457 */
6458 private void enforceSendSmsPermission() {
6459 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6460 }
6461
6462 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006463 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006464 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006465 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006466 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006467 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006468 final long identity = Binder.clearCallingIdentity();
6469 try {
6470 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006471 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 if (componentName == null) {
6473 throw new SecurityException(
6474 "Caller not current active visual voicemail package[null]");
6475 }
6476 String vvmPackage = componentName.getPackageName();
6477 if (!callingPackage.equals(vvmPackage)) {
6478 throw new SecurityException("Caller not current active visual voicemail package["
6479 + vvmPackage + "]");
6480 }
6481 } finally {
6482 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006483 }
6484 }
6485
6486 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006487 * Return the application ID for the app type.
6488 *
6489 * @param subId the subscription ID that this request applies to.
6490 * @param appType the uicc app type.
6491 * @return Application ID for specificied app type, or null if no uicc.
6492 */
6493 @Override
6494 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006495 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006496 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006497
6498 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006499 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006500 if (phone == null) {
6501 return null;
6502 }
6503 String aid = null;
6504 try {
6505 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6506 .getApplicationByType(appType).getAid();
6507 } catch (Exception e) {
6508 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6509 }
6510 return aid;
6511 } finally {
6512 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006513 }
Youhan Wange64578a2016-05-02 15:32:42 -07006514 }
6515
Youhan Wang4001d252016-05-11 10:29:41 -07006516 /**
6517 * Return the Electronic Serial Number.
6518 *
6519 * @param subId the subscription ID that this request applies to.
6520 * @return ESN or null if error.
6521 */
6522 @Override
6523 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006524 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006525 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526
6527 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006528 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006529 if (phone == null) {
6530 return null;
6531 }
6532 String esn = null;
6533 try {
6534 esn = phone.getEsn();
6535 } catch (Exception e) {
6536 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6537 }
6538 return esn;
6539 } finally {
6540 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006541 }
Youhan Wang4001d252016-05-11 10:29:41 -07006542 }
6543
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006544 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006545 * Return the Preferred Roaming List Version.
6546 *
6547 * @param subId the subscription ID that this request applies to.
6548 * @return PRLVersion or null if error.
6549 */
6550 @Override
6551 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006552 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006553 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554
6555 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006556 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557 if (phone == null) {
6558 return null;
6559 }
6560 String cdmaPrlVersion = null;
6561 try {
6562 cdmaPrlVersion = phone.getCdmaPrlVersion();
6563 } catch (Exception e) {
6564 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6565 }
6566 return cdmaPrlVersion;
6567 } finally {
6568 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006569 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006570 }
6571
6572 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006573 * Get snapshot of Telephony histograms
6574 * @return List of Telephony histograms
6575 * @hide
6576 */
6577 @Override
6578 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6580 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581
6582 final long identity = Binder.clearCallingIdentity();
6583 try {
6584 return RIL.getTelephonyRILTimingHistograms();
6585 } finally {
6586 Binder.restoreCallingIdentity(identity);
6587 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006588 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006589
6590 /**
6591 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006592 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6593 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006594 * Require system privileges. In the future we may add this to carrier APIs.
6595 *
Michele Berionne482f8202018-11-27 18:57:59 -08006596 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006597 */
6598 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006599 @TelephonyManager.SetCarrierRestrictionResult
6600 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006601 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006602 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006603
Michele Berionne482f8202018-11-27 18:57:59 -08006604 if (carrierRestrictionRules == null) {
6605 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006606 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006608 final long identity = Binder.clearCallingIdentity();
6609 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006610 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006611 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612 } finally {
6613 Binder.restoreCallingIdentity(identity);
6614 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006615 }
6616
6617 /**
6618 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006619 * Get the allowed carrier list and the excluded carrier list, including the priority between
6620 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006621 * Require system privileges. In the future we may add this to carrier APIs.
6622 *
Michele Berionne482f8202018-11-27 18:57:59 -08006623 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006624 */
6625 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006626 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006627 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006628 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629
6630 final long identity = Binder.clearCallingIdentity();
6631 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006632 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6633 if (response instanceof CarrierRestrictionRules) {
6634 return (CarrierRestrictionRules) response;
6635 }
6636 // Response is an Exception of some kind,
6637 // which is signalled to the user as a NULL retval
6638 return null;
6639 } catch (Exception e) {
6640 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6641 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006642 } finally {
6643 Binder.restoreCallingIdentity(identity);
6644 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006645 }
6646
fionaxu59545b42016-05-25 15:53:37 -07006647 /**
6648 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6649 * @param subId the subscription ID that this action applies to.
6650 * @param enabled control enable or disable metered apns.
6651 * {@hide}
6652 */
6653 @Override
6654 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6655 enforceModifyPermission();
6656 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657
6658 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006659 if (phone == null) {
6660 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6661 return;
6662 }
6663 try {
6664 phone.carrierActionSetMeteredApnsEnabled(enabled);
6665 } catch (Exception e) {
6666 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006667 } finally {
6668 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006669 }
6670 }
6671
6672 /**
6673 * Action set from carrier signalling broadcast receivers to enable/disable radio
6674 * @param subId the subscription ID that this action applies to.
6675 * @param enabled control enable or disable radio.
6676 * {@hide}
6677 */
6678 @Override
6679 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6680 enforceModifyPermission();
6681 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006682
6683 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006684 if (phone == null) {
6685 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6686 return;
6687 }
6688 try {
6689 phone.carrierActionSetRadioEnabled(enabled);
6690 } catch (Exception e) {
6691 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006692 } finally {
6693 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006694 }
6695 }
6696
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006697 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006698 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6699 * network status based on which carrier apps could apply actions accordingly,
6700 * enable/disable default url handler for example.
6701 *
6702 * @param subId the subscription ID that this action applies to.
6703 * @param report control start/stop reporting the default network status.
6704 * {@hide}
6705 */
6706 @Override
6707 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6708 enforceModifyPermission();
6709 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006710
6711 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006712 if (phone == null) {
6713 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6714 return;
6715 }
6716 try {
6717 phone.carrierActionReportDefaultNetworkStatus(report);
6718 } catch (Exception e) {
6719 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006720 } finally {
6721 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006722 }
6723 }
6724
6725 /**
fionaxud9622282017-07-17 17:51:30 -07006726 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6727 * @param subId the subscription ID that this action applies to.
6728 * {@hide}
6729 */
6730 @Override
6731 public void carrierActionResetAll(int subId) {
6732 enforceModifyPermission();
6733 final Phone phone = getPhone(subId);
6734 if (phone == null) {
6735 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6736 return;
6737 }
6738 try {
6739 phone.carrierActionResetAll();
6740 } catch (Exception e) {
6741 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6742 }
6743 }
6744
6745 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006746 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6747 * bug report is being generated.
6748 */
6749 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006750 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006751 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6752 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006753 writer.println("Permission Denial: can't dump Phone from pid="
6754 + Binder.getCallingPid()
6755 + ", uid=" + Binder.getCallingUid()
6756 + "without permission "
6757 + android.Manifest.permission.DUMP);
6758 return;
6759 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006760 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006761 }
Jack Yueb89b242016-06-22 13:27:47 -07006762
Brad Ebingerdac2f002018-04-03 15:17:52 -07006763 @Override
6764 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6765 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6766 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006767 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6768 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006769 }
6770
Jack Yueb89b242016-06-22 13:27:47 -07006771 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006772 * Get aggregated video call data usage since boot.
6773 *
6774 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6775 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006776 * {@hide}
6777 */
6778 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006779 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006780 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6781 null);
6782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783 final long identity = Binder.clearCallingIdentity();
6784 try {
6785 // NetworkStatsService keeps tracking the active network interface and identity. It
6786 // records the delta with the corresponding network identity.
6787 // We just return the total video call data usage snapshot since boot.
6788 Phone phone = getPhone(subId);
6789 if (phone != null) {
6790 return phone.getVtDataUsage(perUidStats);
6791 }
6792 return null;
6793 } finally {
6794 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006795 }
Jack Yueb89b242016-06-22 13:27:47 -07006796 }
Jack Yu75ab2952016-07-08 14:29:33 -07006797
6798 /**
6799 * Policy control of data connection. Usually used when data limit is passed.
6800 * @param enabled True if enabling the data, otherwise disabling.
6801 * @param subId Subscription index
6802 * {@hide}
6803 */
6804 @Override
6805 public void setPolicyDataEnabled(boolean enabled, int subId) {
6806 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006807
6808 final long identity = Binder.clearCallingIdentity();
6809 try {
6810 Phone phone = getPhone(subId);
6811 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006812 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 }
6814 } finally {
6815 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006816 }
6817 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006818
6819 /**
6820 * Get Client request stats
6821 * @return List of Client Request Stats
6822 * @hide
6823 */
6824 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006825 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6826 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006828 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006829 return null;
6830 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006831 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006833 final long identity = Binder.clearCallingIdentity();
6834 try {
6835 if (phone != null) {
6836 return phone.getClientRequestStats();
6837 }
6838
6839 return null;
6840 } finally {
6841 Binder.restoreCallingIdentity(identity);
6842 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006843 }
6844
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006845 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006846 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006847 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006848 }
Jack Yueb4124c2017-02-16 15:32:43 -08006849
6850 /**
Grace Chen70990072017-03-24 17:21:30 -07006851 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006852 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006853 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006854 * @param state State of SIM (power down, power up, pass through)
6855 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6856 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6857 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006858 *
6859 **/
6860 @Override
Grace Chen70990072017-03-24 17:21:30 -07006861 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006862 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006863 Phone phone = PhoneFactory.getPhone(slotIndex);
6864
vagdeviaf9a5b92018-08-15 16:01:53 -07006865 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6866
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006867 final long identity = Binder.clearCallingIdentity();
6868 try {
6869 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006870 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871 }
6872 } finally {
6873 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006874 }
6875 }
Shuo Qiandd210312017-04-12 22:11:33 +00006876
Tyler Gunn65d45c22017-06-05 11:22:26 -07006877 private boolean isUssdApiAllowed(int subId) {
6878 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006879 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006880 if (configManager == null) {
6881 return false;
6882 }
6883 PersistableBundle pb = configManager.getConfigForSubId(subId);
6884 if (pb == null) {
6885 return false;
6886 }
6887 return pb.getBoolean(
6888 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6889 }
6890
Shuo Qiandd210312017-04-12 22:11:33 +00006891 /**
6892 * Check if phone is in emergency callback mode
6893 * @return true if phone is in emergency callback mode
6894 * @param subId sub id
6895 */
goneil9c5f4872017-12-05 14:07:56 -08006896 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006897 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006898 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006899 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006900
6901 final long identity = Binder.clearCallingIdentity();
6902 try {
6903 if (phone != null) {
6904 return phone.isInEcm();
6905 } else {
6906 return false;
6907 }
6908 } finally {
6909 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006910 }
6911 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006912
6913 /**
6914 * Get the current signal strength information for the given subscription.
6915 * Because this information is not updated when the device is in a low power state
6916 * it should not be relied-upon to be current.
6917 * @param subId Subscription index
6918 * @return the most recent cached signal strength info from the modem
6919 */
6920 @Override
6921 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006922 final long identity = Binder.clearCallingIdentity();
6923 try {
6924 Phone p = getPhone(subId);
6925 if (p == null) {
6926 return null;
6927 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006929 return p.getSignalStrength();
6930 } finally {
6931 Binder.restoreCallingIdentity(identity);
6932 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006933 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006934
Pengquan Meng77b7f132018-08-22 14:49:57 -07006935 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006936 * Get the current modem radio state for the given slot.
6937 * @param slotIndex slot index.
6938 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006939 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006940 * @return the current radio power state from the modem
6941 */
6942 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006943 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006944 Phone phone = PhoneFactory.getPhone(slotIndex);
6945 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006946 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6947 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006948 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6949 }
6950
6951 final long identity = Binder.clearCallingIdentity();
6952 try {
6953 return phone.getRadioPowerState();
6954 } finally {
6955 Binder.restoreCallingIdentity(identity);
6956 }
6957 }
6958 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6959 }
6960
6961 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006962 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6963 *
6964 * <p>Requires one of the following permissions:
6965 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6966 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6967 * privileges.
6968 *
6969 * @param subId subscription id
6970 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6971 * {@code false}.
6972 */
6973 @Override
6974 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006975 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6976 null /* message */);
6977
Pengquan Menga1bb6272018-09-06 09:59:22 -07006978 boolean isEnabled = false;
6979 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006980 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006981 Phone phone = getPhone(subId);
6982 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006983 } catch (Exception e) {
6984 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6985 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006986 } finally {
6987 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006988 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006989 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006990 }
6991
6992
6993 /**
6994 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6995 *
6996 * <p> Requires permission:
6997 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6998 * privileges.
6999 *
7000 * @param subId subscription id
7001 * @param isEnabled {@code true} means enable, {@code false} means disable.
7002 */
7003 @Override
7004 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7006 mApp, subId, "setDataRoamingEnabled");
7007
Pengquan Menga1bb6272018-09-06 09:59:22 -07007008 final long identity = Binder.clearCallingIdentity();
7009 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007010 Phone phone = getPhone(subId);
7011 if (phone != null) {
7012 phone.setDataRoamingEnabled(isEnabled);
7013 }
7014 } finally {
7015 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007016 }
7017 }
7018
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007019 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007020 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007021 TelephonyPermissions
7022 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007023 mApp, subId, "isManualNetworkSelectionAllowed");
7024
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007025 boolean isAllowed = true;
7026 final long identity = Binder.clearCallingIdentity();
7027 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007028 Phone phone = getPhone(subId);
7029 if (phone != null) {
7030 isAllowed = phone.isCspPlmnEnabled();
7031 }
7032 } finally {
7033 Binder.restoreCallingIdentity(identity);
7034 }
7035 return isAllowed;
7036 }
7037
7038 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007039 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007040 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007041 try {
7042 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007043 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007044 } catch (SecurityException e) {
7045 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7046 // has carrier privileges on an active UICC
7047 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7048 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007049 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007050 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007051 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007052
7053 final long identity = Binder.clearCallingIdentity();
7054 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007055 UiccController uiccController = UiccController.getInstance();
7056 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007057 if (hasReadPermission) {
7058 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007059 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007060
7061 // Remove private info if the caller doesn't have access
7062 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7063 for (UiccCardInfo cardInfo : cardInfos) {
7064 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7065 // is available
7066 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7067 if (card == null || card.getUiccProfile() == null) {
7068 // assume no access if the card or profile is unavailable
7069 filteredInfos.add(cardInfo.getUnprivileged());
7070 continue;
7071 }
7072 UiccProfile profile = card.getUiccProfile();
7073 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7074 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7075 filteredInfos.add(cardInfo);
7076 } else {
7077 filteredInfos.add(cardInfo.getUnprivileged());
7078 }
7079 }
7080 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007081 } finally {
7082 Binder.restoreCallingIdentity(identity);
7083 }
7084 }
7085
7086 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007087 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007088 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 final long identity = Binder.clearCallingIdentity();
7091 try {
7092 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7093 if (slots == null) {
7094 Rlog.i(LOG_TAG, "slots is null.");
7095 return null;
7096 }
7097
7098 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7099 for (int i = 0; i < slots.length; i++) {
7100 UiccSlot slot = slots[i];
7101 if (slot == null) {
7102 continue;
7103 }
7104
Jordan Liu7be7e652019-05-06 18:55:02 +00007105 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 UiccCard card = slot.getUiccCard();
7107 if (card != null) {
7108 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007109 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007110 cardId = slot.getEid();
7111 if (TextUtils.isEmpty(cardId)) {
7112 cardId = slot.getIccId();
7113 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007114 }
7115
Jordan Liu857451f2019-05-09 16:35:35 -07007116 if (cardId != null) {
7117 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7118 // if cardId is an EID, it's all digits so this is fine
7119 cardId = IccUtils.stripTrailingFs(cardId);
7120 }
7121
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 int cardState = 0;
7123 switch (slot.getCardState()) {
7124 case CARDSTATE_ABSENT:
7125 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7126 break;
7127 case CARDSTATE_PRESENT:
7128 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7129 break;
7130 case CARDSTATE_ERROR:
7131 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7132 break;
7133 case CARDSTATE_RESTRICTED:
7134 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7135 break;
7136 default:
7137 break;
7138
7139 }
7140
7141 infos[i] = new UiccSlotInfo(
7142 slot.isActive(),
7143 slot.isEuicc(),
7144 cardId,
7145 cardState,
7146 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007147 slot.isExtendedApduSupported(),
7148 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149 }
7150 return infos;
7151 } finally {
7152 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007153 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007154 }
7155
7156 @Override
7157 public boolean switchSlots(int[] physicalSlots) {
7158 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007159
7160 final long identity = Binder.clearCallingIdentity();
7161 try {
7162 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7163 } finally {
7164 Binder.restoreCallingIdentity(identity);
7165 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007166 }
Jack Yu4c988042018-02-27 15:30:01 -08007167
7168 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007169 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007170 final long identity = Binder.clearCallingIdentity();
7171 try {
7172 return UiccController.getInstance().getCardIdForDefaultEuicc();
7173 } finally {
7174 Binder.restoreCallingIdentity(identity);
7175 }
7176 }
7177
7178 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007179 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7180 enforceModifyPermission();
7181 final Phone phone = getPhone(subId);
7182 if (phone == null) {
7183 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7184 return;
7185 }
7186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187 final long identity = Binder.clearCallingIdentity();
7188 try {
7189 phone.setRadioIndicationUpdateMode(filters, mode);
7190 } finally {
7191 Binder.restoreCallingIdentity(identity);
7192 }
Jack Yu4c988042018-02-27 15:30:01 -08007193 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007194
7195 /**
goneil47ffb6e2018-04-06 15:40:58 -07007196 * A test API to reload the UICC profile.
7197 *
7198 * <p>Requires that the calling app has permission
7199 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7200 * @hide
7201 */
7202 @Override
7203 public void refreshUiccProfile(int subId) {
7204 enforceModifyPermission();
7205
7206 final long identity = Binder.clearCallingIdentity();
7207 try {
7208 Phone phone = getPhone(subId);
7209 if (phone == null) {
7210 return;
7211 }
7212 UiccCard uiccCard = phone.getUiccCard();
7213 if (uiccCard == null) {
7214 return;
7215 }
7216 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7217 if (uiccProfile == null) {
7218 return;
7219 }
7220 uiccProfile.refresh();
7221 } finally {
7222 Binder.restoreCallingIdentity(identity);
7223 }
7224 }
7225
7226 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007227 * Returns false if the mobile data is disabled by default, otherwise return true.
7228 */
7229 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007230 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007231 }
7232
7233 /**
7234 * Returns true if the data roaming is enabled by default, i.e the system property
7235 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7236 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7237 */
7238 private boolean getDefaultDataRoamingEnabled(int subId) {
7239 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007240 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007241 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007242 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7243 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7244 return isDataRoamingEnabled;
7245 }
7246
7247 /**
7248 * Returns the default network type for the given {@code subId}, if the default network type is
7249 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7250 */
7251 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007252 List<Integer> list = TelephonyProperties.default_network();
7253 int phoneId = mSubscriptionController.getPhoneId(subId);
7254 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7255 return list.get(phoneId);
7256 }
7257 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007258 }
fionaxua13278b2018-03-21 00:08:13 -07007259
7260 @Override
7261 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007262 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007263 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007264
7265 final long identity = Binder.clearCallingIdentity();
7266 try {
7267 final Phone phone = getPhone(subId);
7268 if (phone == null) {
7269 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7270 return;
7271 }
chen xueaba88a2019-03-15 13:15:10 -07007272 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7273 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007274 } finally {
7275 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007276 }
fionaxua13278b2018-03-21 00:08:13 -07007277 }
7278
7279 @Override
7280 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007281 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282
7283 final long identity = Binder.clearCallingIdentity();
7284 try {
7285 final Phone phone = getPhone(subId);
7286 if (phone == null) {
7287 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7288 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7289 }
7290 return phone.getCarrierIdListVersion();
7291 } finally {
7292 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007293 }
fionaxua13278b2018-03-21 00:08:13 -07007294 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007295
7296 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007297 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7298 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007300 mApp, subId, callingPackage, callingFeatureId,
7301 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007302 return -1;
7303 }
7304
7305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7308 } finally {
7309 Binder.restoreCallingIdentity(identity);
7310 }
7311 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007312
7313 @Override
7314 public int getCdmaRoamingMode(int subId) {
7315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7316 mApp, subId, "getCdmaRoamingMode");
7317
7318 final long identity = Binder.clearCallingIdentity();
7319 try {
7320 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7321 } finally {
7322 Binder.restoreCallingIdentity(identity);
7323 }
7324 }
7325
7326 @Override
7327 public boolean setCdmaRoamingMode(int subId, int mode) {
7328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7329 mApp, subId, "setCdmaRoamingMode");
7330
7331 final long identity = Binder.clearCallingIdentity();
7332 try {
7333 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7334 } finally {
7335 Binder.restoreCallingIdentity(identity);
7336 }
7337 }
7338
7339 @Override
7340 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7342 mApp, subId, "setCdmaSubscriptionMode");
7343
7344 final long identity = Binder.clearCallingIdentity();
7345 try {
7346 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7347 } finally {
7348 Binder.restoreCallingIdentity(identity);
7349 }
7350 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007351
sqianc5eccab2018-10-19 18:46:41 -07007352 @Override
sqian8c685422019-02-22 15:55:18 -08007353 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007354 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007356 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7357 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007358 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7359 }
7360 final long identity = Binder.clearCallingIdentity();
7361 try {
sqian854d44b2018-12-12 16:48:18 -08007362 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7363 for (Phone phone: PhoneFactory.getPhones()) {
7364 if (phone.getEmergencyNumberTracker() != null
7365 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7366 emergencyNumberListInternal.put(
7367 phone.getSubId(),
7368 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7369 }
sqian11b7a0e2018-12-05 18:48:28 -08007370 }
sqian854d44b2018-12-12 16:48:18 -08007371 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007372 } finally {
7373 Binder.restoreCallingIdentity(identity);
7374 }
sqianc5eccab2018-10-19 18:46:41 -07007375 }
7376
7377 @Override
sqian8c685422019-02-22 15:55:18 -08007378 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007379 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007380 if (!exactMatch) {
7381 TelephonyPermissions
7382 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007383 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007384 }
7385 final long identity = Binder.clearCallingIdentity();
7386 try {
sqian854d44b2018-12-12 16:48:18 -08007387 for (Phone phone: PhoneFactory.getPhones()) {
7388 if (phone.getEmergencyNumberTracker() != null
7389 && phone.getEmergencyNumberTracker() != null) {
7390 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7391 number, exactMatch)) {
7392 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007393 }
7394 }
sqian11b7a0e2018-12-05 18:48:28 -08007395 }
7396 return false;
7397 } finally {
7398 Binder.restoreCallingIdentity(identity);
7399 }
7400 }
7401
sqianf4ca7ed2019-01-15 18:32:07 -08007402 /**
7403 * Update emergency number list for test mode.
7404 */
7405 @Override
7406 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7407 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7408 "updateEmergencyNumberListTestMode");
7409
7410 final long identity = Binder.clearCallingIdentity();
7411 try {
7412 for (Phone phone: PhoneFactory.getPhones()) {
7413 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7414 if (tracker != null) {
7415 tracker.executeEmergencyNumberTestModeCommand(action, num);
7416 }
7417 }
7418 } finally {
7419 Binder.restoreCallingIdentity(identity);
7420 }
7421 }
7422
7423 /**
7424 * Get the full emergency number list for test mode.
7425 */
7426 @Override
7427 public List<String> getEmergencyNumberListTestMode() {
7428 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7429 "getEmergencyNumberListTestMode");
7430
7431 final long identity = Binder.clearCallingIdentity();
7432 try {
7433 Set<String> emergencyNumbers = new HashSet<>();
7434 for (Phone phone: PhoneFactory.getPhones()) {
7435 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7436 if (tracker != null) {
7437 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7438 emergencyNumbers.add(num.getNumber());
7439 }
7440 }
7441 }
7442 return new ArrayList<>(emergencyNumbers);
7443 } finally {
7444 Binder.restoreCallingIdentity(identity);
7445 }
7446 }
7447
chen xud6b45bd2018-10-30 22:27:10 -07007448 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007449 public int getEmergencyNumberDbVersion(int subId) {
7450 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7451
7452 final long identity = Binder.clearCallingIdentity();
7453 try {
7454 final Phone phone = getPhone(subId);
7455 if (phone == null) {
7456 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7457 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7458 }
7459 return phone.getEmergencyNumberDbVersion();
7460 } finally {
7461 Binder.restoreCallingIdentity(identity);
7462 }
7463 }
7464
7465 @Override
7466 public void notifyOtaEmergencyNumberDbInstalled() {
7467 enforceModifyPermission();
7468
7469 final long identity = Binder.clearCallingIdentity();
7470 try {
7471 for (Phone phone: PhoneFactory.getPhones()) {
7472 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7473 if (tracker != null) {
7474 tracker.updateOtaEmergencyNumberDatabase();
7475 }
7476 }
7477 } finally {
7478 Binder.restoreCallingIdentity(identity);
7479 }
7480 }
7481
7482 @Override
7483 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7484 enforceActiveEmergencySessionPermission();
7485
7486 final long identity = Binder.clearCallingIdentity();
7487 try {
7488 for (Phone phone: PhoneFactory.getPhones()) {
7489 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7490 if (tracker != null) {
7491 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7492 }
7493 }
7494 } finally {
7495 Binder.restoreCallingIdentity(identity);
7496 }
7497 }
7498
7499 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007500 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7501 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7502 Phone phone = getPhone(subId);
7503 if (phone == null) {
7504 return null;
7505 }
7506 final long identity = Binder.clearCallingIdentity();
7507 try {
7508 UiccProfile profile = UiccController.getInstance()
7509 .getUiccProfileForPhone(phone.getPhoneId());
7510 if (profile != null) {
7511 return profile.getCertsFromCarrierPrivilegeAccessRules();
7512 }
7513 } finally {
7514 Binder.restoreCallingIdentity(identity);
7515 }
7516 return null;
7517 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007518
7519 /**
7520 * Enable or disable a modem stack.
7521 */
7522 @Override
7523 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7524 enforceModifyPermission();
7525
7526 final long identity = Binder.clearCallingIdentity();
7527 try {
7528 Phone phone = PhoneFactory.getPhone(slotIndex);
7529 if (phone == null) {
7530 return false;
7531 } else {
7532 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7533 }
7534 } finally {
7535 Binder.restoreCallingIdentity(identity);
7536 }
7537 }
Michelecea4cf22018-12-21 15:00:11 -08007538
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007539 /**
7540 * Whether a modem stack is enabled or not.
7541 */
7542 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007543 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7544 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007545 Phone phone = PhoneFactory.getPhone(slotIndex);
7546 if (phone == null) return false;
7547
7548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007549 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7550 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007551 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7552 }
7553
7554 final long identity = Binder.clearCallingIdentity();
7555 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007556 try {
7557 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7558 } catch (NoSuchElementException ex) {
7559 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7560 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007561 } finally {
7562 Binder.restoreCallingIdentity(identity);
7563 }
7564 }
7565
Michelecea4cf22018-12-21 15:00:11 -08007566 @Override
Michele0ea7d782019-03-19 14:58:42 -07007567 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007568 enforceModifyPermission();
7569
7570 final long identity = Binder.clearCallingIdentity();
7571 try {
7572 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007573 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007574 .commit();
7575 } finally {
7576 Binder.restoreCallingIdentity(identity);
7577 }
7578 }
7579
7580 @Override
Michele0ea7d782019-03-19 14:58:42 -07007581 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007582 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007583 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007584 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7585 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007586 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007587 }
Michelecea4cf22018-12-21 15:00:11 -08007588
7589 final long identity = Binder.clearCallingIdentity();
7590 try {
Michele0ea7d782019-03-19 14:58:42 -07007591 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007592 } finally {
7593 Binder.restoreCallingIdentity(identity);
7594 }
7595 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007596
Michele0ea7d782019-03-19 14:58:42 -07007597 @TelephonyManager.IsMultiSimSupportedResult
7598 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007599 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7600 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7601 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007602 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7603 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007604 }
7605 // Check if the hardware supports multisim functionality. If usage of multisim is not
7606 // supported by the modem, indicate that it is restricted.
7607 PhoneCapability staticCapability =
7608 mPhoneConfigurationManager.getStaticPhoneCapability();
7609 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007610 loge("isMultiSimSupportedInternal: no static configuration available");
7611 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007612 }
7613 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007614 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7615 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007616 }
7617 // Check if support of multiple SIMs is restricted by carrier
7618 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007619 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007620 }
7621
Michele0ea7d782019-03-19 14:58:42 -07007622 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007623 }
7624
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007625 /**
7626 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007627 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7628 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7629 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007630 * @param numOfSims number of active sims we want to switch to
7631 */
7632 @Override
7633 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007634 if (numOfSims == 1) {
7635 enforceModifyPermission();
7636 } else {
7637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7638 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7639 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007640 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007641
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007642 try {
Michele30b57b22019-03-01 12:01:14 -08007643 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007644 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007645 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7646 return;
7647 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007648 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7649 } finally {
7650 Binder.restoreCallingIdentity(identity);
7651 }
7652 }
7653
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007654 @Override
7655 public boolean isApplicationOnUicc(int subId, int appType) {
7656 enforceReadPrivilegedPermission("isApplicationOnUicc");
7657 Phone phone = getPhone(subId);
7658 if (phone == null) {
7659 return false;
7660 }
7661 final long identity = Binder.clearCallingIdentity();
7662 try {
7663 UiccCard uiccCard = phone.getUiccCard();
7664 if (uiccCard == null) {
7665 return false;
7666 }
7667 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7668 if (uiccProfile == null) {
7669 return false;
7670 }
7671 if (TelephonyManager.APPTYPE_SIM <= appType
7672 && appType <= TelephonyManager.APPTYPE_ISIM) {
7673 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7674 }
7675 return false;
7676 } finally {
7677 Binder.restoreCallingIdentity(identity);
7678 }
7679 }
7680
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007681 /**
chen xub4baa772019-04-03 10:23:41 -07007682 * Get whether making changes to modem configurations will trigger reboot.
7683 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007684 */
7685 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007686 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7687 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007689 mApp, subId, callingPackage, callingFeatureId,
7690 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007691 return false;
7692 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007693 final long identity = Binder.clearCallingIdentity();
7694 try {
7695 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7696 } finally {
7697 Binder.restoreCallingIdentity(identity);
7698 }
7699 }
7700
Nathan Harold29f5f052019-02-15 13:41:57 -08007701 private void updateModemStateMetrics() {
7702 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7703 // TODO: check the state for each modem if the api is ready.
7704 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7705 }
7706
Pengquan Meng3889a572019-01-23 11:16:29 -08007707 @Override
7708 public int[] getSlotsMapping() {
7709 enforceReadPrivilegedPermission("getSlotsMapping");
7710
7711 final long identity = Binder.clearCallingIdentity();
7712 try {
7713 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7714 // All logical slots should have a mapping to a physical slot.
7715 int[] logicalSlotsMapping = new int[phoneCount];
7716 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7717 for (int i = 0; i < slotInfos.length; i++) {
7718 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7719 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7720 }
7721 }
7722 return logicalSlotsMapping;
7723 } finally {
7724 Binder.restoreCallingIdentity(identity);
7725 }
7726 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007727
7728 /**
7729 * Get the IRadio HAL Version
7730 */
7731 @Override
7732 public int getRadioHalVersion() {
7733 Phone phone = getDefaultPhone();
7734 if (phone == null) return -1;
7735 HalVersion hv = phone.getHalVersion();
7736 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7737 return hv.major * 100 + hv.minor;
7738 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007739
7740 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007741 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7742 * corresponding network requests on a subId.
7743 *
7744 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007745 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007746 * 2) APN is un-metered for this subscription, or
7747 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7748 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7749 *
7750 * @return whether data is allowed for a apn type.
7751 *
7752 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007753 */
7754 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007755 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007756 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7757 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007758
7759 // Now that all security checks passes, perform the operation as ourselves.
7760 final long identity = Binder.clearCallingIdentity();
7761 try {
7762 Phone phone = getPhone(subId);
7763 if (phone == null) return false;
7764
Jack Yu41407ee2019-05-13 16:54:09 -07007765 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007766 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7767 } finally {
7768 Binder.restoreCallingIdentity(identity);
7769 }
7770 }
7771
7772 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007773 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007774 enforceReadPrivilegedPermission("isApnMetered");
7775
7776 // Now that all security checks passes, perform the operation as ourselves.
7777 final long identity = Binder.clearCallingIdentity();
7778 try {
7779 Phone phone = getPhone(subId);
7780 if (phone == null) return true; // By default return true.
7781
Jack Yu41407ee2019-05-13 16:54:09 -07007782 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007783 } finally {
7784 Binder.restoreCallingIdentity(identity);
7785 }
7786 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007787
7788 @Override
changbetty363e8ac2019-12-06 18:16:37 +08007789 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7790 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7791 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7792 if (iccRecords == null) {
7793 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7794 return false;
7795 }
7796 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7797 }
7798
7799 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007800 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7801 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7802 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7803 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7804 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7805 }
7806 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7807 Intent intent = new Intent();
7808 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7809 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7810 // Bring up choose default SMS subscription dialog right now
7811 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7812 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7813 mApp.startActivity(intent);
7814 }
chen xud5ca2d52019-05-28 15:20:57 -07007815
7816 @Override
7817 public String getMmsUAProfUrl(int subId) {
7818 //TODO investigate if this API should require proper permission check in R b/133791609
7819 final long identity = Binder.clearCallingIdentity();
7820 try {
7821 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7822 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7823 } finally {
7824 Binder.restoreCallingIdentity(identity);
7825 }
7826 }
7827
7828 @Override
7829 public String getMmsUserAgent(int subId) {
7830 //TODO investigate if this API should require proper permission check in R b/133791609
7831 final long identity = Binder.clearCallingIdentity();
7832 try {
7833 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7834 .getString(com.android.internal.R.string.config_mms_user_agent);
7835 } finally {
7836 Binder.restoreCallingIdentity(identity);
7837 }
7838 }
Jack Yub07d4972019-05-28 16:12:25 -07007839
7840 @Override
7841 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7842 enforceModifyPermission();
7843
7844 // Now that all security checks passes, perform the operation as ourselves.
7845 final long identity = Binder.clearCallingIdentity();
7846 try {
7847 Phone phone = getPhone(subId);
7848 if (phone == null) return false;
7849
7850 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7851 } finally {
7852 Binder.restoreCallingIdentity(identity);
7853 }
7854 }
7855
7856 @Override
7857 public boolean isDataAllowedInVoiceCall(int subId) {
7858 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7859
7860 // Now that all security checks passes, perform the operation as ourselves.
7861 final long identity = Binder.clearCallingIdentity();
7862 try {
7863 Phone phone = getPhone(subId);
7864 if (phone == null) return false;
7865
7866 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7867 } finally {
7868 Binder.restoreCallingIdentity(identity);
7869 }
7870 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007871
7872 /**
7873 * Updates whether conference event pacakge handling is enabled.
7874 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7875 * otherwise.
7876 */
7877 @Override
7878 public void setCepEnabled(boolean isCepEnabled) {
7879 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7880
7881 final long identity = Binder.clearCallingIdentity();
7882 try {
7883 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7884 for (Phone phone : PhoneFactory.getPhones()) {
7885 Phone defaultPhone = phone.getImsPhone();
7886 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7887 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7888 ImsPhoneCallTracker imsPhoneCallTracker =
7889 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7890 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7891 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7892 + imsPhone.getMsisdn());
7893 }
7894 }
7895 } finally {
7896 Binder.restoreCallingIdentity(identity);
7897 }
7898 }
allenwtsu46dcc572020-01-08 18:24:03 +08007899
7900 /**
7901 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
7902 *
7903 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
7904 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
7905 * before being read.
7906 */
7907 @Override
7908 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
7909 isCompressed) {
7910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7911 mApp, subId, "notifyRcsAutoConfigurationReceived");
7912 try {
7913 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
7914 if (configBinder == null) {
7915 Rlog.e(LOG_TAG, "null result for getImsConfig");
7916 } else {
7917 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
7918 }
7919 } catch (RemoteException e) {
7920 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
7921 }
7922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007923}