blob: 408131eed9bc3768da47f67f3786a5258ab50070 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080050import android.os.Process;
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;
sqian80370722020-01-29 15:02:51 -080068import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070069import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080070import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070071import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080072import android.telephony.CellIdentityCdma;
73import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070075import android.telephony.CellInfoGsm;
76import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070077import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070078import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070079import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080080import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070081import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080082import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070083import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080084import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080085import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070086import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080089import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080090import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
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;
sqian80370722020-01-29 15:02:51 -0800123import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800130import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800132import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800133import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700134import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800135import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800137import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700138import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700139import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700140import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700142import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800143import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700144import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700145import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700146import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700147import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700148import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700149import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700150import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700151import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800152import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800153import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700154import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800155import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700156import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800157import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700158import com.android.internal.telephony.imsphone.ImsPhone;
159import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800160import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900161import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700162import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800163import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800165import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700166import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800167import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700168import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800169import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000170import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800171import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700172import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800173import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700174import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700175import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800176import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700178import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800179import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800180
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700181import java.io.FileDescriptor;
182import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700183import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800184import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800185import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800186import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800187import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100188import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800189import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700190import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800191import java.util.Set;
Hall Liud0d1dc92020-01-20 13:42:00 -0800192import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193
194/**
195 * Implementation of the ITelephony interface.
196 */
Santos Cordon117fee72014-05-16 17:56:12 -0700197public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198 private static final String LOG_TAG = "PhoneInterfaceManager";
199 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
200 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800201 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202
203 // Message codes used with mMainThreadHandler
204 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700205 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
206 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700207 private static final int CMD_OPEN_CHANNEL = 9;
208 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
209 private static final int CMD_CLOSE_CHANNEL = 11;
210 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800211 private static final int CMD_NV_READ_ITEM = 13;
212 private static final int EVENT_NV_READ_ITEM_DONE = 14;
213 private static final int CMD_NV_WRITE_ITEM = 15;
214 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
215 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
216 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700217 private static final int CMD_RESET_MODEM_CONFIG = 19;
218 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800219 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
220 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
221 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
222 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800223 private static final int CMD_SEND_ENVELOPE = 25;
224 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000225 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
226 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700227 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
228 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
229 private static final int CMD_EXCHANGE_SIM_IO = 31;
230 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800231 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
232 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700233 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
234 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700235 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
236 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700237 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
238 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
239 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
240 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700241 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
242 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
243 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
244 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700245 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800246 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
247 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000248 private static final int CMD_SWITCH_SLOTS = 50;
249 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700250 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
251 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
252 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
253 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
254 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
255 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
256 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
257 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700258 private static final int CMD_GET_ALL_CELL_INFO = 60;
259 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
260 private static final int CMD_GET_CELL_LOCATION = 62;
261 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700262 private static final int CMD_MODEM_REBOOT = 64;
263 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700264 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
265 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800266 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
267 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700268 private static final int CMD_GET_MODEM_STATUS = 70;
269 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700270 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
271 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700272 private static final int CMD_ERASE_MODEM_CONFIG = 74;
273 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800274 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
275 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
276 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
277 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800278 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
279 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
sqian80370722020-01-29 15:02:51 -0800280 private static final int CMD_GET_CALL_FORWARDING = 83;
281 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
282 private static final int CMD_SET_CALL_FORWARDING = 85;
283 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
284 private static final int CMD_GET_CALL_WAITING = 87;
285 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
286 private static final int CMD_SET_CALL_WAITING = 89;
287 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800289 // Parameters of select command.
290 private static final int SELECT_COMMAND = 0xA4;
291 private static final int SELECT_P1 = 0x04;
292 private static final int SELECT_P2 = 0;
293 private static final int SELECT_P3 = 0x10;
294
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 /** The singleton instance. */
296 private static PhoneInterfaceManager sInstance;
297
Wink Saville3ab207e2014-11-20 13:07:20 -0800298 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800299 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800300 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700301 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800302 private AppOpsManager mAppOps;
303 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800304 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800305 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700306 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700307
Derek Tan97ebb422014-09-05 16:55:38 -0700308 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
309 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800310 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800311 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700312
Michelecea4cf22018-12-21 15:00:11 -0800313 // String to store multi SIM allowed
314 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
315
Derek Tan740e1672017-06-27 14:56:27 -0700316 // The AID of ISD-R.
317 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
318
yinxub1bed742017-04-17 11:45:04 -0700319 private NetworkScanRequestTracker mNetworkScanRequestTracker;
320
David Kelly5e06a7f2018-03-12 14:10:59 +0000321 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
322 private static final int MANUFACTURER_CODE_LENGTH = 8;
323
Derek Tan89e89d42014-07-08 17:00:10 -0700324 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700325 * Experiment flag to enable erase modem config on reset network, default value is false
326 */
327 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
328 "reset_network_erase_modem_config_enabled";
329
330 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700331 * A request object to use for transmitting data to an ICC.
332 */
333 private static final class IccAPDUArgument {
334 public int channel, cla, command, p1, p2, p3;
335 public String data;
336
337 public IccAPDUArgument(int channel, int cla, int command,
338 int p1, int p2, int p3, String data) {
339 this.channel = channel;
340 this.cla = cla;
341 this.command = command;
342 this.p1 = p1;
343 this.p2 = p2;
344 this.p3 = p3;
345 this.data = data;
346 }
347 }
348
349 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700350 * A request object to use for transmitting data to an ICC.
351 */
352 private static final class ManualNetworkSelectionArgument {
353 public OperatorInfo operatorInfo;
354 public boolean persistSelection;
355
356 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
357 this.operatorInfo = operatorInfo;
358 this.persistSelection = persistSelection;
359 }
360 }
361
362 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
364 * request after sending. The main thread will notify the request when it is complete.
365 */
366 private static final class MainThreadRequest {
367 /** The argument to use for the request */
368 public Object argument;
369 /** The result of the request that is run on the main thread */
370 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800371 // The subscriber id that this request applies to. Defaults to
372 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
373 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374
Nathan Harold92bed182018-10-12 18:16:49 -0700375 // In cases where subId is unavailable, the caller needs to specify the phone.
376 public Phone phone;
377
vagdeviaf9a5b92018-08-15 16:01:53 -0700378 public WorkSource workSource;
379
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 public MainThreadRequest(Object argument) {
381 this.argument = argument;
382 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800383
Nathan Harold92bed182018-10-12 18:16:49 -0700384 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
385 this.argument = argument;
386 if (phone != null) {
387 this.phone = phone;
388 }
389 this.workSource = workSource;
390 }
391
vagdeviaf9a5b92018-08-15 16:01:53 -0700392 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800393 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800394 if (subId != null) {
395 this.subId = subId;
396 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700397 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 }
400
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800401 private static final class IncomingThirdPartyCallArgs {
402 public final ComponentName component;
403 public final String callId;
404 public final String callerDisplayName;
405
406 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
407 String callerDisplayName) {
408 this.component = component;
409 this.callId = callId;
410 this.callerDisplayName = callerDisplayName;
411 }
412 }
413
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 /**
415 * A handler that processes messages on the main thread in the phone process. Since many
416 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
417 * inbound binder threads to the main thread in the phone process. The Binder thread
418 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
419 * on, which will be notified when the operation completes and will contain the result of the
420 * request.
421 *
422 * <p>If a MainThreadRequest object is provided in the msg.obj field,
423 * note that request.result must be set to something non-null for the calling thread to
424 * unblock.
425 */
426 private final class MainThreadHandler extends Handler {
427 @Override
428 public void handleMessage(Message msg) {
429 MainThreadRequest request;
430 Message onCompleted;
431 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800432 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700433 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800434 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435
436 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700437 case CMD_HANDLE_USSD_REQUEST: {
438 request = (MainThreadRequest) msg.obj;
439 final Phone phone = getPhoneFromRequest(request);
440 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
441 String ussdRequest = ussdObject.first;
442 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700443
Pengquan Menga1bb6272018-09-06 09:59:22 -0700444 if (!isUssdApiAllowed(request.subId)) {
445 // Carrier does not support use of this API, return failure.
446 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
447 UssdResponse response = new UssdResponse(ussdRequest, null);
448 Bundle returnData = new Bundle();
449 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
450 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700451
Pengquan Menga1bb6272018-09-06 09:59:22 -0700452 request.result = true;
453 notifyRequester(request);
454 return;
455 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700456
Pengquan Menga1bb6272018-09-06 09:59:22 -0700457 try {
458 request.result = phone != null
459 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
460 } catch (CallStateException cse) {
461 request.result = false;
462 }
463 // Wake up the requesting thread
464 notifyRequester(request);
465 break;
pkanwar32d516d2016-10-14 19:37:38 -0700466 }
467
Yorke Lee716f67e2015-06-17 15:39:16 -0700468 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700470 final Phone phone = getPhoneFromRequest(request);
471 request.result = phone != null ?
472 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
473 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700475 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700476 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700481 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800482 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700483 if (uiccCard == null) {
484 loge("iccTransmitApduLogicalChannel: No UICC");
485 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700486 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700487 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
489 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700490 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 iccArgument.channel, iccArgument.cla, iccArgument.command,
492 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700493 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700494 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700495 break;
496
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700498 ar = (AsyncResult) msg.obj;
499 request = (MainThreadRequest) ar.userObj;
500 if (ar.exception == null && ar.result != null) {
501 request.result = ar.result;
502 } else {
503 request.result = new IccIoResult(0x6F, 0, (byte[])null);
504 if (ar.result == null) {
505 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800506 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700507 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800508 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700509 } else {
510 loge("iccTransmitApduLogicalChannel: Unknown exception");
511 }
512 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700513 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700514 break;
515
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
517 request = (MainThreadRequest) msg.obj;
518 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800519 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700520 if (uiccCard == null) {
521 loge("iccTransmitApduBasicChannel: No UICC");
522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 } else {
525 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
526 request);
527 uiccCard.iccTransmitApduBasicChannel(
528 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
529 iccArgument.p3, iccArgument.data, onCompleted);
530 }
531 break;
532
533 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
534 ar = (AsyncResult) msg.obj;
535 request = (MainThreadRequest) ar.userObj;
536 if (ar.exception == null && ar.result != null) {
537 request.result = ar.result;
538 } else {
539 request.result = new IccIoResult(0x6F, 0, (byte[])null);
540 if (ar.result == null) {
541 loge("iccTransmitApduBasicChannel: Empty response");
542 } else if (ar.exception instanceof CommandException) {
543 loge("iccTransmitApduBasicChannel: CommandException: " +
544 ar.exception);
545 } else {
546 loge("iccTransmitApduBasicChannel: Unknown exception");
547 }
548 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700550 break;
551
552 case CMD_EXCHANGE_SIM_IO:
553 request = (MainThreadRequest) msg.obj;
554 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800555 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 if (uiccCard == null) {
557 loge("iccExchangeSimIO: No UICC");
558 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 } else {
561 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
562 request);
563 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
564 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
565 iccArgument.data, onCompleted);
566 }
567 break;
568
569 case EVENT_EXCHANGE_SIM_IO_DONE:
570 ar = (AsyncResult) msg.obj;
571 request = (MainThreadRequest) ar.userObj;
572 if (ar.exception == null && ar.result != null) {
573 request.result = ar.result;
574 } else {
575 request.result = new IccIoResult(0x6f, 0, (byte[])null);
576 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700577 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700578 break;
579
Derek Tan4d5e5c12014-02-04 11:54:58 -0800580 case CMD_SEND_ENVELOPE:
581 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800582 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 if (uiccCard == null) {
584 loge("sendEnvelopeWithStatus: No UICC");
585 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700586 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700587 } else {
588 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
589 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
590 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800591 break;
592
593 case EVENT_SEND_ENVELOPE_DONE:
594 ar = (AsyncResult) msg.obj;
595 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700596 if (ar.exception == null && ar.result != null) {
597 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800598 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700599 request.result = new IccIoResult(0x6F, 0, (byte[])null);
600 if (ar.result == null) {
601 loge("sendEnvelopeWithStatus: Empty response");
602 } else if (ar.exception instanceof CommandException) {
603 loge("sendEnvelopeWithStatus: CommandException: " +
604 ar.exception);
605 } else {
606 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
607 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800608 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700609 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800610 break;
611
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 case CMD_OPEN_CHANNEL:
613 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800614 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800615 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700616 if (uiccCard == null) {
617 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800618 request.result = new IccOpenLogicalChannelResponse(-1,
619 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700621 } else {
622 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800623 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
624 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700625 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 break;
627
628 case EVENT_OPEN_CHANNEL_DONE:
629 ar = (AsyncResult) msg.obj;
630 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 int[] result = (int[]) ar.result;
634 int channelId = result[0];
635 byte[] selectResponse = null;
636 if (result.length > 1) {
637 selectResponse = new byte[result.length - 1];
638 for (int i = 1; i < result.length; ++i) {
639 selectResponse[i - 1] = (byte) result[i];
640 }
641 }
642 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700643 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 if (ar.result == null) {
646 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 if (ar.exception != null) {
649 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
650 }
651
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700652 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700653 if (ar.exception instanceof CommandException) {
654 CommandException.Error error =
655 ((CommandException) (ar.exception)).getCommandError();
656 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700657 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700658 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700659 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700660 }
661 }
662 openChannelResp = new IccOpenLogicalChannelResponse(
663 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700665 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 break;
668
669 case CMD_CLOSE_CHANNEL:
670 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800671 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700672 if (uiccCard == null) {
673 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900674 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700675 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700676 } else {
677 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
678 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
679 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 break;
681
682 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800683 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
684 break;
685
686 case CMD_NV_READ_ITEM:
687 request = (MainThreadRequest) msg.obj;
688 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800689 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
690 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800691 break;
692
693 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 ar = (AsyncResult) msg.obj;
695 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800696 if (ar.exception == null && ar.result != null) {
697 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700698 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800699 request.result = "";
700 if (ar.result == null) {
701 loge("nvReadItem: Empty response");
702 } else if (ar.exception instanceof CommandException) {
703 loge("nvReadItem: CommandException: " +
704 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800706 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 }
708 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700709 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700710 break;
711
Jake Hambye994d462014-02-03 13:10:13 -0800712 case CMD_NV_WRITE_ITEM:
713 request = (MainThreadRequest) msg.obj;
714 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
715 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800716 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700717 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800718 break;
719
720 case EVENT_NV_WRITE_ITEM_DONE:
721 handleNullReturnEvent(msg, "nvWriteItem");
722 break;
723
724 case CMD_NV_WRITE_CDMA_PRL:
725 request = (MainThreadRequest) msg.obj;
726 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800727 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800728 break;
729
730 case EVENT_NV_WRITE_CDMA_PRL_DONE:
731 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
732 break;
733
chen xu6dac5ab2018-10-26 17:39:23 -0700734 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800735 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700736 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800737 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800738 break;
739
chen xu6dac5ab2018-10-26 17:39:23 -0700740 case EVENT_RESET_MODEM_CONFIG_DONE:
741 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800742 break;
743
Jake Hamby7c27be32014-03-03 13:25:59 -0800744 case CMD_GET_PREFERRED_NETWORK_TYPE:
745 request = (MainThreadRequest) msg.obj;
746 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700747 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800748 break;
749
750 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
751 ar = (AsyncResult) msg.obj;
752 request = (MainThreadRequest) ar.userObj;
753 if (ar.exception == null && ar.result != null) {
754 request.result = ar.result; // Integer
755 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800756 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800757 if (ar.result == null) {
758 loge("getPreferredNetworkType: Empty response");
759 } else if (ar.exception instanceof CommandException) {
760 loge("getPreferredNetworkType: CommandException: " +
761 ar.exception);
762 } else {
763 loge("getPreferredNetworkType: Unknown exception");
764 }
765 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700766 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800767 break;
768
769 case CMD_SET_PREFERRED_NETWORK_TYPE:
770 request = (MainThreadRequest) msg.obj;
771 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
772 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700773 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800774 break;
775
776 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
777 handleNullReturnEvent(msg, "setPreferredNetworkType");
778 break;
779
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000780 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
781 request = (MainThreadRequest)msg.obj;
782 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800783 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000784 break;
785
786 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
787 ar = (AsyncResult)msg.obj;
788 request = (MainThreadRequest)ar.userObj;
789 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700790 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000791 break;
792
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800793 case CMD_SET_VOICEMAIL_NUMBER:
794 request = (MainThreadRequest) msg.obj;
795 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
796 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800797 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
798 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800799 break;
800
801 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
802 handleNullReturnEvent(msg, "setVoicemailNumber");
803 break;
804
Stuart Scott54788802015-03-30 13:18:01 -0700805 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
806 request = (MainThreadRequest) msg.obj;
807 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
808 request);
809 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
810 break;
811
812 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
813 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
814 break;
815
Shishir Agrawal302c8692015-06-19 13:49:39 -0700816 case CMD_PERFORM_NETWORK_SCAN:
817 request = (MainThreadRequest) msg.obj;
818 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
819 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
820 break;
821
sqian80370722020-01-29 15:02:51 -0800822 case CMD_GET_CALL_FORWARDING:
823 request = (MainThreadRequest) msg.obj;
824 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
825 int callForwardingReason = (Integer) request.argument;
826 getPhoneFromRequest(request).getCallForwardingOption(
827 callForwardingReason, onCompleted);
828 break;
829
830 case EVENT_GET_CALL_FORWARDING_DONE:
831 ar = (AsyncResult) msg.obj;
832 request = (MainThreadRequest) ar.userObj;
833 CallForwardingInfo callForwardingInfo = null;
834 if (ar.exception == null && ar.result != null) {
835 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
836 for (CallForwardInfo callForwardInfo : callForwardInfos) {
837 // Service Class is a bit mask per 3gpp 27.007. Search for
838 // any service for voice call.
839 if ((callForwardInfo.serviceClass
840 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
841 callForwardingInfo = new CallForwardingInfo(
842 callForwardInfo.serviceClass, callForwardInfo.reason,
843 callForwardInfo.number,
844 callForwardInfo.timeSeconds);
845 break;
846 }
847 }
848 // Didn't find a call forward info for voice call.
849 if (callForwardingInfo == null) {
850 callForwardingInfo = new CallForwardingInfo(
851 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
852 0 /* reason */, null /* number */, 0 /* timeout */);
853 }
854 } else {
855 if (ar.result == null) {
856 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
857 }
858 if (ar.exception != null) {
859 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
860 }
861 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
862 if (ar.exception instanceof CommandException) {
863 CommandException.Error error =
864 ((CommandException) (ar.exception)).getCommandError();
865 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
866 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
867 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
868 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
869 }
870 }
871 callForwardingInfo = new CallForwardingInfo(
872 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
873 }
874 request.result = callForwardingInfo;
875 notifyRequester(request);
876 break;
877
878 case CMD_SET_CALL_FORWARDING:
879 request = (MainThreadRequest) msg.obj;
880 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
881 CallForwardingInfo callForwardingInfoToSet =
882 (CallForwardingInfo) request.argument;
883 getPhoneFromRequest(request).setCallForwardingOption(
884 callForwardingInfoToSet.getStatus(),
885 callForwardingInfoToSet.getReason(),
886 callForwardingInfoToSet.getNumber(),
887 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
888 break;
889
890 case EVENT_SET_CALL_FORWARDING_DONE:
891 ar = (AsyncResult) msg.obj;
892 request = (MainThreadRequest) ar.userObj;
893 if (ar.exception == null) {
894 request.result = true;
895 } else {
896 request.result = false;
897 loge("setCallForwarding exception: " + ar.exception);
898 }
899 notifyRequester(request);
900 break;
901
902 case CMD_GET_CALL_WAITING:
903 request = (MainThreadRequest) msg.obj;
904 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
905 getPhoneFromRequest(request).getCallWaiting(onCompleted);
906 break;
907
908 case EVENT_GET_CALL_WAITING_DONE:
909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
911 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
912 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800913 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -0800914 // Service Class is a bit mask per 3gpp 27.007.
915 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800916 if (callForwardResults.length > 1
917 && ((callForwardResults[1]
918 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
919 callForwardingStatus = callForwardResults[0] == 0
sqian80370722020-01-29 15:02:51 -0800920 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
921 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
922 } else {
923 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
924 }
925 } else {
926 if (ar.result == null) {
927 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
928 }
929 if (ar.exception != null) {
930 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
931 }
932 if (ar.exception instanceof CommandException) {
933 CommandException.Error error =
934 ((CommandException) (ar.exception)).getCommandError();
935 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
936 callForwardingStatus =
937 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
938 }
939 }
940 }
941 request.result = callForwardingStatus;
942 notifyRequester(request);
943 break;
944
945 case CMD_SET_CALL_WAITING:
946 request = (MainThreadRequest) msg.obj;
947 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
948 boolean isEnable = (Boolean) request.argument;
949 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
950 break;
951
952 case EVENT_SET_CALL_WAITING_DONE:
953 ar = (AsyncResult) msg.obj;
954 request = (MainThreadRequest) ar.userObj;
955 if (ar.exception == null) {
956 request.result = true;
957 } else {
958 request.result = false;
959 loge("setCallWaiting exception: " + ar.exception);
960 }
961 notifyRequester(request);
962 break;
963
Shishir Agrawal302c8692015-06-19 13:49:39 -0700964 case EVENT_PERFORM_NETWORK_SCAN_DONE:
965 ar = (AsyncResult) msg.obj;
966 request = (MainThreadRequest) ar.userObj;
967 CellNetworkScanResult cellScanResult;
968 if (ar.exception == null && ar.result != null) {
969 cellScanResult = new CellNetworkScanResult(
970 CellNetworkScanResult.STATUS_SUCCESS,
971 (List<OperatorInfo>) ar.result);
972 } else {
973 if (ar.result == null) {
974 loge("getCellNetworkScanResults: Empty response");
975 }
976 if (ar.exception != null) {
977 loge("getCellNetworkScanResults: Exception: " + ar.exception);
978 }
979 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
980 if (ar.exception instanceof CommandException) {
981 CommandException.Error error =
982 ((CommandException) (ar.exception)).getCommandError();
983 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
984 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
985 } else if (error == CommandException.Error.GENERIC_FAILURE) {
986 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
987 }
988 }
989 cellScanResult = new CellNetworkScanResult(errorCode, null);
990 }
991 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700992 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700993 break;
994
995 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
996 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700997 ManualNetworkSelectionArgument selArg =
998 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700999 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1000 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001001 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1002 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001003 break;
1004
1005 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001006 ar = (AsyncResult) msg.obj;
1007 request = (MainThreadRequest) ar.userObj;
1008 if (ar.exception == null) {
1009 request.result = true;
1010 } else {
1011 request.result = false;
1012 loge("setNetworkSelectionModeManual " + ar.exception);
1013 }
1014 notifyRequester(request);
1015 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001016 break;
1017
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001018 case CMD_GET_MODEM_ACTIVITY_INFO:
1019 request = (MainThreadRequest) msg.obj;
1020 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001021 if (defaultPhone != null) {
1022 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001023 } else {
1024 ResultReceiver result = (ResultReceiver) request.argument;
1025 Bundle bundle = new Bundle();
1026 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1027 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1028 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001029 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001030 break;
1031
1032 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1033 ar = (AsyncResult) msg.obj;
1034 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001035 ResultReceiver result = (ResultReceiver) request.argument;
1036
1037 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001038 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001039 // Update the last modem activity info and the result of the request.
1040 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1041 if (isModemActivityInfoValid(info)) {
1042 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1043 int[] txTimeMs = info.getTransmitTimeMillis();
1044 int[] lastModemTxTimeMs = mLastModemActivityInfo
1045 .getTransmitTimeMillis();
1046 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1047 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1048 }
1049 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1050 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1051 + mLastModemActivityInfo.getSleepTimeMillis());
1052 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1053 + mLastModemActivityInfo.getIdleTimeMillis());
1054 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1055 mLastModemActivityInfo.setReceiveTimeMillis(
1056 info.getReceiveTimeMillis()
1057 + mLastModemActivityInfo.getReceiveTimeMillis());
1058 }
1059 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1060 mLastModemActivityInfo.getSleepTimeMillis(),
1061 mLastModemActivityInfo.getIdleTimeMillis(),
1062 mLastModemActivityInfo.getTransmitTimeMillis(),
1063 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001064 } else {
1065 if (ar.result == null) {
1066 loge("queryModemActivityInfo: Empty response");
1067 } else if (ar.exception instanceof CommandException) {
1068 loge("queryModemActivityInfo: CommandException: " +
1069 ar.exception);
1070 } else {
1071 loge("queryModemActivityInfo: Unknown exception");
1072 }
1073 }
sqian1a1be542020-03-05 11:37:28 -08001074 Bundle bundle = new Bundle();
1075 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1076 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001077 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001078 break;
1079
Meng Wang1a7c35a2016-05-05 20:56:15 -07001080 case CMD_SET_ALLOWED_CARRIERS:
1081 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001082 CarrierRestrictionRules argument =
1083 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001084 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001085 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001086 break;
1087
1088 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1089 ar = (AsyncResult) msg.obj;
1090 request = (MainThreadRequest) ar.userObj;
1091 if (ar.exception == null && ar.result != null) {
1092 request.result = ar.result;
1093 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001094 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1095 if (ar.exception instanceof CommandException) {
1096 loge("setAllowedCarriers: CommandException: " + ar.exception);
1097 CommandException.Error error =
1098 ((CommandException) (ar.exception)).getCommandError();
1099 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1100 request.result =
1101 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1102 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001103 } else {
1104 loge("setAllowedCarriers: Unknown exception");
1105 }
1106 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001107 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001108 break;
1109
1110 case CMD_GET_ALLOWED_CARRIERS:
1111 request = (MainThreadRequest) msg.obj;
1112 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001113 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001114 break;
1115
1116 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1117 ar = (AsyncResult) msg.obj;
1118 request = (MainThreadRequest) ar.userObj;
1119 if (ar.exception == null && ar.result != null) {
1120 request.result = ar.result;
1121 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001122 request.result = new IllegalStateException(
1123 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001124 if (ar.result == null) {
1125 loge("getAllowedCarriers: Empty response");
1126 } else if (ar.exception instanceof CommandException) {
1127 loge("getAllowedCarriers: CommandException: " +
1128 ar.exception);
1129 } else {
1130 loge("getAllowedCarriers: Unknown exception");
1131 }
1132 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001133 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001134 break;
1135
Nathan Haroldb3014052017-01-25 15:57:32 -08001136 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1137 ar = (AsyncResult) msg.obj;
1138 request = (MainThreadRequest) ar.userObj;
1139 if (ar.exception == null && ar.result != null) {
1140 request.result = ar.result;
1141 } else {
1142 request.result = new IllegalArgumentException(
1143 "Failed to retrieve Forbidden Plmns");
1144 if (ar.result == null) {
1145 loge("getForbiddenPlmns: Empty response");
1146 } else {
1147 loge("getForbiddenPlmns: Unknown exception");
1148 }
1149 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001150 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001151 break;
1152
1153 case CMD_GET_FORBIDDEN_PLMNS:
1154 request = (MainThreadRequest) msg.obj;
1155 uiccCard = getUiccCardFromRequest(request);
1156 if (uiccCard == null) {
1157 loge("getForbiddenPlmns() UiccCard is null");
1158 request.result = new IllegalArgumentException(
1159 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001160 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001161 break;
1162 }
1163 Integer appType = (Integer) request.argument;
1164 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1165 if (uiccApp == null) {
1166 loge("getForbiddenPlmns() no app with specified type -- "
1167 + appType);
1168 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001169 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001170 break;
1171 } else {
1172 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1173 + " specified type -- " + appType);
1174 }
1175 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1176 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1177 onCompleted);
1178 break;
1179
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001180 case CMD_SWITCH_SLOTS:
1181 request = (MainThreadRequest) msg.obj;
1182 int[] physicalSlots = (int[]) request.argument;
1183 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1184 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1185 break;
1186
1187 case EVENT_SWITCH_SLOTS_DONE:
1188 ar = (AsyncResult) msg.obj;
1189 request = (MainThreadRequest) ar.userObj;
1190 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001191 notifyRequester(request);
1192 break;
1193 case CMD_GET_NETWORK_SELECTION_MODE:
1194 request = (MainThreadRequest) msg.obj;
1195 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1196 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1197 break;
1198
1199 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1200 ar = (AsyncResult) msg.obj;
1201 request = (MainThreadRequest) ar.userObj;
1202 if (ar.exception != null) {
1203 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1204 } else {
1205 int mode = ((int[]) ar.result)[0];
1206 if (mode == 0) {
1207 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1208 } else {
1209 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1210 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001211 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001212 notifyRequester(request);
1213 break;
1214 case CMD_GET_CDMA_ROAMING_MODE:
1215 request = (MainThreadRequest) msg.obj;
1216 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1217 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1218 break;
1219 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1220 ar = (AsyncResult) msg.obj;
1221 request = (MainThreadRequest) ar.userObj;
1222 if (ar.exception != null) {
1223 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1224 } else {
1225 request.result = ((int[]) ar.result)[0];
1226 }
1227 notifyRequester(request);
1228 break;
1229 case CMD_SET_CDMA_ROAMING_MODE:
1230 request = (MainThreadRequest) msg.obj;
1231 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1232 int mode = (int) request.argument;
1233 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1234 break;
1235 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1236 ar = (AsyncResult) msg.obj;
1237 request = (MainThreadRequest) ar.userObj;
1238 request.result = ar.exception == null;
1239 notifyRequester(request);
1240 break;
1241 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1242 request = (MainThreadRequest) msg.obj;
1243 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1244 int subscriptionMode = (int) request.argument;
1245 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1246 break;
1247 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1248 ar = (AsyncResult) msg.obj;
1249 request = (MainThreadRequest) ar.userObj;
1250 request.result = ar.exception == null;
1251 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001252 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001253 case CMD_GET_ALL_CELL_INFO:
1254 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001255 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001256 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001257 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001258 case EVENT_GET_ALL_CELL_INFO_DONE:
1259 ar = (AsyncResult) msg.obj;
1260 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001261 // If a timeout occurs, the response will be null
1262 request.result = (ar.exception == null && ar.result != null)
1263 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001264 synchronized (request) {
1265 request.notifyAll();
1266 }
1267 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001268 case CMD_REQUEST_CELL_INFO_UPDATE:
1269 request = (MainThreadRequest) msg.obj;
1270 request.phone.requestCellInfoUpdate(request.workSource,
1271 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1272 break;
1273 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1274 ar = (AsyncResult) msg.obj;
1275 request = (MainThreadRequest) ar.userObj;
1276 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1277 try {
1278 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001279 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001280 cb.onError(
1281 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1282 ar.exception.getClass().getName(),
1283 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001284 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001285 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001286 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001287 } else {
1288 // use the result as returned
1289 cb.onCellInfo((List<CellInfo>) ar.result);
1290 }
1291 } catch (RemoteException re) {
1292 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1293 }
1294 break;
1295 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001296 request = (MainThreadRequest) msg.obj;
1297 WorkSource ws = (WorkSource) request.argument;
1298 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001299 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001300 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001301 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001302 ar = (AsyncResult) msg.obj;
1303 request = (MainThreadRequest) ar.userObj;
1304 if (ar.exception == null) {
1305 request.result = ar.result;
1306 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001307 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001308 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001309 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001310 }
1311
1312 synchronized (request) {
1313 request.notifyAll();
1314 }
1315 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001316 case CMD_MODEM_REBOOT:
1317 request = (MainThreadRequest) msg.obj;
1318 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001319 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001320 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001321 case EVENT_CMD_MODEM_REBOOT_DONE:
1322 handleNullReturnEvent(msg, "rebootModem");
1323 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001324 case CMD_REQUEST_ENABLE_MODEM:
1325 request = (MainThreadRequest) msg.obj;
1326 boolean enable = (boolean) request.argument;
1327 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001328 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001329 PhoneConfigurationManager.getInstance()
1330 .enablePhone(request.phone, enable, onCompleted);
1331 break;
1332 case EVENT_ENABLE_MODEM_DONE:
1333 ar = (AsyncResult) msg.obj;
1334 request = (MainThreadRequest) ar.userObj;
1335 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001336 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001337 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001338 if ((boolean) request.result) {
1339 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1340 updateModemStateMetrics();
1341 } else {
1342 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1343 + ar.exception);
1344 }
1345 notifyRequester(request);
1346 break;
1347 case CMD_GET_MODEM_STATUS:
1348 request = (MainThreadRequest) msg.obj;
1349 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1350 PhoneConfigurationManager.getInstance()
1351 .getPhoneStatusFromModem(request.phone, onCompleted);
1352 break;
1353 case EVENT_GET_MODEM_STATUS_DONE:
1354 ar = (AsyncResult) msg.obj;
1355 request = (MainThreadRequest) ar.userObj;
1356 int id = request.phone.getPhoneId();
1357 if (ar.exception == null && ar.result != null) {
1358 request.result = ar.result;
1359 //update the cache as modem status has changed
1360 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1361 (boolean) request.result);
1362 } else {
1363 // Return true if modem status cannot be retrieved. For most cases,
1364 // modem status is on. And for older version modems, GET_MODEM_STATUS
1365 // and disable modem are not supported. Modem is always on.
1366 // TODO: this should be fixed in R to support a third
1367 // status UNKNOWN b/131631629
1368 request.result = true;
1369 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1370 + ar.exception);
1371 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001372 notifyRequester(request);
1373 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001374 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1375 request = (MainThreadRequest) msg.obj;
1376 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1377 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1378 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1379 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1380 break;
1381 }
1382 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1383 ar = (AsyncResult) msg.obj;
1384 request = (MainThreadRequest) ar.userObj;
1385 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1386 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1387 args.second.accept(ar.exception == null);
1388 notifyRequester(request);
1389 break;
1390 }
yincheng zhaod698b842019-09-06 17:06:54 -07001391 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1392 ar = (AsyncResult) msg.obj;
1393 request = (MainThreadRequest) ar.userObj;
1394 if (ar.exception == null && ar.result != null) {
1395 request.result = ar.result;
1396 } else {
1397 request.result = -1;
1398 loge("Failed to set Forbidden Plmns");
1399 if (ar.result == null) {
1400 loge("setForbidenPlmns: Empty response");
1401 } else if (ar.exception != null) {
1402 loge("setForbiddenPlmns: Exception: " + ar.exception);
1403 request.result = -1;
1404 } else {
1405 loge("setForbiddenPlmns: Unknown exception");
1406 }
1407 }
1408 notifyRequester(request);
1409 break;
1410 case CMD_SET_FORBIDDEN_PLMNS:
1411 request = (MainThreadRequest) msg.obj;
1412 uiccCard = getUiccCardFromRequest(request);
1413 if (uiccCard == null) {
1414 loge("setForbiddenPlmns: UiccCard is null");
1415 request.result = -1;
1416 notifyRequester(request);
1417 break;
1418 }
1419 Pair<Integer, List<String>> setFplmnsArgs =
1420 (Pair<Integer, List<String>>) request.argument;
1421 appType = setFplmnsArgs.first;
1422 List<String> fplmns = setFplmnsArgs.second;
1423 uiccApp = uiccCard.getApplicationByType(appType);
1424 if (uiccApp == null) {
1425 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1426 request.result = -1;
1427 loge("Failed to get UICC App");
1428 notifyRequester(request);
1429 } else {
1430 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1431 ((SIMRecords) uiccApp.getIccRecords())
1432 .setForbiddenPlmns(onCompleted, fplmns);
1433 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001434 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001435 case CMD_ERASE_MODEM_CONFIG:
1436 request = (MainThreadRequest) msg.obj;
1437 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1438 defaultPhone.eraseModemConfig(onCompleted);
1439 break;
1440 case EVENT_ERASE_MODEM_CONFIG_DONE:
1441 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001442 break;
zoey chenf95ca592019-12-30 16:11:23 +08001443
1444 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1445 request = (MainThreadRequest) msg.obj;
1446 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1447 Pair<String, String> changed = (Pair<String, String>) request.argument;
1448 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1449 changed.first, changed.second, onCompleted);
1450 break;
1451 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1452 ar = (AsyncResult) msg.obj;
1453 request = (MainThreadRequest) ar.userObj;
1454 if (ar.exception == null) {
1455 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1456 } else {
1457 request.result = msg.arg1;
1458 }
1459 notifyRequester(request);
1460 break;
1461
1462 case CMD_SET_ICC_LOCK_ENABLED:
1463 request = (MainThreadRequest) msg.obj;
1464 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1465 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1466 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1467 enabled.first, enabled.second, onCompleted);
1468 break;
1469 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1470 ar = (AsyncResult) msg.obj;
1471 request = (MainThreadRequest) ar.userObj;
1472 if (ar.exception == null) {
1473 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1474 } else {
1475 request.result = msg.arg1;
1476 }
1477 notifyRequester(request);
1478 break;
1479
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001480 default:
1481 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1482 break;
1483 }
1484 }
Jake Hambye994d462014-02-03 13:10:13 -08001485
Pengquan Menga1bb6272018-09-06 09:59:22 -07001486 private void notifyRequester(MainThreadRequest request) {
1487 synchronized (request) {
1488 request.notifyAll();
1489 }
1490 }
1491
Jake Hambye994d462014-02-03 13:10:13 -08001492 private void handleNullReturnEvent(Message msg, String command) {
1493 AsyncResult ar = (AsyncResult) msg.obj;
1494 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1495 if (ar.exception == null) {
1496 request.result = true;
1497 } else {
1498 request.result = false;
1499 if (ar.exception instanceof CommandException) {
1500 loge(command + ": CommandException: " + ar.exception);
1501 } else {
1502 loge(command + ": Unknown exception");
1503 }
1504 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001505 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001507 }
1508
1509 /**
1510 * Posts the specified command to be executed on the main thread,
1511 * waits for the request to complete, and returns the result.
1512 * @see #sendRequestAsync
1513 */
1514 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001515 return sendRequest(
1516 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001517 }
1518
1519 /**
1520 * Posts the specified command to be executed on the main thread,
1521 * waits for the request to complete, and returns the result.
1522 * @see #sendRequestAsync
1523 */
1524 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1525 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001526 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001527 }
1528
1529 /**
1530 * Posts the specified command to be executed on the main thread,
1531 * waits for the request to complete, and returns the result.
1532 * @see #sendRequestAsync
1533 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001534 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001535 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001536 }
1537
1538 /**
1539 * Posts the specified command to be executed on the main thread,
1540 * waits for the request to complete, and returns the result.
1541 * @see #sendRequestAsync
1542 */
Nathan Harold92bed182018-10-12 18:16:49 -07001543 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1544 return sendRequest(command, argument, subId, null, workSource);
1545 }
1546
1547 /**
1548 * Posts the specified command to be executed on the main thread,
1549 * waits for the request to complete, and returns the result.
1550 * @see #sendRequestAsync
1551 */
1552 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1553 return sendRequest(
1554 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1555 }
1556
1557 /**
1558 * Posts the specified command to be executed on the main thread,
1559 * waits for the request to complete, and returns the result.
1560 * @see #sendRequestAsync
1561 */
1562 private Object sendRequest(
1563 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1565 throw new RuntimeException("This method will deadlock if called from the main thread.");
1566 }
1567
Nathan Harold92bed182018-10-12 18:16:49 -07001568 MainThreadRequest request = null;
1569 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1570 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1571 } else if (phone != null) {
1572 request = new MainThreadRequest(argument, phone, workSource);
1573 } else {
1574 request = new MainThreadRequest(argument, subId, workSource);
1575 }
1576
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 Message msg = mMainThreadHandler.obtainMessage(command, request);
1578 msg.sendToTarget();
1579
1580 // Wait for the request to complete
1581 synchronized (request) {
1582 while (request.result == null) {
1583 try {
1584 request.wait();
1585 } catch (InterruptedException e) {
1586 // Do nothing, go back and wait until the request is complete
1587 }
1588 }
1589 }
1590 return request.result;
1591 }
1592
1593 /**
1594 * Asynchronous ("fire and forget") version of sendRequest():
1595 * Posts the specified command to be executed on the main thread, and
1596 * returns immediately.
1597 * @see #sendRequest
1598 */
1599 private void sendRequestAsync(int command) {
1600 mMainThreadHandler.sendEmptyMessage(command);
1601 }
1602
1603 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001604 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001605 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001606 */
1607 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001608 sendRequestAsync(command, argument, null, null);
1609 }
1610
1611 /**
1612 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1613 * @see {@link #sendRequest(int,Object)}
1614 */
1615 private void sendRequestAsync(
1616 int command, Object argument, Phone phone, WorkSource workSource) {
1617 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001618 Message msg = mMainThreadHandler.obtainMessage(command, request);
1619 msg.sendToTarget();
1620 }
1621
1622 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 * Initialize the singleton PhoneInterfaceManager instance.
1624 * This is only done once, at startup, from PhoneApp.onCreate().
1625 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001626 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001627 synchronized (PhoneInterfaceManager.class) {
1628 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001629 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 } else {
1631 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1632 }
1633 return sInstance;
1634 }
1635 }
1636
1637 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001638 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001639 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001640 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001641 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001642 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1644 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001645 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001646 mTelephonySharedPreferences =
1647 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001648 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001649 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001650
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 publish();
1652 }
1653
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001654 private Phone getDefaultPhone() {
1655 Phone thePhone = getPhone(getDefaultSubscription());
1656 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1657 }
1658
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 private void publish() {
1660 if (DBG) log("publish: " + this);
1661
1662 ServiceManager.addService("phone", this);
1663 }
1664
Stuart Scott584921c2015-01-15 17:10:34 -08001665 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001666 if (request.phone != null) {
1667 return request.phone;
1668 } else {
1669 return getPhoneFromSubId(request.subId);
1670 }
1671 }
1672
1673 private Phone getPhoneFromSubId(int subId) {
1674 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1675 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001676 }
1677
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001678 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1679 Phone phone = getPhoneFromRequest(request);
1680 return phone == null ? null :
1681 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1682 }
1683
Wink Saville36469e72014-06-11 15:17:00 -07001684 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001685 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001686 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001687 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001689 private void sendEraseModemConfig(Phone phone) {
1690 if (phone != null) {
1691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1692 mApp, phone.getSubId(), "eraseModemConfig");
1693 final long identity = Binder.clearCallingIdentity();
1694 try {
1695 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1696 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1697 } finally {
1698 Binder.restoreCallingIdentity(identity);
1699 }
1700 }
1701 }
1702
Peter Wang050bb052020-01-13 23:33:09 -08001703 private boolean isImsAvailableOnDevice() {
1704 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1705 if (pm == null) {
1706 // For some reason package manger is not available.. This will fail internally anyway,
1707 // so do not throw error and allow.
1708 return true;
1709 }
1710 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1711 }
1712
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001714 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001715 }
1716
Wink Savilleb564aae2014-10-23 10:18:09 -07001717 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 if (DBG) log("dial: " + number);
1719 // No permission check needed here: This is just a wrapper around the
1720 // ACTION_DIAL intent, which is available to any app since it puts up
1721 // the UI before it does anything.
1722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001723 final long identity = Binder.clearCallingIdentity();
1724 try {
1725 String url = createTelUrl(number);
1726 if (url == null) {
1727 return;
1728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001730 // PENDING: should we just silently fail if phone is offhook or ringing?
1731 PhoneConstants.State state = mCM.getState(subId);
1732 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1733 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1734 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1735 mApp.startActivity(intent);
1736 }
1737 } finally {
1738 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739 }
1740 }
1741
1742 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001743 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001744 }
1745
Wink Savilleb564aae2014-10-23 10:18:09 -07001746 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 if (DBG) log("call: " + number);
1748
1749 // This is just a wrapper around the ACTION_CALL intent, but we still
1750 // need to do a permission check since we're calling startActivity()
1751 // from the context of the phone app.
1752 enforceCallPermission();
1753
Jordan Liu1617b712019-07-10 15:06:26 -07001754 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 != AppOpsManager.MODE_ALLOWED) {
1756 return;
1757 }
1758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001759 final long identity = Binder.clearCallingIdentity();
1760 try {
1761 String url = createTelUrl(number);
1762 if (url == null) {
1763 return;
1764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001766 boolean isValid = false;
1767 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1768 if (slist != null) {
1769 for (SubscriptionInfo subInfoRecord : slist) {
1770 if (subInfoRecord.getSubscriptionId() == subId) {
1771 isValid = true;
1772 break;
1773 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001774 }
Wink Saville08874612014-08-31 19:19:58 -07001775 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001776 if (!isValid) {
1777 return;
1778 }
Wink Saville08874612014-08-31 19:19:58 -07001779
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001780 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1781 intent.putExtra(SUBSCRIPTION_KEY, subId);
1782 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1783 mApp.startActivity(intent);
1784 } finally {
1785 Binder.restoreCallingIdentity(identity);
1786 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 }
1788
Wink Savilleb564aae2014-10-23 10:18:09 -07001789 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001790 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001791 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1792 }
1793
Wink Savilleb564aae2014-10-23 10:18:09 -07001794 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001795 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001796 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1797 }
1798
Wink Savilleb564aae2014-10-23 10:18:09 -07001799 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001800 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001801
1802 final long identity = Binder.clearCallingIdentity();
1803 try {
1804 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1805 checkSimPin.start();
1806 return checkSimPin.unlockSim(null, pin);
1807 } finally {
1808 Binder.restoreCallingIdentity(identity);
1809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 }
1811
Wink Savilleb564aae2014-10-23 10:18:09 -07001812 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001814
1815 final long identity = Binder.clearCallingIdentity();
1816 try {
1817 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1818 checkSimPuk.start();
1819 return checkSimPuk.unlockSim(puk, pin);
1820 } finally {
1821 Binder.restoreCallingIdentity(identity);
1822 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 }
1824
1825 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001826 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 * a synchronous one.
1828 */
1829 private static class UnlockSim extends Thread {
1830
1831 private final IccCard mSimCard;
1832
1833 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001834 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1835 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836
1837 // For replies from SimCard interface
1838 private Handler mHandler;
1839
1840 // For async handler to identify request type
1841 private static final int SUPPLY_PIN_COMPLETE = 100;
1842
1843 public UnlockSim(IccCard simCard) {
1844 mSimCard = simCard;
1845 }
1846
1847 @Override
1848 public void run() {
1849 Looper.prepare();
1850 synchronized (UnlockSim.this) {
1851 mHandler = new Handler() {
1852 @Override
1853 public void handleMessage(Message msg) {
1854 AsyncResult ar = (AsyncResult) msg.obj;
1855 switch (msg.what) {
1856 case SUPPLY_PIN_COMPLETE:
1857 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1858 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001859 mRetryCount = msg.arg1;
1860 if (ar.exception != null) {
1861 if (ar.exception instanceof CommandException &&
1862 ((CommandException)(ar.exception)).getCommandError()
1863 == CommandException.Error.PASSWORD_INCORRECT) {
1864 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1865 } else {
1866 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1867 }
1868 } else {
1869 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 mDone = true;
1872 UnlockSim.this.notifyAll();
1873 }
1874 break;
1875 }
1876 }
1877 };
1878 UnlockSim.this.notifyAll();
1879 }
1880 Looper.loop();
1881 }
1882
1883 /*
1884 * Use PIN or PUK to unlock SIM card
1885 *
1886 * If PUK is null, unlock SIM card with PIN
1887 *
1888 * If PUK is not null, unlock SIM card with PUK and set PIN code
1889 */
Wink Saville9de0f752013-10-22 19:04:03 -07001890 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891
1892 while (mHandler == null) {
1893 try {
1894 wait();
1895 } catch (InterruptedException e) {
1896 Thread.currentThread().interrupt();
1897 }
1898 }
1899 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1900
1901 if (puk == null) {
1902 mSimCard.supplyPin(pin, callback);
1903 } else {
1904 mSimCard.supplyPuk(puk, pin, callback);
1905 }
1906
1907 while (!mDone) {
1908 try {
1909 Log.d(LOG_TAG, "wait for done");
1910 wait();
1911 } catch (InterruptedException e) {
1912 // Restore the interrupted status
1913 Thread.currentThread().interrupt();
1914 }
1915 }
1916 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001917 int[] resultArray = new int[2];
1918 resultArray[0] = mResult;
1919 resultArray[1] = mRetryCount;
1920 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 }
1922 }
1923
1924 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001925 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001926
1927 }
1928
Wink Savilleb564aae2014-10-23 10:18:09 -07001929 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930 // No permission check needed here: this call is harmless, and it's
1931 // needed for the ServiceState.requestStateUpdate() call (which is
1932 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001933 final long identity = Binder.clearCallingIdentity();
1934 try {
1935 final Phone phone = getPhone(subId);
1936 if (phone != null) {
1937 phone.updateServiceLocation();
1938 }
1939 } finally {
1940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
1943
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001944 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001945 @Override
1946 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001947 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001948 }
1949
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001950 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001951 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1952 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1953 callingFeatureId);
1954 }
1955
1956 @Deprecated
1957 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001958 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001959 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1960 }
1961
1962 @Override
1963 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1964 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001965 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001966 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001967 return false;
1968 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001969
1970 final long identity = Binder.clearCallingIdentity();
1971 try {
1972 return isRadioOnForSubscriber(subId);
1973 } finally {
1974 Binder.restoreCallingIdentity(identity);
1975 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001976 }
1977
1978 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001979 final long identity = Binder.clearCallingIdentity();
1980 try {
1981 final Phone phone = getPhone(subId);
1982 if (phone != null) {
1983 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1984 } else {
1985 return false;
1986 }
1987 } finally {
1988 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990 }
1991
1992 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001993 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 }
Wink Saville36469e72014-06-11 15:17:00 -07001995
Wink Savilleb564aae2014-10-23 10:18:09 -07001996 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001998
1999 final long identity = Binder.clearCallingIdentity();
2000 try {
2001 final Phone phone = getPhone(subId);
2002 if (phone != null) {
2003 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2004 }
2005 } finally {
2006 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002007 }
Wink Saville36469e72014-06-11 15:17:00 -07002008 }
2009
2010 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002011 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002012 }
2013
Wink Savilleb564aae2014-10-23 10:18:09 -07002014 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002015 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002016
2017 final long identity = Binder.clearCallingIdentity();
2018 try {
2019 final Phone phone = getPhone(subId);
2020 if (phone == null) {
2021 return false;
2022 }
2023 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2024 toggleRadioOnOffForSubscriber(subId);
2025 }
2026 return true;
2027 } finally {
2028 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 }
Wink Saville36469e72014-06-11 15:17:00 -07002031
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002032 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002033 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002034 /*
2035 * If any of the Radios are available, it will need to be
2036 * shutdown. So return true if any Radio is available.
2037 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002038 final long identity = Binder.clearCallingIdentity();
2039 try {
2040 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2041 Phone phone = PhoneFactory.getPhone(i);
2042 if (phone != null && phone.isRadioAvailable()) return true;
2043 }
2044 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2045 return false;
2046 } finally {
2047 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002048 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002049 }
2050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002051 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002052 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002053 enforceModifyPermission();
2054
2055 final long identity = Binder.clearCallingIdentity();
2056 try {
2057 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2058 logv("Shutting down Phone " + i);
2059 shutdownRadioUsingPhoneId(i);
2060 }
2061 } finally {
2062 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002063 }
2064 }
2065
2066 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002067 Phone phone = PhoneFactory.getPhone(phoneId);
2068 if (phone != null && phone.isRadioAvailable()) {
2069 phone.shutdownRadio();
2070 }
2071 }
2072
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002074 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002075
2076 final long identity = Binder.clearCallingIdentity();
2077 try {
2078 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2079 if (defaultPhone != null) {
2080 defaultPhone.setRadioPower(turnOn);
2081 return true;
2082 } else {
2083 loge("There's no default phone.");
2084 return false;
2085 }
2086 } finally {
2087 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002088 }
Wink Saville36469e72014-06-11 15:17:00 -07002089 }
2090
Wink Savilleb564aae2014-10-23 10:18:09 -07002091 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002092 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002093
2094 final long identity = Binder.clearCallingIdentity();
2095 try {
2096 final Phone phone = getPhone(subId);
2097 if (phone != null) {
2098 phone.setRadioPower(turnOn);
2099 return true;
2100 } else {
2101 return false;
2102 }
2103 } finally {
2104 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 }
2107
Wink Saville36469e72014-06-11 15:17:00 -07002108 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002109 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 public boolean enableDataConnectivity() {
2111 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002112
2113 final long identity = Binder.clearCallingIdentity();
2114 try {
2115 int subId = mSubscriptionController.getDefaultDataSubId();
2116 final Phone phone = getPhone(subId);
2117 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002118 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002119 return true;
2120 } else {
2121 return false;
2122 }
2123 } finally {
2124 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 }
2127
Wink Saville36469e72014-06-11 15:17:00 -07002128 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002129 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002130 public boolean disableDataConnectivity() {
2131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002132
2133 final long identity = Binder.clearCallingIdentity();
2134 try {
2135 int subId = mSubscriptionController.getDefaultDataSubId();
2136 final Phone phone = getPhone(subId);
2137 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002138 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002139 return true;
2140 } else {
2141 return false;
2142 }
2143 } finally {
2144 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002145 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146 }
2147
Sanket Padawe356d7632015-06-22 14:03:32 -07002148 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002149 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002150 final long identity = Binder.clearCallingIdentity();
2151 try {
2152 final Phone phone = getPhone(subId);
2153 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002154 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002155 } else {
2156 return false;
2157 }
2158 } finally {
2159 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002160 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 }
2162
2163 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002164 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002165 }
2166
pkanwarae03a6b2016-11-06 20:37:09 -08002167 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002168 enforceCallPermission();
2169
2170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2173 return;
2174 }
2175 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2176 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2177 } finally {
2178 Binder.restoreCallingIdentity(identity);
2179 }
pkanwar32d516d2016-10-14 19:37:38 -07002180 };
2181
Wink Savilleb564aae2014-10-23 10:18:09 -07002182 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002184
2185 final long identity = Binder.clearCallingIdentity();
2186 try {
2187 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2188 return false;
2189 }
2190 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2191 } finally {
2192 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 }
2195
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002197 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002198 }
2199
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002200 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002201 final long identity = Binder.clearCallingIdentity();
2202 try {
2203 Phone phone = PhoneFactory.getPhone(slotIndex);
2204 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2205 PhoneConstantConversions.convertCallState(phone.getState());
2206 } finally {
2207 Binder.restoreCallingIdentity(identity);
2208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 }
2210
Sanket Padawe356d7632015-06-22 14:03:32 -07002211 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002212 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002213 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2214 }
2215
2216 @Override
2217 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002218 final long identity = Binder.clearCallingIdentity();
2219 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002220 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002221 if (phone != null) {
2222 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2223 } else {
2224 return PhoneConstantConversions.convertDataState(
2225 PhoneConstants.DataState.DISCONNECTED);
2226 }
2227 } finally {
2228 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 }
2231
Sanket Padawe356d7632015-06-22 14:03:32 -07002232 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002233 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002234 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2235 }
2236
2237 @Override
2238 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002239 final long identity = Binder.clearCallingIdentity();
2240 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002241 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242 if (phone != null) {
2243 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2244 } else {
2245 return TelephonyManager.DATA_ACTIVITY_NONE;
2246 }
2247 } finally {
2248 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 }
2251
2252 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002253 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002254 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002255 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002256
2257 LocationAccessPolicy.LocationPermissionResult locationResult =
2258 LocationAccessPolicy.checkLocationPermission(mApp,
2259 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2260 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002261 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002262 .setCallingPid(Binder.getCallingPid())
2263 .setCallingUid(Binder.getCallingUid())
2264 .setMethod("getCellLocation")
2265 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2266 .build());
2267 switch (locationResult) {
2268 case DENIED_HARD:
2269 throw new SecurityException("Not allowed to access cell location");
2270 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002271 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2272 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 }
2274
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002275 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002276 final long identity = Binder.clearCallingIdentity();
2277 try {
2278 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002279 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002280 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002281 } finally {
2282 Binder.restoreCallingIdentity(identity);
2283 }
Svetoslav64fad262015-04-14 14:35:21 -07002284 }
2285
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002287 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2288 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002289 if (!TextUtils.isEmpty(callingPackage)) {
2290 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002291 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2292 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002293 return "";
2294 }
2295 }
2296
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002297 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2298 // registered cell info, so return a NULL country instead.
2299 final long identity = Binder.clearCallingIdentity();
2300 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002301 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2302 // Get default phone in this case.
2303 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2304 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002305 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002306 // Todo: fix this when we can get the actual cellular network info when the device
2307 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002308 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002309 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2310 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002311 return "";
2312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002313 Phone phone = PhoneFactory.getPhone(phoneId);
2314 if (phone != null) {
2315 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002316 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002317 if (sst != null) {
2318 LocaleTracker lt = sst.getLocaleTracker();
2319 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002320 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2321 return lt.getCurrentCountry();
2322 } else if (emergencyNumberTracker != null) {
2323 return emergencyNumberTracker.getEmergencyCountryIso();
2324 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002325 }
2326 }
2327 }
2328 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002329 } finally {
2330 Binder.restoreCallingIdentity(identity);
2331 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002332 }
2333
2334 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002336 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002337 }
2338
Sanket Padawe356d7632015-06-22 14:03:32 -07002339 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002340 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 mApp.enforceCallingOrSelfPermission(
2342 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002343
2344 final long identity = Binder.clearCallingIdentity();
2345 try {
2346 final Phone phone = getPhone(subId);
2347 if (phone != null) {
2348 phone.enableLocationUpdates();
2349 }
2350 } finally {
2351 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 }
2354
2355 @Override
2356 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002357 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002358 }
2359
Sanket Padawe356d7632015-06-22 14:03:32 -07002360 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002361 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 mApp.enforceCallingOrSelfPermission(
2363 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002364
2365 final long identity = Binder.clearCallingIdentity();
2366 try {
2367 final Phone phone = getPhone(subId);
2368 if (phone != null) {
2369 phone.disableLocationUpdates();
2370 }
2371 } finally {
2372 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 }
2375
Nathan Harold31d7ff32018-10-15 20:20:30 -07002376 /**
2377 * Returns the target SDK version number for a given package name.
2378 *
Nathan Haroldec184742019-07-10 17:04:16 -07002379 * This call MUST be invoked before clearing the calling UID.
2380 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002381 * @return target SDK if the package is found or INT_MAX.
2382 */
2383 private int getTargetSdk(String packageName) {
2384 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002385 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002386 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002387 if (ai != null) return ai.targetSdkVersion;
2388 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002389 loge("Failed to get package info for pkg="
2390 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002391 }
2392 return Integer.MAX_VALUE;
2393 }
2394
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 @Override
2396 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002397 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2398 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002399 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002400 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2401 throw new SecurityException(
2402 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2403 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002404
Jordan Liu1617b712019-07-10 15:06:26 -07002405 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2407 return null;
2408 }
Svetoslav64fad262015-04-14 14:35:21 -07002409
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002410 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002412 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002413 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414
Nathan Haroldf180aac2018-06-01 18:43:55 -07002415 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2416 for (CellInfo ci : info) {
2417 if (ci instanceof CellInfoGsm) {
2418 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2419 } else if (ci instanceof CellInfoWcdma) {
2420 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002423 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 }
2425
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002426 private List<CellInfo> getCachedCellInfo() {
2427 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2428 for (Phone phone : PhoneFactory.getPhones()) {
2429 List<CellInfo> info = phone.getAllCellInfo();
2430 if (info != null) cellInfos.addAll(info);
2431 }
2432 return cellInfos;
2433 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002434
2435 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002436 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002437 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002438 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002439
2440 LocationAccessPolicy.LocationPermissionResult locationResult =
2441 LocationAccessPolicy.checkLocationPermission(mApp,
2442 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2443 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002444 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002445 .setCallingPid(Binder.getCallingPid())
2446 .setCallingUid(Binder.getCallingUid())
2447 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002448 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002449 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2450 .build());
2451 switch (locationResult) {
2452 case DENIED_HARD:
2453 throw new SecurityException("Not allowed to access cell info");
2454 case DENIED_SOFT:
2455 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 }
2457
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002458 final int targetSdk = getTargetSdk(callingPackage);
2459 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2460 return getCachedCellInfo();
2461 }
2462
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002463 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002464 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2468 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002469 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002470 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002471 if (info != null) cellInfos.addAll(info);
2472 }
2473 return cellInfos;
2474 } finally {
2475 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 }
2477 }
2478
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002479 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002480 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2481 String callingFeatureId) {
2482 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2483 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002484 }
2485
2486 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002487 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2488 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002489 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002490 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002491 }
2492
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002493 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2494 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002495 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002496 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002497
2498 LocationAccessPolicy.LocationPermissionResult locationResult =
2499 LocationAccessPolicy.checkLocationPermission(mApp,
2500 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2501 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002502 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002503 .setCallingPid(Binder.getCallingPid())
2504 .setCallingUid(Binder.getCallingUid())
2505 .setMethod("requestCellInfoUpdate")
2506 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2507 .build());
2508 switch (locationResult) {
2509 case DENIED_HARD:
2510 throw new SecurityException("Not allowed to access cell info");
2511 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002512 try {
2513 cb.onCellInfo(new ArrayList<CellInfo>());
2514 } catch (RemoteException re) {
2515 // Drop without consequences
2516 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002517 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002518 }
2519
Nathan Harolda939a962019-05-09 10:13:47 -07002520
2521 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002522 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2523
2524 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2525 }
2526
2527 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002529 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002530 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002531
2532 final long identity = Binder.clearCallingIdentity();
2533 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002534 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002535 } finally {
2536 Binder.restoreCallingIdentity(identity);
2537 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002538 }
2539
Shishir Agrawala9f32182016-04-12 12:00:16 -07002540 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002541 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002542 Phone phone = PhoneFactory.getPhone(slotIndex);
2543 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002544 return null;
2545 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002546 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002547 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002548 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002549 return null;
2550 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002551
2552 final long identity = Binder.clearCallingIdentity();
2553 try {
2554 return phone.getImei();
2555 } finally {
2556 Binder.restoreCallingIdentity(identity);
2557 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002558 }
2559
2560 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002561 public String getTypeAllocationCodeForSlot(int slotIndex) {
2562 Phone phone = PhoneFactory.getPhone(slotIndex);
2563 String tac = null;
2564 if (phone != null) {
2565 String imei = phone.getImei();
2566 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2567 }
2568 return tac;
2569 }
2570
2571 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002572 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002573 Phone phone = PhoneFactory.getPhone(slotIndex);
2574 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002575 return null;
2576 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002577
Jeff Davidson913390f2018-02-23 17:11:49 -08002578 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002579 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002580 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002581 return null;
2582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 return phone.getMeid();
2587 } finally {
2588 Binder.restoreCallingIdentity(identity);
2589 }
Jack Yu2af8d712017-03-15 17:14:14 -07002590 }
2591
2592 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002593 public String getManufacturerCodeForSlot(int slotIndex) {
2594 Phone phone = PhoneFactory.getPhone(slotIndex);
2595 String manufacturerCode = null;
2596 if (phone != null) {
2597 String meid = phone.getMeid();
2598 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2599 }
2600 return manufacturerCode;
2601 }
2602
2603 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002604 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2605 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002606 Phone phone = PhoneFactory.getPhone(slotIndex);
2607 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002608 return null;
2609 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002610 int subId = phone.getSubId();
2611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002612 mApp, subId, callingPackage, callingFeatureId,
2613 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002614 return null;
2615 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616
2617 final long identity = Binder.clearCallingIdentity();
2618 try {
2619 return phone.getDeviceSvn();
2620 } finally {
2621 Binder.restoreCallingIdentity(identity);
2622 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002623 }
2624
fionaxu43304da2017-11-27 22:51:16 -08002625 @Override
2626 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 final Phone phone = getPhone(subId);
2630 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
2633 }
fionaxu43304da2017-11-27 22:51:16 -08002634 }
2635
2636 @Override
2637 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638 final long identity = Binder.clearCallingIdentity();
2639 try {
2640 final Phone phone = getPhone(subId);
2641 return phone == null ? null : phone.getCarrierName();
2642 } finally {
2643 Binder.restoreCallingIdentity(identity);
2644 }
fionaxu43304da2017-11-27 22:51:16 -08002645 }
2646
calvinpanffe225e2018-11-01 19:43:06 +08002647 @Override
chen xu0026ca62019-03-06 15:28:50 -08002648 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002649 final long identity = Binder.clearCallingIdentity();
2650 try {
2651 final Phone phone = getPhone(subId);
2652 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002653 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002654 } finally {
2655 Binder.restoreCallingIdentity(identity);
2656 }
2657 }
2658
2659 @Override
chen xu0026ca62019-03-06 15:28:50 -08002660 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002661 final long identity = Binder.clearCallingIdentity();
2662 try {
2663 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002664 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002665 } finally {
2666 Binder.restoreCallingIdentity(identity);
2667 }
2668 }
2669
chen xu651eec72018-11-11 19:03:44 -08002670 @Override
chen xu864e11c2018-12-06 22:10:03 -08002671 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2672 if (!isSubscriptionMccMnc) {
2673 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2674 }
chen xu651eec72018-11-11 19:03:44 -08002675 final Phone phone = PhoneFactory.getPhone(slotIndex);
2676 if (phone == null) {
2677 return TelephonyManager.UNKNOWN_CARRIER_ID;
2678 }
2679 final long identity = Binder.clearCallingIdentity();
2680 try {
2681 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2682 } finally {
2683 Binder.restoreCallingIdentity(identity);
2684 }
2685 }
2686
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 //
2688 // Internal helper methods.
2689 //
2690
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002691 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2693 *
2694 * @throws SecurityException if the caller does not have the required permission
2695 */
2696 private void enforceModifyPermission() {
2697 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2698 }
2699
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002700 /**
2701 * Make sure the caller is system.
2702 *
2703 * @throws SecurityException if the caller is not system.
2704 */
2705 private void enforceSystemCaller() {
2706 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2707 throw new SecurityException("Caller must be system");
2708 }
2709 }
2710
Shuo Qianf2b2df42019-11-13 17:43:31 -08002711 private void enforceActiveEmergencySessionPermission() {
2712 mApp.enforceCallingOrSelfPermission(
2713 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2714 }
2715
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 /**
2717 * Make sure the caller has the CALL_PHONE permission.
2718 *
2719 * @throws SecurityException if the caller does not have the required permission
2720 */
2721 private void enforceCallPermission() {
2722 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2723 }
2724
paulhu423b5f22019-08-23 19:17:33 +08002725 private void enforceSettingsPermission() {
2726 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002727 }
2728
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 private String createTelUrl(String number) {
2730 if (TextUtils.isEmpty(number)) {
2731 return null;
2732 }
2733
Jake Hambye994d462014-02-03 13:10:13 -08002734 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735 }
2736
Ihab Awadf9e92732013-12-05 18:02:52 -08002737 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2739 }
2740
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002741 private static void logv(String msg) {
2742 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2743 }
2744
Ihab Awadf9e92732013-12-05 18:02:52 -08002745 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2747 }
2748
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002749 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002750 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002751 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002752 }
2753
Sanket Padawe356d7632015-06-22 14:03:32 -07002754 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002755 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756 final long identity = Binder.clearCallingIdentity();
2757 try {
2758 final Phone phone = PhoneFactory.getPhone(slotIndex);
2759 if (phone == null) {
2760 return PhoneConstants.PHONE_TYPE_NONE;
2761 } else {
2762 return phone.getPhoneType();
2763 }
2764 } finally {
2765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002766 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002767 }
2768
2769 /**
2770 * Returns the CDMA ERI icon index to display
2771 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002772 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002773 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2774 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2775 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002776 }
2777
Sanket Padawe356d7632015-06-22 14:03:32 -07002778 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002779 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2780 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002781 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002782 mApp, subId, callingPackage, callingFeatureId,
2783 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002784 return -1;
2785 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786
2787 final long identity = Binder.clearCallingIdentity();
2788 try {
2789 final Phone phone = getPhone(subId);
2790 if (phone != null) {
2791 return phone.getCdmaEriIconIndex();
2792 } else {
2793 return -1;
2794 }
2795 } finally {
2796 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002797 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798 }
2799
2800 /**
2801 * Returns the CDMA ERI icon mode,
2802 * 0 - ON
2803 * 1 - FLASHING
2804 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002805 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002806 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2807 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2808 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002809 }
2810
Sanket Padawe356d7632015-06-22 14:03:32 -07002811 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002812 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2813 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002814 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002815 mApp, subId, callingPackage, callingFeatureId,
2816 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002817 return -1;
2818 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 final Phone phone = getPhone(subId);
2823 if (phone != null) {
2824 return phone.getCdmaEriIconMode();
2825 } else {
2826 return -1;
2827 }
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 }
2832
2833 /**
2834 * Returns the CDMA ERI text,
2835 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002836 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002837 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2838 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2839 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002840 }
2841
Sanket Padawe356d7632015-06-22 14:03:32 -07002842 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002843 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2844 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002845 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002846 mApp, subId, callingPackage, callingFeatureId,
2847 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002848 return null;
2849 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850
2851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 final Phone phone = getPhone(subId);
2854 if (phone != null) {
2855 return phone.getCdmaEriText();
2856 } else {
2857 return null;
2858 }
2859 } finally {
2860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 }
2863
2864 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002865 * Returns the CDMA MDN.
2866 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002867 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002868 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2870 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002871
2872 final long identity = Binder.clearCallingIdentity();
2873 try {
2874 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002875 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 return phone.getLine1Number();
2877 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002878 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879 return null;
2880 }
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002883 }
2884 }
2885
2886 /**
2887 * Returns the CDMA MIN.
2888 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002889 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002890 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2892 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002893
2894 final long identity = Binder.clearCallingIdentity();
2895 try {
2896 final Phone phone = getPhone(subId);
2897 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2898 return phone.getCdmaMin();
2899 } else {
2900 return null;
2901 }
2902 } finally {
2903 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002904 }
2905 }
2906
Hall Liud892bec2018-11-30 14:51:45 -08002907 @Override
2908 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2909 INumberVerificationCallback callback, String callingPackage) {
2910 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2911 != PERMISSION_GRANTED) {
2912 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2913 }
2914 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2915
2916 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2917 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2918 throw new SecurityException("Calling package must be configured in the device config");
2919 }
2920
2921 if (range == null) {
2922 throw new NullPointerException("Range must be non-null");
2923 }
2924
2925 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002926 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002927
2928 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2929 }
2930
Junda Liuca05d5d2014-08-14 22:36:34 -07002931 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002932 * Returns true if CDMA provisioning needs to run.
2933 */
2934 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002935 final long identity = Binder.clearCallingIdentity();
2936 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002937 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 } finally {
2939 Binder.restoreCallingIdentity(identity);
2940 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002941 }
2942
2943 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002944 * Sets the voice mail number of a given subId.
2945 */
2946 @Override
2947 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002948 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2949 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002950
2951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2954 new Pair<String, String>(alphaTag, number), new Integer(subId));
2955 return success;
2956 } finally {
2957 Binder.restoreCallingIdentity(identity);
2958 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002959 }
2960
Ta-wei Yen87c49842016-05-13 21:19:52 -07002961 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002962 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2963 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002964 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2965 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002966 if (!TextUtils.equals(callingPackage, systemDialer)) {
2967 throw new SecurityException("caller must be system dialer");
2968 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002969
2970 final long identity = Binder.clearCallingIdentity();
2971 try {
2972 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2973 if (phoneAccountHandle == null) {
2974 return null;
2975 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002976 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002977 } finally {
2978 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002979 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002980 }
2981
2982 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002983 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2984 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002985 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002987 mApp, subId, callingPackage, callingFeatureId,
2988 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002989 return null;
2990 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002992 final long identity = Binder.clearCallingIdentity();
2993 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002994 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002995 } finally {
2996 Binder.restoreCallingIdentity(identity);
2997 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002998 }
2999
3000 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003001 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3002 VisualVoicemailSmsFilterSettings settings) {
3003 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003004
3005 final long identity = Binder.clearCallingIdentity();
3006 try {
3007 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003008 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003009 } finally {
3010 Binder.restoreCallingIdentity(identity);
3011 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003012 }
3013
3014 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003015 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017
3018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003021 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 } finally {
3023 Binder.restoreCallingIdentity(identity);
3024 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003025 }
3026
3027 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003028 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3029 String callingPackage, int subId) {
3030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003031
3032 final long identity = Binder.clearCallingIdentity();
3033 try {
3034 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003035 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003039 }
3040
3041 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003042 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003043 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003044
3045 final long identity = Binder.clearCallingIdentity();
3046 try {
3047 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003048 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049 } finally {
3050 Binder.restoreCallingIdentity(identity);
3051 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003052 }
3053
3054 @Override
3055 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3056 String number, int port, String text, PendingIntent sentIntent) {
3057 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003058 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003059 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003060 SmsController smsController = PhoneFactory.getSmsController();
3061 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3062 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003063 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003064
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003065 /**
fionaxu0152e512016-11-14 13:36:14 -08003066 * Sets the voice activation state of a given subId.
3067 */
3068 @Override
3069 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3071 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003072
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 final Phone phone = getPhone(subId);
3076 if (phone != null) {
3077 phone.setVoiceActivationState(activationState);
3078 } else {
3079 loge("setVoiceActivationState fails with invalid subId: " + subId);
3080 }
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003083 }
3084 }
3085
3086 /**
3087 * Sets the data activation state of a given subId.
3088 */
3089 @Override
3090 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3092 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003093
3094 final long identity = Binder.clearCallingIdentity();
3095 try {
3096 final Phone phone = getPhone(subId);
3097 if (phone != null) {
3098 phone.setDataActivationState(activationState);
3099 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003100 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101 }
3102 } finally {
3103 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003104 }
3105 }
3106
3107 /**
3108 * Returns the voice activation state of a given subId.
3109 */
3110 @Override
3111 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003112 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113
fionaxu0152e512016-11-14 13:36:14 -08003114 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 if (phone != null) {
3118 return phone.getVoiceActivationState();
3119 } else {
3120 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3121 }
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003124 }
3125 }
3126
3127 /**
3128 * Returns the data activation state of a given subId.
3129 */
3130 @Override
3131 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003132 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003133
fionaxu0152e512016-11-14 13:36:14 -08003134 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 if (phone != null) {
3138 return phone.getDataActivationState();
3139 } else {
3140 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3141 }
3142 } finally {
3143 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003144 }
3145 }
3146
3147 /**
Wink Saville36469e72014-06-11 15:17:00 -07003148 * Returns the unread count of voicemails for a subId
3149 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003150 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003151 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3152 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003154 mApp, subId, callingPackage, callingFeatureId,
3155 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003156 return 0;
3157 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003158 final long identity = Binder.clearCallingIdentity();
3159 try {
3160 final Phone phone = getPhone(subId);
3161 if (phone != null) {
3162 return phone.getVoiceMessageCount();
3163 } else {
3164 return 0;
3165 }
3166 } finally {
3167 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003169 }
3170
3171 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003172 * returns true, if the device is in a state where both voice and data
3173 * are supported simultaneously. This can change based on location or network condition.
3174 */
3175 @Override
3176 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003177 final long identity = Binder.clearCallingIdentity();
3178 try {
3179 final Phone phone = getPhone(subId);
3180 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3181 } finally {
3182 Binder.restoreCallingIdentity(identity);
3183 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003184 }
3185
3186 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003187 * Send the dialer code if called from the current default dialer or the caller has
3188 * carrier privilege.
3189 * @param inputCode The dialer code to send
3190 */
3191 @Override
3192 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003193 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003194 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003195 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3196 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003197 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003198 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003199 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003200 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201
3202 final long identity = Binder.clearCallingIdentity();
3203 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003204 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 } finally {
3206 Binder.restoreCallingIdentity(identity);
3207 }
fionaxu235cc5e2017-03-06 22:25:57 -08003208 }
3209
Pengquan Menga1bb6272018-09-06 09:59:22 -07003210 @Override
3211 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003212 TelephonyPermissions
3213 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3214 mApp, subId, "getNetworkSelectionMode");
3215 final long identity = Binder.clearCallingIdentity();
3216 try {
3217 if (!isActiveSubscription(subId)) {
3218 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3219 }
3220 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3221 } finally {
3222 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003223 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003224 }
3225
Brad Ebinger35c841c2018-10-01 10:40:55 -07003226 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003227 public boolean isInEmergencySmsMode() {
3228 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3229 final long identity = Binder.clearCallingIdentity();
3230 try {
3231 for (Phone phone : PhoneFactory.getPhones()) {
3232 if (phone.isInEmergencySmsMode()) {
3233 return true;
3234 }
3235 }
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
3238 }
3239 return false;
3240 }
3241
shilu366312e2019-12-17 09:28:10 -08003242 /**
3243 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3244 * @param subId The subscription to use to check the configuration.
3245 * @param c The callback that will be used to send the result.
3246 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003247 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003248 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3249 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003250 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3251 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003252
Brad Ebinger77b832e2019-10-17 17:03:22 -07003253 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3254 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3255 "IMS not available on device.");
3256 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003257 final long token = Binder.clearCallingIdentity();
3258 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003259 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003260 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003261 .addRegistrationCallbackForSubscription(c, subId);
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(token);
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 * @param c The callback that will be used to send the result.
3273 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003275 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003276 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3277 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003278 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3279 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3280 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003281 final long token = Binder.clearCallingIdentity();
3282 try {
3283 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3284 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3285 .removeRegistrationCallbackForSubscription(c, subId);
3286 } catch (ImsException e) {
3287 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3288 + "is inactive, ignoring unregister.");
3289 // If the subscription is no longer active, just return, since the callback
3290 // will already have been removed internally.
3291 } finally {
3292 Binder.restoreCallingIdentity(token);
3293 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003294 }
3295
Brad Ebinger774ba362019-10-22 17:36:18 -07003296 /**
3297 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3298 */
3299 @Override
3300 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3301 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3302 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3303 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3304 "IMS not available on device.");
3305 }
3306 final long token = Binder.clearCallingIdentity();
3307 try {
3308 Phone phone = getPhone(subId);
3309 if (phone == null) {
3310 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3311 + subId + "'");
3312 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3313 }
3314 phone.getImsRegistrationState(regState -> {
3315 try {
3316 consumer.accept((regState == null)
3317 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3318 } catch (RemoteException e) {
3319 // Ignore if the remote process is no longer available to call back.
3320 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3321 }
3322 });
3323 } finally {
3324 Binder.restoreCallingIdentity(token);
3325 }
3326 }
3327
3328 /**
3329 * Get the transport type for the IMS service registration state.
3330 */
3331 @Override
3332 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003333 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3334 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003335 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3336 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3337 "IMS not available on device.");
3338 }
3339 final long token = Binder.clearCallingIdentity();
3340 try {
3341 Phone phone = getPhone(subId);
3342 if (phone == null) {
3343 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3344 + subId + "'");
3345 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3346 }
3347 phone.getImsRegistrationTech(regTech -> {
3348 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3349 int regTechConverted = (regTech == null)
3350 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3351 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3352 regTechConverted);
3353 try {
3354 consumer.accept(regTechConverted);
3355 } catch (RemoteException e) {
3356 // Ignore if the remote process is no longer available to call back.
3357 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3358 }
3359 });
3360 } finally {
3361 Binder.restoreCallingIdentity(token);
3362 }
3363 }
3364
shilu366312e2019-12-17 09:28:10 -08003365 /**
3366 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3367 * @param subId The subscription to use to check the configuration.
3368 * @param c The callback that will be used to send the result.
3369 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003370 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003371 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3372 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003373 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3374 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003375 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3376 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3377 "IMS not available on device.");
3378 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003379 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3380 final long token = Binder.clearCallingIdentity();
3381 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003382 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003384 } catch (ImsException e) {
3385 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003386 } finally {
3387 Binder.restoreCallingIdentity(token);
3388 }
3389 }
3390
shilu366312e2019-12-17 09:28:10 -08003391 /**
3392 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3393 * @param subId The subscription to use to check the configuration.
3394 * @param c The callback that will be used to send the result.
3395 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003396 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003397 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003398 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3399 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003400 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3401 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3402 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003403
3404 final long token = Binder.clearCallingIdentity();
3405 try {
3406 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3407 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003408 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003409 } catch (ImsException e) {
3410 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3411 + "is inactive, ignoring unregister.");
3412 // If the subscription is no longer active, just return, since the callback
3413 // will already have been removed internally.
3414 } finally {
3415 Binder.restoreCallingIdentity(token);
3416 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003417 }
3418
3419 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003420 public boolean isCapable(int subId, int capability, int regTech) {
3421 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003422 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3423 final long token = Binder.clearCallingIdentity();
3424 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003425 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003427 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003428 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3429 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003430 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003431 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3432 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003433 } finally {
3434 Binder.restoreCallingIdentity(token);
3435 }
3436 }
3437
3438 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003439 public boolean isAvailable(int subId, int capability, int regTech) {
3440 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003441 final long token = Binder.clearCallingIdentity();
3442 try {
3443 Phone phone = getPhone(subId);
3444 if (phone == null) return false;
3445 return phone.isImsCapabilityAvailable(capability, regTech);
3446 } finally {
3447 Binder.restoreCallingIdentity(token);
3448 }
3449 }
3450
Brad Ebinger77b832e2019-10-17 17:03:22 -07003451 /**
3452 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3453 * subscription.
3454 * @param subId The subscription to use to check the configuration.
3455 * @param callback The callback that will be used to send the result.
3456 * @param capability The MmTelFeature capability that will be used to send the result.
3457 * @param transportType The transport type of the MmTelFeature capability.
3458 */
3459 @Override
3460 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3461 int transportType) {
3462 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3463 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3464 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3465 "IMS not available on device.");
3466 }
3467 final long token = Binder.clearCallingIdentity();
3468 try {
3469 int slotId = getSlotIndex(subId);
3470 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3471 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3472 + subId + "'");
3473 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3474 }
3475 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3476 transportType, aBoolean -> {
3477 try {
3478 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3479 } catch (RemoteException e) {
3480 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3481 + "running. Ignore");
3482 }
3483 });
3484 } finally {
3485 Binder.restoreCallingIdentity(token);
3486 }
3487 }
3488
shilu366312e2019-12-17 09:28:10 -08003489 /**
3490 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3491 * @param subId The subscription to use to check the configuration.
3492 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003493 @Override
3494 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003495 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3496 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003497
Brad Ebinger35c841c2018-10-01 10:40:55 -07003498 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3499 final long token = Binder.clearCallingIdentity();
3500 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003501 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003502 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003503 } catch (ImsException e) {
3504 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003505 } finally {
3506 Binder.restoreCallingIdentity(token);
3507 }
3508 }
3509
3510 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003511 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003513 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003514 final long identity = Binder.clearCallingIdentity();
3515 try {
3516 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003517 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003518 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003519 } catch (ImsException e) {
3520 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003521 } finally {
3522 Binder.restoreCallingIdentity(identity);
3523 }
3524 }
3525
shilu366312e2019-12-17 09:28:10 -08003526 /**
3527 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3528 * @param subId The subscription to use to check the configuration.
3529 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003530 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003531 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003532 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3533 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003537 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3538 } catch (ImsException e) {
3539 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003540 } finally {
3541 Binder.restoreCallingIdentity(identity);
3542 }
3543 }
3544
3545 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003546 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003548 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003552 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003553 } catch (ImsException e) {
3554 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
3558 }
3559
shilu366312e2019-12-17 09:28:10 -08003560 /**
3561 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3562 * @param subId The subscription to use to check the configuration.
3563 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003564 @Override
3565 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003566 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3567 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003571 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003573 } catch (ImsException e) {
3574 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 } finally {
3576 Binder.restoreCallingIdentity(identity);
3577 }
3578 }
3579
3580 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003581 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003583 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003584 final long identity = Binder.clearCallingIdentity();
3585 try {
3586 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003587 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003588 } catch (ImsException e) {
3589 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003590 } finally {
3591 Binder.restoreCallingIdentity(identity);
3592 }
3593 }
3594
shilu366312e2019-12-17 09:28:10 -08003595 /**
3596 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3597 * @param subId The subscription to use to check the configuration.
3598 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003599 @Override
3600 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003601 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3602 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003603 final long identity = Binder.clearCallingIdentity();
3604 try {
3605 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003606 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003607 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003608 } catch (ImsException e) {
3609 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003610 } finally {
3611 Binder.restoreCallingIdentity(identity);
3612 }
3613 }
3614
3615 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003616 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003618 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003619 final long identity = Binder.clearCallingIdentity();
3620 try {
3621 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003622 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003623 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003624 } catch (ImsException e) {
3625 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003626 } finally {
3627 Binder.restoreCallingIdentity(identity);
3628 }
3629 }
3630
3631 @Override
3632 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3634 "setVoWiFiNonPersistent");
3635 final long identity = Binder.clearCallingIdentity();
3636 try {
3637 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003638 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003639 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003640 } catch (ImsException e) {
3641 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003642 } finally {
3643 Binder.restoreCallingIdentity(identity);
3644 }
3645 }
3646
shilu366312e2019-12-17 09:28:10 -08003647 /**
3648 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3649 * @param subId The subscription to use to check the configuration.
3650 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003651 @Override
3652 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003653 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3654 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003658 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003659 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003660 } catch (ImsException e) {
3661 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003662 } finally {
3663 Binder.restoreCallingIdentity(identity);
3664 }
3665 }
3666
3667 @Override
3668 public void setVoWiFiModeSetting(int subId, int mode) {
3669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3670 "setVoWiFiModeSetting");
3671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003674 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003675 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003676 } catch (ImsException e) {
3677 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003678 } finally {
3679 Binder.restoreCallingIdentity(identity);
3680 }
3681 }
3682
3683 @Override
3684 public int getVoWiFiRoamingModeSetting(int subId) {
3685 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3686 final long identity = Binder.clearCallingIdentity();
3687 try {
3688 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003689 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003690 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003691 } catch (ImsException e) {
3692 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003693 } finally {
3694 Binder.restoreCallingIdentity(identity);
3695 }
3696 }
3697
3698 @Override
3699 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3701 "setVoWiFiRoamingModeSetting");
3702 final long identity = Binder.clearCallingIdentity();
3703 try {
3704 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003705 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003706 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003707 } catch (ImsException e) {
3708 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003709 } finally {
3710 Binder.restoreCallingIdentity(identity);
3711 }
3712 }
3713
3714 @Override
3715 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3717 "setRttCapabilityEnabled");
3718 final long identity = Binder.clearCallingIdentity();
3719 try {
3720 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003721 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3722 } catch (ImsException e) {
3723 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 } finally {
3725 Binder.restoreCallingIdentity(identity);
3726 }
3727 }
3728
shilu366312e2019-12-17 09:28:10 -08003729 /**
3730 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3731 * @param subId The subscription to use to check the configuration.
3732 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003733 @Override
3734 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003735 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3736 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 final long identity = Binder.clearCallingIdentity();
3738 try {
3739 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003740 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003741 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003742 } catch (ImsException e) {
3743 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003744 } finally {
3745 Binder.restoreCallingIdentity(identity);
3746 }
3747 }
3748
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003749 @Override
3750 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3751 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3752 final long identity = Binder.clearCallingIdentity();
3753 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003754 if (!isImsAvailableOnDevice()) {
3755 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3756 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003757 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003758 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003759 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003760 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003761 } catch (ImsException e) {
3762 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003763 } finally {
3764 Binder.restoreCallingIdentity(identity);
3765 }
3766 }
3767
3768 @Override
3769 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3770 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3771 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003772 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3773 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3774 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003775 try {
3776 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003777 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003778 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003779 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003780 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3781 + "is inactive, ignoring unregister.");
3782 // If the subscription is no longer active, just return, since the callback will already
3783 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003784 } finally {
3785 Binder.restoreCallingIdentity(identity);
3786 }
3787 }
3788
allenwtsu99c623b2020-01-03 18:24:23 +08003789
3790 private void checkModifyPhoneStatePermission(int subId, String message) {
3791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3792 message);
3793 }
3794
3795 private boolean isImsProvisioningRequired(int subId, int capability,
3796 boolean isMmtelCapability) {
3797 Phone phone = getPhone(subId);
3798 if (phone == null) {
3799 loge("phone instance null for subid " + subId);
3800 return false;
3801 }
3802 if (isMmtelCapability) {
3803 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3804 return false;
3805 }
3806 } else {
3807 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3808 return false;
3809 }
3810 }
3811 return true;
3812 }
3813
3814 @Override
3815 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3816 boolean isProvisioned) {
3817 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3818
3819 final long identity = Binder.clearCallingIdentity();
3820 try {
3821 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3822 if (!isImsProvisioningRequired(subId, capability, false)) {
3823 return;
3824 }
3825
3826 // this capability requires provisioning, route to the correct API.
3827 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3828 switch (capability) {
3829 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3830 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3831 ims.setEabProvisioned(isProvisioned);
3832 break;
3833 default: {
3834 throw new IllegalArgumentException("Tried to set provisioning for "
3835 + "rcs capability '" + capability + "', which does not require "
3836 + "provisioning.");
3837 }
3838 }
3839 } finally {
3840 Binder.restoreCallingIdentity(identity);
3841 }
3842
3843 }
3844
3845
3846 @Override
3847 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3848 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3849 final long identity = Binder.clearCallingIdentity();
3850 try {
3851 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3852 if (!isImsProvisioningRequired(subId, capability, false)) {
3853 return true;
3854 }
3855
3856 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3857 switch (capability) {
3858 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3859 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3860 return ims.isEabProvisionedOnDevice();
3861
3862 default: {
3863 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3864 + "capability '" + capability + "', which does not require "
3865 + "provisioning.");
3866 }
3867 }
3868
3869 } finally {
3870 Binder.restoreCallingIdentity(identity);
3871 }
3872 }
3873
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003874 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003875 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3876 boolean isProvisioned) {
3877 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3878 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3879 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3880 }
allenwtsu99c623b2020-01-03 18:24:23 +08003881 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003882 final long identity = Binder.clearCallingIdentity();
3883 try {
3884 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003885 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003886 return;
3887 }
3888
3889 // this capability requires provisioning, route to the correct API.
3890 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3891 switch (capability) {
3892 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3893 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3894 ims.setVolteProvisioned(isProvisioned);
3895 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3896 ims.setWfcProvisioned(isProvisioned);
3897 }
3898 break;
3899 }
3900 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3901 // There is currently no difference in VT provisioning type.
3902 ims.setVtProvisioned(isProvisioned);
3903 break;
3904 }
3905 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3906 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3907 // change the capability of the feature instead if needed.
3908 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3909 == isProvisioned) {
3910 // No change in provisioning.
3911 return;
3912 }
3913 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3914 try {
3915 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003916 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003917 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3918 + ", Exception" + e.getMessage());
3919 }
3920 break;
3921 }
3922 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003923 throw new IllegalArgumentException("Tried to set provisioning for "
3924 + "MmTel capability '" + capability + "', which does not require "
3925 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003926 }
3927 }
3928
3929 } finally {
3930 Binder.restoreCallingIdentity(identity);
3931 }
3932 }
3933
3934 @Override
3935 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3936 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3937 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3938 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3939 }
3940 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3941 final long identity = Binder.clearCallingIdentity();
3942 try {
3943 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003944 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003945 return true;
3946 }
3947
3948 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3949 switch (capability) {
3950 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3951 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3952 return ims.isVolteProvisionedOnDevice();
3953 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3954 return ims.isWfcProvisionedOnDevice();
3955 }
3956 // This should never happen, since we are checking tech above to make sure it
3957 // is either LTE or IWLAN.
3958 throw new IllegalArgumentException("Invalid radio technology for voice "
3959 + "capability.");
3960 }
3961 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3962 // There is currently no difference in VT provisioning type.
3963 return ims.isVtProvisionedOnDevice();
3964 }
3965 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3966 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3967 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3968 }
3969 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003970 throw new IllegalArgumentException(
3971 "Tried to get provisioning for MmTel capability '" + capability
3972 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003973 }
3974 }
3975
3976 } finally {
3977 Binder.restoreCallingIdentity(identity);
3978 }
3979 }
3980
3981 @Override
3982 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3983 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3984 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3985 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3986 }
3987 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3988 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3989 return (provisionedBits & capability) > 0;
3990 }
3991
3992 @Override
3993 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3994 boolean isProvisioned) {
3995 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3996 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3997 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3998 }
3999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4000 "setProvisioningStatusForCapability");
4001 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4002 // If the current provisioning status for capability already matches isProvisioned,
4003 // do nothing.
4004 if (((provisionedBits & capability) > 0) == isProvisioned) {
4005 return;
4006 }
4007 if (isProvisioned) {
4008 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4009 } else {
4010 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4011 }
4012 }
4013
4014 /**
4015 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4016 * technology. The bitfield should mirror the bitfield defined by
4017 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4018 */
4019 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4020 String key = getMmTelProvisioningKey(subId, tech);
4021 // Default is no capabilities are provisioned.
4022 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4023 }
4024
4025 /**
4026 * Sets the MmTel capability provisioning bitfield (defined by
4027 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4028 * technology specified.
4029 *
4030 * Note: This is a synchronous command and should not be called on UI thread.
4031 */
4032 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4033 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4034 String key = getMmTelProvisioningKey(subId, tech);
4035 editor.putInt(key, newField);
4036 editor.commit();
4037 }
4038
4039 private static String getMmTelProvisioningKey(int subId, int tech) {
4040 // resulting key is provision_ims_mmtel_{subId}_{tech}
4041 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4042 }
4043
4044 /**
4045 * Query CarrierConfig to see if the specified capability requires provisioning for the
4046 * carrier associated with the subscription id.
4047 */
4048 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4049 int capability) {
4050 CarrierConfigManager configManager = new CarrierConfigManager(context);
4051 PersistableBundle c = configManager.getConfigForSubId(subId);
4052 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004053 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004054 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4055 false);
4056 boolean requireVoiceVtProvisioning = c.getBoolean(
4057 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4058
4059 // First check to make sure that the capability requires provisioning.
4060 switch (capability) {
4061 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4062 // intentional fallthrough
4063 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4064 if (requireVoiceVtProvisioning) {
4065 // Voice and Video requires provisioning
4066 return true;
4067 }
4068 break;
4069 }
4070 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4071 if (requireUtProvisioning) {
4072 // UT requires provisioning
4073 return true;
4074 }
4075 break;
4076 }
4077 }
4078 return false;
4079 }
4080
allenwtsu99c623b2020-01-03 18:24:23 +08004081 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4082 int capability) {
4083 CarrierConfigManager configManager = new CarrierConfigManager(context);
4084 PersistableBundle c = configManager.getConfigForSubId(subId);
4085
4086 boolean requireRcsProvisioning = c.getBoolean(
4087 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4088
4089 // First check to make sure that the capability requires provisioning.
4090 switch (capability) {
4091 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4092 // intentional fallthrough
4093 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4094 if (requireRcsProvisioning) {
4095 // OPTION or PRESENCE requires provisioning
4096 return true;
4097 }
4098 break;
4099 }
4100 }
4101 return false;
4102 }
4103
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004104 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004105 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004106 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4107 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4108 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004109 enforceReadPrivilegedPermission("getImsProvisioningInt");
4110 final long identity = Binder.clearCallingIdentity();
4111 try {
4112 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004113 int slotId = getSlotIndex(subId);
4114 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4115 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4116 + subId + "' for key:" + key);
4117 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4118 }
4119 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004120 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004121 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4122 + subId + "' for key:" + key);
4123 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004124 } finally {
4125 Binder.restoreCallingIdentity(identity);
4126 }
4127 }
4128
4129 @Override
4130 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004131 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4132 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4133 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004134 enforceReadPrivilegedPermission("getImsProvisioningString");
4135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004138 int slotId = getSlotIndex(subId);
4139 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4140 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4141 + subId + "' for key:" + key);
4142 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4143 }
4144 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004145 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004146 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4147 + subId + "' for key:" + key);
4148 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004149 } finally {
4150 Binder.restoreCallingIdentity(identity);
4151 }
4152 }
4153
4154 @Override
4155 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004156 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4157 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4158 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4160 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004161 final long identity = Binder.clearCallingIdentity();
4162 try {
4163 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004164 int slotId = getSlotIndex(subId);
4165 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4166 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4167 + subId + "' for key:" + key);
4168 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4169 }
4170 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004171 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004172 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4173 + "' for key:" + key);
4174 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004175 } finally {
4176 Binder.restoreCallingIdentity(identity);
4177 }
4178 }
4179
4180 @Override
4181 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004182 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4183 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4184 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4186 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004187 final long identity = Binder.clearCallingIdentity();
4188 try {
4189 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004190 int slotId = getSlotIndex(subId);
4191 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4192 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4193 + subId + "' for key:" + key);
4194 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4195 }
4196 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004197 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004198 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4199 + "' for key:" + key);
4200 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004201 } finally {
4202 Binder.restoreCallingIdentity(identity);
4203 }
4204 }
4205
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004206 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 int slotId = SubscriptionManager.getSlotIndex(subId);
4208 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004209 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4210 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004211 }
4212 return slotId;
4213 }
4214
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004215 private int getSlotIndex(int subId) {
4216 int slotId = SubscriptionManager.getSlotIndex(subId);
4217 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4218 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4219 }
4220 return slotId;
4221 }
4222
Wink Saville36469e72014-06-11 15:17:00 -07004223 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004224 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004225 */
4226 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004227 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4228 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004229 final int targetSdk = getTargetSdk(callingPackage);
4230 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004231 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004232 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004233 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004234 mApp, subId, callingPackage, callingFeatureId,
4235 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004236 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4237 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004239 final long identity = Binder.clearCallingIdentity();
4240 try {
4241 final Phone phone = getPhone(subId);
4242 if (phone != null) {
4243 return phone.getServiceState().getDataNetworkType();
4244 } else {
4245 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4246 }
4247 } finally {
4248 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004250 }
4251
4252 /**
4253 * Returns the data network type
4254 */
4255 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004256 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4257 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4258 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004259 }
4260
4261 /**
4262 * Returns the data network type for a subId
4263 */
4264 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004265 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4266 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004268 mApp, subId, callingPackage, callingFeatureId,
4269 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004270 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4271 }
4272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273 final long identity = Binder.clearCallingIdentity();
4274 try {
4275 final Phone phone = getPhone(subId);
4276 if (phone != null) {
4277 return phone.getServiceState().getDataNetworkType();
4278 } else {
4279 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4280 }
4281 } finally {
4282 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004284 }
4285
4286 /**
Wink Saville36469e72014-06-11 15:17:00 -07004287 * Returns the Voice network type for a subId
4288 */
4289 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004290 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4291 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004293 mApp, subId, callingPackage, callingFeatureId,
4294 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004295 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4296 }
4297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004298 final long identity = Binder.clearCallingIdentity();
4299 try {
4300 final Phone phone = getPhone(subId);
4301 if (phone != null) {
4302 return phone.getServiceState().getVoiceNetworkType();
4303 } else {
4304 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4305 }
4306 } finally {
4307 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004309 }
4310
4311 /**
4312 * @return true if a ICC card is present
4313 */
4314 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004315 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004316 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4317 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004318 }
4319
4320 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004321 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004322 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004323 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004324 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004325 final long identity = Binder.clearCallingIdentity();
4326 try {
4327 final Phone phone = PhoneFactory.getPhone(slotIndex);
4328 if (phone != null) {
4329 return phone.getIccCard().hasIccCard();
4330 } else {
4331 return false;
4332 }
4333 } finally {
4334 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004336 }
4337
4338 /**
4339 * Return if the current radio is LTE on CDMA. This
4340 * is a tri-state return value as for a period of time
4341 * the mode may be unknown.
4342 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004343 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004344 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004345 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004346 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004347 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004348 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4349 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4350 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004351 }
4352
Sanket Padawe356d7632015-06-22 14:03:32 -07004353 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004354 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4355 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004356 try {
4357 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4358 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004359 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4360 }
4361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004362 final long identity = Binder.clearCallingIdentity();
4363 try {
4364 final Phone phone = getPhone(subId);
4365 if (phone == null) {
4366 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4367 } else {
4368 return phone.getLteOnCdmaMode();
4369 }
4370 } finally {
4371 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004372 }
Wink Saville36469e72014-06-11 15:17:00 -07004373 }
4374
Wink Saville36469e72014-06-11 15:17:00 -07004375 /**
4376 * {@hide}
4377 * Returns Default subId, 0 in the case of single standby.
4378 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004379 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004380 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004381 }
4382
Shishir Agrawala9f32182016-04-12 12:00:16 -07004383 private int getSlotForDefaultSubscription() {
4384 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4385 }
4386
Wink Savilleb564aae2014-10-23 10:18:09 -07004387 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004388 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004389 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004390
Pengquan Menge92a50d2018-09-21 15:54:48 -07004391 private boolean isActiveSubscription(int subId) {
4392 return mSubscriptionController.isActiveSubId(subId);
4393 }
4394
Ihab Awadf2177b72013-11-25 13:33:23 -08004395 /**
4396 * @see android.telephony.TelephonyManager.WifiCallingChoices
4397 */
4398 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004399 final long identity = Binder.clearCallingIdentity();
4400 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004401 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4403 getWhenToMakeWifiCallsDefaultPreference());
4404 } finally {
4405 Binder.restoreCallingIdentity(identity);
4406 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004407 }
4408
4409 /**
4410 * @see android.telephony.TelephonyManager.WifiCallingChoices
4411 */
4412 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004413 final long identity = Binder.clearCallingIdentity();
4414 try {
4415 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004416 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004417 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4418 } finally {
4419 Binder.restoreCallingIdentity(identity);
4420 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004421 }
4422
Sailesh Nepald1e68152013-12-12 19:08:02 -08004423 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004424 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004425 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004426 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004427
Jordan Liu4c733742019-02-28 12:03:40 -08004428 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4429 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4430 if (phoneId == -1) {
4431 throw new IllegalArgumentException("Given slot index: " + slotIndex
4432 + " does not correspond to an active phone");
4433 }
4434 return PhoneFactory.getPhone(phoneId);
4435 }
4436
Shishir Agrawal566b7612013-10-28 14:41:00 -07004437 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004438 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4439 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4441 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004443 if (DBG) {
4444 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4445 }
4446 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4447 p2);
4448 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004449
Jordan Liu4c733742019-02-28 12:03:40 -08004450
4451 @Override
4452 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4453 int slotIndex, String callingPackage, String aid, int p2) {
4454 enforceModifyPermission();
4455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4456 if (DBG) {
4457 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4458 }
4459 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4460 callingPackage, aid, p2);
4461 }
4462
4463 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4464 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004465 final long identity = Binder.clearCallingIdentity();
4466 try {
4467 if (TextUtils.equals(ISDR_AID, aid)) {
4468 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004469 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4470 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004471 if (bestComponent == null
4472 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4473 loge("The calling package is not allowed to access ISD-R.");
4474 throw new SecurityException(
4475 "The calling package is not allowed to access ISD-R.");
4476 }
Derek Tan740e1672017-06-27 14:56:27 -07004477 }
Derek Tan740e1672017-06-27 14:56:27 -07004478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004479 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004480 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4481 null /* workSource */);
4482 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004483 return response;
4484 } finally {
4485 Binder.restoreCallingIdentity(identity);
4486 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004487 }
4488
4489 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004490 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4492 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004493 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4494 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4495 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004496
Jordan Liu4c733742019-02-28 12:03:40 -08004497 @Override
4498 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4499 enforceModifyPermission();
4500 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4501 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4502 channel);
4503 }
4504
4505 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004506 final long identity = Binder.clearCallingIdentity();
4507 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508 if (channel < 0) {
4509 return false;
4510 }
Jordan Liu4c733742019-02-28 12:03:40 -08004511 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4512 null /* workSource */);
4513 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514 return success;
4515 } finally {
4516 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004517 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004518 }
4519
4520 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004521 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004522 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4524 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004525 if (DBG) {
4526 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4527 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4528 + p3 + " data=" + data);
4529 }
4530 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4531 command, p1, p2, p3, data);
4532 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004533
Jordan Liu4c733742019-02-28 12:03:40 -08004534 @Override
4535 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4536 int command, int p1, int p2, int p3, String data) {
4537 enforceModifyPermission();
4538 if (DBG) {
4539 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4540 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4541 + p3 + " data=" + data);
4542 }
4543 return iccTransmitApduLogicalChannelWithPermission(
4544 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4545 data);
4546 }
4547
4548 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4549 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004550 final long identity = Binder.clearCallingIdentity();
4551 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004552 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 return "";
4554 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004557 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4558 null /* workSource */);
4559 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561 // Append the returned status code to the end of the response payload.
4562 String s = Integer.toHexString(
4563 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4564 if (response.payload != null) {
4565 s = IccUtils.bytesToHexString(response.payload) + s;
4566 }
4567 return s;
4568 } finally {
4569 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004570 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004571 }
Jake Hambye994d462014-02-03 13:10:13 -08004572
Evan Charltonc66da362014-05-16 14:06:40 -07004573 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004574 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4575 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4577 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004578 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004579 if (DBG) {
4580 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4581 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4582 }
4583 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4584 cla, command, p1, p2, p3, data);
4585 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004586
Jordan Liu4c733742019-02-28 12:03:40 -08004587 @Override
4588 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4589 int command, int p1, int p2, int p3, String data) {
4590 enforceModifyPermission();
4591 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4592 if (DBG) {
4593 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4594 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4595 + " data=" + data);
4596 }
4597
4598 return iccTransmitApduBasicChannelWithPermission(
4599 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4600 p2, p3, data);
4601 }
4602
4603 // open APDU basic channel assuming the caller has sufficient permissions
4604 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4605 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004606 final long identity = Binder.clearCallingIdentity();
4607 try {
4608 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4609 && TextUtils.equals(ISDR_AID, data)) {
4610 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004611 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4612 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004613 if (bestComponent == null
4614 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4615 loge("The calling package is not allowed to select ISD-R.");
4616 throw new SecurityException(
4617 "The calling package is not allowed to select ISD-R.");
4618 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004619 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004621 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004622 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4623 null /* workSource */);
4624 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004625
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004626 // Append the returned status code to the end of the response payload.
4627 String s = Integer.toHexString(
4628 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4629 if (response.payload != null) {
4630 s = IccUtils.bytesToHexString(response.payload) + s;
4631 }
4632 return s;
4633 } finally {
4634 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004635 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004636 }
4637
4638 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004639 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004640 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4642 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004643
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004644 final long identity = Binder.clearCallingIdentity();
4645 try {
4646 if (DBG) {
4647 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4648 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4649 }
4650
4651 IccIoResult response =
4652 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4653 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4654 subId);
4655
4656 if (DBG) {
4657 log("Exchange SIM_IO [R]" + response);
4658 }
4659
4660 byte[] result = null;
4661 int length = 2;
4662 if (response.payload != null) {
4663 length = 2 + response.payload.length;
4664 result = new byte[length];
4665 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4666 } else {
4667 result = new byte[length];
4668 }
4669
4670 result[length - 1] = (byte) response.sw2;
4671 result[length - 2] = (byte) response.sw1;
4672 return result;
4673 } finally {
4674 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004675 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004676 }
4677
Nathan Haroldb3014052017-01-25 15:57:32 -08004678 /**
4679 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4680 * on a particular subscription
4681 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004682 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4683 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004685 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004686 return null;
4687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004688
4689 final long identity = Binder.clearCallingIdentity();
4690 try {
4691 if (appType != TelephonyManager.APPTYPE_USIM
4692 && appType != TelephonyManager.APPTYPE_SIM) {
4693 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4694 return null;
4695 }
4696 Object response = sendRequest(
4697 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4698 if (response instanceof String[]) {
4699 return (String[]) response;
4700 }
yincheng zhaod698b842019-09-06 17:06:54 -07004701 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004702 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004703 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704 } finally {
4705 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004706 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004707 }
4708
yincheng zhaod698b842019-09-06 17:06:54 -07004709 /**
4710 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4711 * subscription.
4712 *
4713 * @param subId the id of the subscription.
4714 * @param appType the uicc app type, must be USIM or SIM.
4715 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4716 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004717 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004718 * @return number of fplmns that is successfully written to the SIM.
4719 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004720 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4721 String callingFeatureId) {
4722 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4723 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004724 if (DBG) logv("no permissions for setForbiddenplmns");
4725 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4726 }
4727 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4728 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4729 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4730 }
4731 if (fplmns == null) {
4732 throw new IllegalArgumentException("Fplmn List provided is null");
4733 }
4734 for (String fplmn : fplmns) {
4735 if (!CellIdentity.isValidPlmn(fplmn)) {
4736 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4737 }
4738 }
4739 final long identity = Binder.clearCallingIdentity();
4740 try {
4741 Object response = sendRequest(
4742 CMD_SET_FORBIDDEN_PLMNS,
4743 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4744 subId);
4745 return (int) response;
4746 } finally {
4747 Binder.restoreCallingIdentity(identity);
4748 }
4749 }
4750
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004751 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004752 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004753 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4754 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004756 final long identity = Binder.clearCallingIdentity();
4757 try {
4758 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4759 if (response.payload == null) {
4760 return "";
4761 }
Evan Charltonc66da362014-05-16 14:06:40 -07004762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763 // Append the returned status code to the end of the response payload.
4764 String s = Integer.toHexString(
4765 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4766 s = IccUtils.bytesToHexString(response.payload) + s;
4767 return s;
4768 } finally {
4769 Binder.restoreCallingIdentity(identity);
4770 }
Evan Charltonc66da362014-05-16 14:06:40 -07004771 }
4772
Jake Hambye994d462014-02-03 13:10:13 -08004773 /**
4774 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4775 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4776 *
4777 * @param itemID the ID of the item to read
4778 * @return the NV item as a String, or null on error.
4779 */
4780 @Override
4781 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004782 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4784 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004785
4786 final long identity = Binder.clearCallingIdentity();
4787 try {
4788 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004789 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004790 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4791 return value;
4792 } finally {
4793 Binder.restoreCallingIdentity(identity);
4794 }
Jake Hambye994d462014-02-03 13:10:13 -08004795 }
4796
4797 /**
4798 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4799 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4800 *
4801 * @param itemID the ID of the item to read
4802 * @param itemValue the value to write, as a String
4803 * @return true on success; false on any failure
4804 */
4805 @Override
4806 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004807 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4809 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004810
4811 final long identity = Binder.clearCallingIdentity();
4812 try {
4813 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4814 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004815 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4817 return success;
4818 } finally {
4819 Binder.restoreCallingIdentity(identity);
4820 }
Jake Hambye994d462014-02-03 13:10:13 -08004821 }
4822
4823 /**
4824 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4825 * Used for device configuration by some CDMA operators.
4826 *
4827 * @param preferredRoamingList byte array containing the new PRL
4828 * @return true on success; false on any failure
4829 */
4830 @Override
4831 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4833 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004834
4835 final long identity = Binder.clearCallingIdentity();
4836 try {
4837 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4838 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4839 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4840 return success;
4841 } finally {
4842 Binder.restoreCallingIdentity(identity);
4843 }
Jake Hambye994d462014-02-03 13:10:13 -08004844 }
4845
4846 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004847 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004848 * Used for device configuration by some CDMA operators.
4849 *
chen xu6dac5ab2018-10-26 17:39:23 -07004850 * @param slotIndex - device slot.
4851 *
Jake Hambye994d462014-02-03 13:10:13 -08004852 * @return true on success; false on any failure
4853 */
4854 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004855 public boolean resetModemConfig(int slotIndex) {
4856 Phone phone = PhoneFactory.getPhone(slotIndex);
4857 if (phone != null) {
4858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4859 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860
chen xu6dac5ab2018-10-26 17:39:23 -07004861 final long identity = Binder.clearCallingIdentity();
4862 try {
4863 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4864 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4865 return success;
4866 } finally {
4867 Binder.restoreCallingIdentity(identity);
4868 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869 }
chen xu6dac5ab2018-10-26 17:39:23 -07004870 return false;
4871 }
4872
4873 /**
4874 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4875 *
4876 * @param slotIndex - device slot.
4877 *
4878 * @return true on success; false on any failure
4879 */
4880 @Override
4881 public boolean rebootModem(int slotIndex) {
4882 Phone phone = PhoneFactory.getPhone(slotIndex);
4883 if (phone != null) {
4884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4885 mApp, phone.getSubId(), "rebootModem");
4886
4887 final long identity = Binder.clearCallingIdentity();
4888 try {
4889 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4890 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4891 return success;
4892 } finally {
4893 Binder.restoreCallingIdentity(identity);
4894 }
4895 }
4896 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004897 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004898
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004899 public String[] getPcscfAddress(String apnType, String callingPackage,
4900 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004901 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004902 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4903 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004904 return new String[0];
4905 }
4906
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907 final long identity = Binder.clearCallingIdentity();
4908 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004909 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 } finally {
4911 Binder.restoreCallingIdentity(identity);
4912 }
Wink Saville36469e72014-06-11 15:17:00 -07004913 }
4914
Brad Ebinger51f743a2017-01-23 13:50:20 -08004915 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004916 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4917 * {@link #disableIms(int)}.
4918 * @param slotIndex device slot.
4919 */
4920 public void resetIms(int slotIndex) {
4921 enforceModifyPermission();
4922
4923 final long identity = Binder.clearCallingIdentity();
4924 try {
4925 if (mImsResolver == null) {
4926 // may happen if the does not support IMS.
4927 return;
4928 }
4929 mImsResolver.disableIms(slotIndex);
4930 mImsResolver.enableIms(slotIndex);
4931 } finally {
4932 Binder.restoreCallingIdentity(identity);
4933 }
4934 }
4935
4936 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004937 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4938 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004939 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004940 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004941 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004942
4943 final long identity = Binder.clearCallingIdentity();
4944 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004945 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004946 // may happen if the device does not support IMS.
4947 return;
4948 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004949 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950 } finally {
4951 Binder.restoreCallingIdentity(identity);
4952 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004953 }
4954
4955 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004956 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4957 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004958 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004959 public void disableIms(int slotId) {
4960 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004961
4962 final long identity = Binder.clearCallingIdentity();
4963 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004964 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004965 // may happen if the device does not support IMS.
4966 return;
4967 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004968 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969 } finally {
4970 Binder.restoreCallingIdentity(identity);
4971 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004972 }
4973
4974 /**
4975 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4976 * feature or {@link null} if the service is not available. If the feature is available, the
4977 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4978 */
4979 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004980 IImsServiceFeatureCallback callback) {
4981 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982
4983 final long identity = Binder.clearCallingIdentity();
4984 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004985 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004986 // may happen if the device does not support IMS.
4987 return null;
4988 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004989 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004990 } finally {
4991 Binder.restoreCallingIdentity(identity);
4992 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004993 }
4994
4995 /**
4996 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4997 * feature during emergency calling or {@link null} if the service is not available. If the
4998 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4999 * listener for feature updates.
5000 */
5001 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5002 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003
5004 final long identity = Binder.clearCallingIdentity();
5005 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005006 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005007 // may happen if the device does not support IMS.
5008 return null;
5009 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005010 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011 } finally {
5012 Binder.restoreCallingIdentity(identity);
5013 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005014 }
5015
Brad Ebinger5f64b052017-12-14 14:26:15 -08005016 /**
5017 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005018 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005019 */
5020 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5021 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022
5023 final long identity = Binder.clearCallingIdentity();
5024 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005025 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005026 // may happen if the device does not support IMS.
5027 return null;
5028 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005029 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005030 } finally {
5031 Binder.restoreCallingIdentity(identity);
5032 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005033 }
5034
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005035 /**
5036 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005037 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005038 */
5039 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5040 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041
5042 final long identity = Binder.clearCallingIdentity();
5043 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005044 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005045 // may happen if the device does not support IMS.
5046 return null;
5047 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005048 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049 } finally {
5050 Binder.restoreCallingIdentity(identity);
5051 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005052 }
5053
Brad Ebinger884c07b2018-02-15 16:17:40 -08005054 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005055 * Sets the ImsService Package Name that Telephony will bind to.
5056 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005057 * @param slotIndex the slot ID that the ImsService should bind for.
5058 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005059 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005060 * @param featureTypes An integer array of feature types associated with a packageName.
5061 * @param packageName The name of the package that the current configuration will be replaced
5062 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005063 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005064 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005065 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5066 int[] featureTypes, String packageName) {
5067 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5068 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5070 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005071 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073 final long identity = Binder.clearCallingIdentity();
5074 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005075 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005076 // may happen if the device does not support IMS.
5077 return false;
5078 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005079 Map<Integer, String> featureConfig = new HashMap<>();
5080 for (int featureType : featureTypes) {
5081 featureConfig.put(featureType, packageName);
5082 }
5083 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5084 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 } finally {
5086 Binder.restoreCallingIdentity(identity);
5087 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005088 }
5089
5090 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005091 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005092 *
5093 * @param slotId The slot that the ImsService is associated with.
5094 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5095 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005096 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005097 * @return the package name of the ImsService configuration.
5098 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005099 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5100 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005101 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005102 TelephonyPermissions
5103 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5104 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5105 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005107 final long identity = Binder.clearCallingIdentity();
5108 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005109 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005110 // may happen if the device does not support IMS.
5111 return "";
5112 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005113 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005114 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5115 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 } finally {
5117 Binder.restoreCallingIdentity(identity);
5118 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005119 }
5120
Brad Ebinger77b832e2019-10-17 17:03:22 -07005121 /**
5122 * Get the MmTelFeature state associated with the requested subscription id.
5123 * @param subId The subscription that the MmTelFeature is associated with.
5124 * @param callback A callback with an integer containing the
5125 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5126 */
5127 @Override
5128 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5129 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5130 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5131 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5132 "IMS not available on device.");
5133 }
5134 final long token = Binder.clearCallingIdentity();
5135 try {
5136 int slotId = getSlotIndex(subId);
5137 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5138 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5139 + subId + "'");
5140 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5141 }
5142 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5143 try {
5144 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5145 } catch (RemoteException e) {
5146 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5147 + "Ignore");
5148 }
5149 });
5150 } finally {
5151 Binder.restoreCallingIdentity(token);
5152 }
5153 }
5154
Wink Saville36469e72014-06-11 15:17:00 -07005155 public void setImsRegistrationState(boolean registered) {
5156 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005157
5158 final long identity = Binder.clearCallingIdentity();
5159 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005160 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161 } finally {
5162 Binder.restoreCallingIdentity(identity);
5163 }
Wink Saville36469e72014-06-11 15:17:00 -07005164 }
5165
5166 /**
Stuart Scott54788802015-03-30 13:18:01 -07005167 * Set the network selection mode to automatic.
5168 *
5169 */
5170 @Override
5171 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5173 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174
5175 final long identity = Binder.clearCallingIdentity();
5176 try {
shilufc958392020-01-20 11:36:01 -08005177 if (!isActiveSubscription(subId)) {
5178 return;
5179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5181 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5182 } finally {
5183 Binder.restoreCallingIdentity(identity);
5184 }
Stuart Scott54788802015-03-30 13:18:01 -07005185 }
5186
Pengquan Mengea84e042018-09-20 14:57:26 -07005187 /**
5188 * Ask the radio to connect to the input network and change selection mode to manual.
5189 *
5190 * @param subId the id of the subscription.
5191 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5192 * the operator to attach to.
5193 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5194 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5195 * normal network selection next time.
5196 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005197 */
5198 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005199 public boolean setNetworkSelectionModeManual(
5200 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005201 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5202 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005203
5204 if (!isActiveSubscription(subId)) {
5205 return false;
5206 }
5207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 final long identity = Binder.clearCallingIdentity();
5209 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005210 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005212 if (DBG) {
5213 log("setNetworkSelectionModeManual: subId: " + subId
5214 + " operator: " + operatorInfo);
5215 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5217 } finally {
5218 Binder.restoreCallingIdentity(identity);
5219 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005220 }
5221
5222 /**
5223 * Scans for available networks.
5224 */
5225 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005226 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5227 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5229 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005230 LocationAccessPolicy.LocationPermissionResult locationResult =
5231 LocationAccessPolicy.checkLocationPermission(mApp,
5232 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5233 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005234 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005235 .setCallingPid(Binder.getCallingPid())
5236 .setCallingUid(Binder.getCallingUid())
5237 .setMethod("getCellNetworkScanResults")
5238 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5239 .build());
5240 switch (locationResult) {
5241 case DENIED_HARD:
5242 throw new SecurityException("Not allowed to access scan results -- location");
5243 case DENIED_SOFT:
5244 return null;
5245 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246
Pengquan Menga1bb6272018-09-06 09:59:22 -07005247 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248 try {
5249 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005250 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 } finally {
5253 Binder.restoreCallingIdentity(identity);
5254 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005255 }
5256
5257 /**
sqian80370722020-01-29 15:02:51 -08005258 * Get the call forwarding info, given the call forwarding reason.
5259 */
5260 @Override
5261 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5262 enforceReadPrivilegedPermission("getCallForwarding");
5263 long identity = Binder.clearCallingIdentity();
5264 try {
5265 if (DBG) {
5266 log("getCallForwarding: subId " + subId
5267 + " callForwardingReason" + callForwardingReason);
5268 }
5269 return (CallForwardingInfo) sendRequest(
5270 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5271 } finally {
5272 Binder.restoreCallingIdentity(identity);
5273 }
5274 }
5275
5276 /**
5277 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5278 * reason, the number to forward, and the timeout before the forwarding is attempted.
5279 */
5280 @Override
5281 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5282 enforceModifyPermission();
5283 long identity = Binder.clearCallingIdentity();
5284 try {
5285 if (DBG) {
5286 log("setCallForwarding: subId " + subId
5287 + " callForwardingInfo" + callForwardingInfo);
5288 }
5289 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5290 } finally {
5291 Binder.restoreCallingIdentity(identity);
5292 }
5293 }
5294
5295 /**
5296 * Get the call forwarding info, given the call forwarding reason.
5297 */
5298 @Override
5299 public int getCallWaitingStatus(int subId) {
5300 enforceReadPrivilegedPermission("getCallForwarding");
5301 long identity = Binder.clearCallingIdentity();
5302 try {
5303 if (DBG) log("getCallWaitingStatus: subId " + subId);
5304 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5305 } finally {
5306 Binder.restoreCallingIdentity(identity);
5307 }
5308 }
5309
5310 /**
5311 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5312 * reason, the number to forward, and the timeout before the forwarding is attempted.
5313 */
5314 @Override
5315 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5316 enforceModifyPermission();
5317 long identity = Binder.clearCallingIdentity();
5318 try {
5319 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5320 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5321 } finally {
5322 Binder.restoreCallingIdentity(identity);
5323 }
5324 }
5325
5326 /**
yinxub1bed742017-04-17 11:45:04 -07005327 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005328 *
yinxub1bed742017-04-17 11:45:04 -07005329 * @param subId id of the subscription
5330 * @param request contains the radio access networks with bands/channels to scan
5331 * @param messenger callback messenger for scan results or errors
5332 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005333 * @return the id of the requested scan which can be used to stop the scan.
5334 */
5335 @Override
5336 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005337 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5339 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005340 LocationAccessPolicy.LocationPermissionResult locationResult =
5341 LocationAccessPolicy.checkLocationPermission(mApp,
5342 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5343 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005344 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005345 .setCallingPid(Binder.getCallingPid())
5346 .setCallingUid(Binder.getCallingUid())
5347 .setMethod("requestNetworkScan")
5348 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5349 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005350 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005351 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005352 if (e != null) {
5353 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5354 throw e;
5355 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005356 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005357 return TelephonyScanManager.INVALID_SCAN_ID;
5358 }
5359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 }
Hall Liu912dfd32019-04-25 14:02:26 -07005361 int callingUid = Binder.getCallingUid();
5362 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005363 final long identity = Binder.clearCallingIdentity();
5364 try {
5365 return mNetworkScanRequestTracker.startNetworkScan(
5366 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005367 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005368 } finally {
5369 Binder.restoreCallingIdentity(identity);
5370 }
yinxu504e1392017-04-12 16:03:22 -07005371 }
5372
Hall Liub2ac8ef2019-02-28 15:56:23 -08005373 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005374 NetworkScanRequest request, int subId) {
5375 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5376 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5377 boolean hasNetworkScanPermission =
5378 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5379 == PERMISSION_GRANTED;
5380
5381 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5382 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5383 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005384 }
5385
5386 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5387 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005388 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5389 return new SecurityException("Specific channels must not be"
5390 + " scanned without location access.");
5391 }
5392 }
5393 }
5394
Hall Liub2ac8ef2019-02-28 15:56:23 -08005395 return null;
5396 }
5397
yinxu504e1392017-04-12 16:03:22 -07005398 /**
5399 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005400 *
5401 * @param subId id of the subscription
5402 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005403 */
5404 @Override
5405 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5407 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408
Hall Liu912dfd32019-04-25 14:02:26 -07005409 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 final long identity = Binder.clearCallingIdentity();
5411 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005412 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413 } finally {
5414 Binder.restoreCallingIdentity(identity);
5415 }
yinxu504e1392017-04-12 16:03:22 -07005416 }
5417
5418 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005419 * Get the calculated preferred network type.
5420 * Used for debugging incorrect network type.
5421 *
5422 * @return the preferred network type, defined in RILConstants.java.
5423 */
5424 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005425 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005426 final Phone defaultPhone = getDefaultPhone();
5427 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005428 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005429 return RILConstants.PREFERRED_NETWORK_MODE;
5430 }
5431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432 final long identity = Binder.clearCallingIdentity();
5433 try {
5434 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005435 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005436 } finally {
5437 Binder.restoreCallingIdentity(identity);
5438 }
Junda Liu84d15a22014-07-02 11:21:04 -07005439 }
5440
5441 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005442 * Get the preferred network type.
5443 * Used for device configuration by some CDMA operators.
5444 *
5445 * @return the preferred network type, defined in RILConstants.java.
5446 */
5447 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005448 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005449 TelephonyPermissions
5450 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5451 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452
5453 final long identity = Binder.clearCallingIdentity();
5454 try {
5455 if (DBG) log("getPreferredNetworkType");
5456 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5457 int networkType = (result != null ? result[0] : -1);
5458 if (DBG) log("getPreferredNetworkType: " + networkType);
5459 return networkType;
5460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005463 }
5464
5465 /**
5466 * Set the preferred network type.
5467 * Used for device configuration by some CDMA operators.
5468 *
5469 * @param networkType the preferred network type, defined in RILConstants.java.
5470 * @return true on success; false on any failure.
5471 */
5472 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005473 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5475 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476
5477 final long identity = Binder.clearCallingIdentity();
5478 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005479 Settings.Global.putInt(mApp.getContentResolver(),
5480 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5481 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005482 } finally {
5483 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005484 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005485 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005486
5487 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005488 * Get the allowed network types that store in the telephony provider.
5489 *
5490 * @param subId the id of the subscription.
5491 * @return allowedNetworkTypes the allowed network types.
5492 */
5493 @Override
5494 public long getAllowedNetworkTypes(int subId) {
5495 TelephonyPermissions
5496 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5497 mApp, subId, "getAllowedNetworkTypes");
5498
5499 final long identity = Binder.clearCallingIdentity();
5500 try {
5501 return SubscriptionManager.getLongSubscriptionProperty(
5502 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5503 } finally {
5504 Binder.restoreCallingIdentity(identity);
5505 }
5506 }
5507
5508 /**
5509 * Set the allowed network types.
5510 *
5511 * @param subId the id of the subscription.
5512 * @param allowedNetworkTypes the allowed network types.
5513 * @return true on success; false on any failure.
5514 */
5515 @Override
5516 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5517 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5518 mApp, subId, "setAllowedNetworkTypes");
5519 final long identity = Binder.clearCallingIdentity();
5520 try {
5521 SubscriptionManager.setSubscriptionProperty(subId,
5522 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5523 String.valueOf(allowedNetworkTypes));
5524 return setPreferredNetworkTypesInternal(subId);
5525 } finally {
5526 Binder.restoreCallingIdentity(identity);
5527 }
5528 }
5529
5530 private boolean setPreferredNetworkTypesInternal(int subId) {
5531 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5532 Settings.Global.getInt(mApp.getContentResolver(),
5533 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5534 RILConstants.PREFERRED_NETWORK_MODE));
5535 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5536 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5537 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5538 (int) (networkTypeBitMask & allowedNetworkTypes));
5539
5540 if (DBG) {
5541 log("setPreferredNetworkTypesInternal: subId " + subId
5542 + " networkTypes " + networkTypeBitMask
5543 + " allowedNetworkTypes " + allowedNetworkTypes
5544 + " networkMode " + networkMode);
5545 }
5546
5547 Boolean success = (Boolean) sendRequest(
5548 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5549 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5550 return success;
5551 }
5552
5553 /**
Miaoa84611c2019-03-15 09:21:10 +08005554 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005555 *
Miaoa84611c2019-03-15 09:21:10 +08005556 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005557 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005558 * @hide
5559 */
5560 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005561 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005562 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005563 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005564 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 try {
Miaoa84611c2019-03-15 09:21:10 +08005566 if (phone != null) {
5567 return phone.hasMatchedTetherApnSetting();
5568 } else {
5569 return false;
5570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005571 } finally {
5572 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005573 }
Junda Liu475951f2014-11-07 16:45:03 -08005574 }
5575
5576 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005577 * Set mobile data enabled
5578 * Used by the user through settings etc to turn on/off mobile data
5579 *
5580 * @param enable {@code true} turn turn data on, else {@code false}
5581 */
5582 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005583 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5585 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586
5587 final long identity = Binder.clearCallingIdentity();
5588 try {
5589 int phoneId = mSubscriptionController.getPhoneId(subId);
5590 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5591 Phone phone = PhoneFactory.getPhone(phoneId);
5592 if (phone != null) {
5593 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005594 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005596 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005597 }
5598 } finally {
5599 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005600 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005601 }
5602
5603 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005604 * Enable or disable always reporting signal strength changes from radio.
5605 *
5606 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5607 */
5608 @Override
5609 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5610 enforceModifyPermission();
5611 enforceSystemCaller();
5612
5613 final long identity = Binder.clearCallingIdentity();
5614 final Phone phone = getPhone(subId);
5615 try {
5616 if (phone != null) {
5617 if (DBG) {
5618 log("setAlwaysReportSignalStrength: subId=" + subId
5619 + " isEnable=" + isEnable);
5620 }
5621 phone.setAlwaysReportSignalStrength(isEnable);
5622 } else {
5623 loge("setAlwaysReportSignalStrength: no phone found for subId="
5624 + subId);
5625 }
5626 } finally {
5627 Binder.restoreCallingIdentity(identity);
5628 }
5629 }
5630
5631 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005632 * Get the user enabled state of Mobile Data.
5633 *
5634 * TODO: remove and use isUserDataEnabled.
5635 * This can't be removed now because some vendor codes
5636 * calls through ITelephony directly while they should
5637 * use TelephonyManager.
5638 *
5639 * @return true on enabled
5640 */
5641 @Override
5642 public boolean getDataEnabled(int subId) {
5643 return isUserDataEnabled(subId);
5644 }
5645
5646 /**
5647 * Get whether mobile data is enabled per user setting.
5648 *
5649 * There are other factors deciding whether mobile data is actually enabled, but they are
5650 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005651 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005652 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005653 *
5654 * @return {@code true} if data is enabled else {@code false}
5655 */
5656 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005657 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005658 try {
5659 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5660 null);
5661 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5663 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665
5666 final long identity = Binder.clearCallingIdentity();
5667 try {
5668 int phoneId = mSubscriptionController.getPhoneId(subId);
5669 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5670 Phone phone = PhoneFactory.getPhone(phoneId);
5671 if (phone != null) {
5672 boolean retVal = phone.isUserDataEnabled();
5673 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5674 return retVal;
5675 } else {
5676 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5677 return false;
5678 }
5679 } finally {
5680 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005681 }
5682 }
5683
5684 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005685 * Checks if the device is capable of mobile data by considering whether whether the
5686 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5687 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005688 *
Shuo Qian985d1232020-01-08 14:30:06 -08005689 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005690 */
5691 @Override
5692 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005693 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694
5695 final long identity = Binder.clearCallingIdentity();
5696 try {
5697 int phoneId = mSubscriptionController.getPhoneId(subId);
5698 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5699 Phone phone = PhoneFactory.getPhone(phoneId);
5700 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005701 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5703 return retVal;
5704 } else {
5705 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5706 return false;
5707 }
5708 } finally {
5709 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005710 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005711 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005712
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005713 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5714 Phone phone) {
5715 //load access rules from carrier configs, and check those as well: b/139133814
5716 SubscriptionController subController = SubscriptionController.getInstance();
5717 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5718 || subController == null) return privilegeFromSim;
5719
5720 int uid = Binder.getCallingUid();
5721 PackageManager pkgMgr = phone.getContext().getPackageManager();
5722 String[] packages = pkgMgr.getPackagesForUid(uid);
5723
5724 final long identity = Binder.clearCallingIdentity();
5725 try {
5726 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5727 SubscriptionManager subManager = (SubscriptionManager)
5728 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5729 for (String pkg : packages) {
5730 if (subManager.canManageSubscription(subInfo, pkg)) {
5731 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5732 }
5733 }
5734 return privilegeFromSim;
5735 } finally {
5736 Binder.restoreCallingIdentity(identity);
5737 }
5738 }
5739
5740 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5741 String pkgName) {
5742 //load access rules from carrier configs, and check those as well: b/139133814
5743 SubscriptionController subController = SubscriptionController.getInstance();
5744 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5745 || subController == null) return privilegeFromSim;
5746
5747 final long identity = Binder.clearCallingIdentity();
5748 try {
5749 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5750 SubscriptionManager subManager = (SubscriptionManager)
5751 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5752 return subManager.canManageSubscription(subInfo, pkgName)
5753 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5754 } finally {
5755 Binder.restoreCallingIdentity(identity);
5756 }
5757 }
5758
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005759 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005760 public int getCarrierPrivilegeStatus(int subId) {
5761 final Phone phone = getPhone(subId);
5762 if (phone == null) {
5763 loge("getCarrierPrivilegeStatus: Invalid subId");
5764 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5765 }
5766 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005767 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005768 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005769 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5770 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005771
5772 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5773 card.getCarrierPrivilegeStatusForCurrentTransaction(
5774 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005775 }
Junda Liu29340342014-07-10 15:23:27 -07005776
5777 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005778 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005779 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005780 final Phone phone = getPhone(subId);
5781 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005782 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005783 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5784 }
5785 UiccProfile profile =
5786 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5787 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005788 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005789 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5790 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005791 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005792 profile.getCarrierPrivilegeStatusForUid(
5793 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005794 }
5795
5796 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005797 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5798 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005799 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005800 }
5801
5802 int phoneId = SubscriptionManager.getPhoneId(subId);
5803 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005804 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005805 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005806 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5807 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005808 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5809 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5810 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005811 }
5812
5813 @Override
5814 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005815 if (TextUtils.isEmpty(pkgName))
5816 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005817 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5818 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5819 UiccCard card = UiccController.getInstance().getUiccCard(i);
5820 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005821 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005822 continue;
5823 }
5824
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005825 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5826 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5827 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005828 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5829 break;
5830 }
5831 }
5832
5833 return result;
Junda Liu29340342014-07-10 15:23:27 -07005834 }
Derek Tan89e89d42014-07-08 17:00:10 -07005835
5836 @Override
Junda Liue64de782015-04-16 17:19:16 -07005837 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5838 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5839 loge("phoneId " + phoneId + " is not valid.");
5840 return null;
5841 }
5842 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005843 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005844 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005845 return null ;
5846 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005847 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005848 }
5849
Amith Yamasani6e118872016-02-19 12:53:51 -08005850 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005851 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005852 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005853 List<String> privilegedPackages = new ArrayList<>();
5854 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005855 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5856 // has UICC in that slot.
5857 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005858 if (card.hasCarrierPrivilegeRules()) {
5859 if (packages == null) {
5860 // Only check packages in user 0 for now
5861 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005862 PackageManager.MATCH_DISABLED_COMPONENTS
5863 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005864 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005865 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005866 }
5867 for (int p = packages.size() - 1; p >= 0; p--) {
5868 PackageInfo pkgInfo = packages.get(p);
5869 if (pkgInfo != null && pkgInfo.packageName != null
5870 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005871 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005872 privilegedPackages.add(pkgInfo.packageName);
5873 }
5874 }
5875 }
5876 }
5877 return privilegedPackages;
5878 }
5879
chen xuf7e9fe82019-05-09 19:31:02 -07005880 @Override
5881 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005882 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5883
5884 final long identity = Binder.clearCallingIdentity();
5885
chen xuf7e9fe82019-05-09 19:31:02 -07005886 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005887 try {
5888 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5889 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5890 }
5891 } finally {
5892 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005893 }
5894 return privilegedPackages;
5895 }
5896
Wink Savilleb564aae2014-10-23 10:18:09 -07005897 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005898 final Phone phone = getPhone(subId);
5899 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005900 if (card == null) {
5901 loge("getIccId: No UICC");
5902 return null;
5903 }
5904 String iccId = card.getIccId();
5905 if (TextUtils.isEmpty(iccId)) {
5906 loge("getIccId: ICC ID is null or empty.");
5907 return null;
5908 }
5909 return iccId;
5910 }
5911
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005912 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005913 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5914 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005915 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005916 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005917
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 final long identity = Binder.clearCallingIdentity();
5919 try {
5920 final String iccId = getIccId(subId);
5921 final Phone phone = getPhone(subId);
5922 if (phone == null) {
5923 return false;
5924 }
5925 final String subscriberId = phone.getSubscriberId();
5926
5927 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005928 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 + subscriberId + " to " + number);
5930 }
5931
5932 if (TextUtils.isEmpty(iccId)) {
5933 return false;
5934 }
5935
5936 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5937
5938 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5939 if (alphaTag == null) {
5940 editor.remove(alphaTagPrefKey);
5941 } else {
5942 editor.putString(alphaTagPrefKey, alphaTag);
5943 }
5944
5945 // Record both the line number and IMSI for this ICCID, since we need to
5946 // track all merged IMSIs based on line number
5947 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5948 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5949 if (number == null) {
5950 editor.remove(numberPrefKey);
5951 editor.remove(subscriberPrefKey);
5952 } else {
5953 editor.putString(numberPrefKey, number);
5954 editor.putString(subscriberPrefKey, subscriberId);
5955 }
5956
5957 editor.commit();
5958 return true;
5959 } finally {
5960 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005961 }
Derek Tan7226c842014-07-02 17:42:23 -07005962 }
5963
5964 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005965 public String getLine1NumberForDisplay(int subId, String callingPackage,
5966 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005967 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005968 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005969 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005970 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005971 return null;
5972 }
Derek Tan97ebb422014-09-05 16:55:38 -07005973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005974 final long identity = Binder.clearCallingIdentity();
5975 try {
5976 String iccId = getIccId(subId);
5977 if (iccId != null) {
5978 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5979 if (DBG_MERGE) {
5980 log("getLine1NumberForDisplay returning "
5981 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5982 }
5983 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5986 return null;
5987 } finally {
5988 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005989 }
Derek Tan7226c842014-07-02 17:42:23 -07005990 }
5991
5992 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005993 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5994 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005995 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005996 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005997 return null;
5998 }
Derek Tan97ebb422014-09-05 16:55:38 -07005999
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 final long identity = Binder.clearCallingIdentity();
6001 try {
6002 String iccId = getIccId(subId);
6003 if (iccId != null) {
6004 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6005 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6006 }
6007 return null;
6008 } finally {
6009 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006010 }
Derek Tan7226c842014-07-02 17:42:23 -07006011 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006012
6013 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006014 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6015 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006016 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6017 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006018 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006019 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006020 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006021 return null;
6022 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006023
Jordan Liub49b04b2019-05-06 14:45:15 -07006024 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6025 // the process, where TelephonyManager was instantiated.
6026 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006027 final long identity = Binder.clearCallingIdentity();
6028 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006029 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 final TelephonyManager tele = TelephonyManager.from(context);
6031 final SubscriptionManager sub = SubscriptionManager.from(context);
6032
6033 // Figure out what subscribers are currently active
6034 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035
Jordan Liub49b04b2019-05-06 14:45:15 -07006036 // Only consider subs which match the current subId
6037 // This logic can be simplified. See b/131189269 for progress.
6038 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006039 activeSubscriberIds.add(tele.getSubscriberId(subId));
6040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041
6042 // First pass, find a number override for an active subscriber
6043 String mergeNumber = null;
6044 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6045 for (String key : prefs.keySet()) {
6046 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6047 final String subscriberId = (String) prefs.get(key);
6048 if (activeSubscriberIds.contains(subscriberId)) {
6049 final String iccId = key.substring(
6050 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6051 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6052 mergeNumber = (String) prefs.get(numberKey);
6053 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006054 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055 + " for active subscriber " + subscriberId);
6056 }
6057 if (!TextUtils.isEmpty(mergeNumber)) {
6058 break;
6059 }
6060 }
6061 }
6062 }
6063
6064 // Shortcut when no active merged subscribers
6065 if (TextUtils.isEmpty(mergeNumber)) {
6066 return null;
6067 }
6068
6069 // Second pass, find all subscribers under that line override
6070 final ArraySet<String> result = new ArraySet<>();
6071 for (String key : prefs.keySet()) {
6072 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6073 final String number = (String) prefs.get(key);
6074 if (mergeNumber.equals(number)) {
6075 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6076 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6077 final String subscriberId = (String) prefs.get(subscriberKey);
6078 if (!TextUtils.isEmpty(subscriberId)) {
6079 result.add(subscriberId);
6080 }
6081 }
6082 }
6083 }
6084
6085 final String[] resultArray = result.toArray(new String[result.size()]);
6086 Arrays.sort(resultArray);
6087 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006088 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6090 }
6091 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006092 } finally {
6093 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006094 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006095 }
6096
6097 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006098 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6099 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6100
6101 final long identity = Binder.clearCallingIdentity();
6102 try {
6103 final TelephonyManager telephonyManager = mApp.getSystemService(
6104 TelephonyManager.class);
6105 String subscriberId = telephonyManager.getSubscriberId(subId);
6106 if (subscriberId == null) {
6107 if (DBG) {
6108 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6109 + subId);
6110 }
6111 return null;
6112 }
6113
6114 final SubscriptionInfo info = SubscriptionController.getInstance()
6115 .getSubscriptionInfo(subId);
6116 final ParcelUuid groupUuid = info.getGroupUuid();
6117 // If it doesn't belong to any group, return just subscriberId of itself.
6118 if (groupUuid == null) {
6119 return new String[]{subscriberId};
6120 }
6121
6122 // Get all subscriberIds from the group.
6123 final List<String> mergedSubscriberIds = new ArrayList<>();
6124 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006125 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6126 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006127 for (SubscriptionInfo subInfo : groupInfos) {
6128 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6129 if (subscriberId != null) {
6130 mergedSubscriberIds.add(subscriberId);
6131 }
6132 }
6133
6134 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6135 } finally {
6136 Binder.restoreCallingIdentity(identity);
6137
6138 }
6139 }
6140
6141 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006142 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006143 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006144 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006145
6146 final long identity = Binder.clearCallingIdentity();
6147 try {
6148 final Phone phone = getPhone(subId);
6149 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6150 } finally {
6151 Binder.restoreCallingIdentity(identity);
6152 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006153 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006154
6155 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006156 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006157 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6158 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006159 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6160 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006161
6162 final long identity = Binder.clearCallingIdentity();
6163 try {
6164 final Phone phone = getPhone(subId);
6165 if (phone == null) {
6166 return false;
6167 }
6168 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6169 cdmaNonRoamingList);
6170 } finally {
6171 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006172 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006173 }
6174
6175 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006176 @Deprecated
6177 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6178 enforceModifyPermission();
6179
6180 int returnValue = 0;
6181 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006182 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006183 if(result.exception == null) {
6184 if (result.result != null) {
6185 byte[] responseData = (byte[])(result.result);
6186 if(responseData.length > oemResp.length) {
6187 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6188 responseData.length + "bytes. Buffer Size is " +
6189 oemResp.length + "bytes.");
6190 }
6191 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6192 returnValue = responseData.length;
6193 }
6194 } else {
6195 CommandException ex = (CommandException) result.exception;
6196 returnValue = ex.getCommandError().ordinal();
6197 if(returnValue > 0) returnValue *= -1;
6198 }
6199 } catch (RuntimeException e) {
6200 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6201 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6202 if(returnValue > 0) returnValue *= -1;
6203 }
6204
6205 return returnValue;
6206 }
6207
6208 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006209 public void setRadioCapability(RadioAccessFamily[] rafs) {
6210 try {
6211 ProxyController.getInstance().setRadioCapability(rafs);
6212 } catch (RuntimeException e) {
6213 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6214 }
6215 }
6216
6217 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006218 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006219 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006220 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006221 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006222 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006223 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 final long identity = Binder.clearCallingIdentity();
6225 try {
chen xub97461a2018-10-26 14:17:57 -07006226 TelephonyPermissions
6227 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6228 mApp, phone.getSubId(), "getRadioAccessFamily");
6229 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006230 } finally {
6231 Binder.restoreCallingIdentity(identity);
6232 }
chen xub97461a2018-10-26 14:17:57 -07006233 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006234 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006235
6236 @Override
6237 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006238 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006239 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240
6241 final long identity = Binder.clearCallingIdentity();
6242 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006243 ImsManager.getInstance(defaultPhone.getContext(),
6244 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006245 } finally {
6246 Binder.restoreCallingIdentity(identity);
6247 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006248 }
6249
6250 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006251 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006252 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006253 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6254 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006255 return false;
6256 }
Svet Ganovb320e182015-04-16 12:30:10 -07006257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258 final long identity = Binder.clearCallingIdentity();
6259 try {
6260 // Check the user preference and the system-level IMS setting. Even if the user has
6261 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6262 // In the long run, we may instead need to check if there exists a connection service
6263 // which can support video calling.
6264 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006265 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266 return imsManager.isVtEnabledByPlatform()
6267 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6268 && imsManager.isVtEnabledByUser();
6269 } finally {
6270 Binder.restoreCallingIdentity(identity);
6271 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006272 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006273
Andrew Leea1239f22015-03-02 17:44:07 -08006274 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006275 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6276 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006277 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006278 mApp, subId, callingPackage, callingFeatureId,
6279 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 return false;
6281 }
6282
6283 final long identity = Binder.clearCallingIdentity();
6284 try {
6285 CarrierConfigManager configManager =
6286 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006287 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6289 } finally {
6290 Binder.restoreCallingIdentity(identity);
6291 }
Andrew Leea1239f22015-03-02 17:44:07 -08006292 }
6293
6294 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006295 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006297 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 return false;
6299 }
6300
6301 final long identity = Binder.clearCallingIdentity();
6302 try {
6303 CarrierConfigManager configManager =
6304 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006305 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6307 } finally {
6308 Binder.restoreCallingIdentity(identity);
6309 }
Andrew Leea1239f22015-03-02 17:44:07 -08006310 }
6311
Andrew Lee9431b832015-03-09 18:46:45 -07006312 @Override
6313 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006314 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006315 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006316 }
6317
6318 @Override
6319 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006320 final long identity = Binder.clearCallingIdentity();
6321 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006322 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006323 } finally {
6324 Binder.restoreCallingIdentity(identity);
6325 }
Andrew Lee9431b832015-03-09 18:46:45 -07006326 }
6327
Hall Liuf6668912018-10-31 17:05:23 -07006328 /**
6329 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6330 * support for the feature and device firmware support.
6331 *
6332 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6333 */
6334 @Override
6335 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006336 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006337 final Phone phone = getPhone(subscriptionId);
6338 if (phone == null) {
6339 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6340 return false;
6341 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006343 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006344 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6345 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006346 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006347 return isCarrierSupported && isDeviceSupported;
6348 } finally {
6349 Binder.restoreCallingIdentity(identity);
6350 }
Hall Liu98187582018-01-22 19:15:32 -08006351 }
6352
Hall Liuf6668912018-10-31 17:05:23 -07006353 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006354 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6355 * RTT setting, will return true if the device and carrier both support RTT.
6356 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006357 */
6358 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006359 final long identity = Binder.clearCallingIdentity();
6360 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006361 boolean isRttSupported = isRttSupported(subscriptionId);
6362 boolean isUserRttSettingOn = Settings.Secure.getInt(
6363 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6364 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6365 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6366 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367 } finally {
6368 Binder.restoreCallingIdentity(identity);
6369 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006370 }
6371
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006372 @Deprecated
6373 @Override
6374 public String getDeviceId(String callingPackage) {
6375 return getDeviceIdWithFeature(callingPackage, null);
6376 }
6377
Sanket Padawe7310cc72015-01-14 09:53:20 -08006378 /**
6379 * Returns the unique device ID of phone, for example, the IMEI for
6380 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6381 *
6382 * <p>Requires Permission:
6383 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6384 */
6385 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006386 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006387 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006388 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006389 return null;
6390 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006391 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006392 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006393 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006394 return null;
6395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006396
6397 final long identity = Binder.clearCallingIdentity();
6398 try {
6399 return phone.getDeviceId();
6400 } finally {
6401 Binder.restoreCallingIdentity(identity);
6402 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006403 }
6404
Ping Sunc67b7c22016-03-02 19:16:45 +08006405 /**
6406 * {@hide}
6407 * Returns the IMS Registration Status on a particular subid
6408 *
6409 * @param subId
6410 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006411 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006412 Phone phone = getPhone(subId);
6413 if (phone != null) {
6414 return phone.isImsRegistered();
6415 } else {
6416 return false;
6417 }
6418 }
6419
Santos Cordon7a1885b2015-02-03 11:15:19 -08006420 @Override
6421 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006422 final long identity = Binder.clearCallingIdentity();
6423 try {
6424 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6425 } finally {
6426 Binder.restoreCallingIdentity(identity);
6427 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006428 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006429
Tyler Gunnf70ed162019-04-03 15:28:53 -07006430 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006431 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006432 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006433 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006434 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006435 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6436 }
6437 final long identity = Binder.clearCallingIdentity();
6438 try {
6439 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6440 } finally {
6441 Binder.restoreCallingIdentity(identity);
6442 }
6443 }
6444
6445 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006446 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6447 final long identity = Binder.clearCallingIdentity();
6448 try {
6449 Phone phone = getPhone(subscriptionId);
6450 if (phone == null) {
6451 return null;
6452 }
6453 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6454 } finally {
6455 Binder.restoreCallingIdentity(identity);
6456 }
6457 }
6458
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006459 /**
6460 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006461 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006462 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006463 final long identity = Binder.clearCallingIdentity();
6464 try {
6465 Phone phone = getPhone(subId);
6466 if (phone != null) {
6467 return phone.isWifiCallingEnabled();
6468 } else {
6469 return false;
6470 }
6471 } finally {
6472 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006473 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006474 }
6475
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006476 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006477 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006478 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006479 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 final long identity = Binder.clearCallingIdentity();
6481 try {
6482 Phone phone = getPhone(subId);
6483 if (phone != null) {
6484 return phone.isVideoEnabled();
6485 } else {
6486 return false;
6487 }
6488 } finally {
6489 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006490 }
6491 }
6492
6493 /**
6494 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6495 * defined in {@link ImsRegistrationImplBase}.
6496 */
6497 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006498 final long identity = Binder.clearCallingIdentity();
6499 try {
6500 Phone phone = getPhone(subId);
6501 if (phone != null) {
6502 return phone.getImsRegistrationTech();
6503 } else {
6504 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6505 }
6506 } finally {
6507 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006508 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006509 }
6510
Stuart Scott8eef64f2015-04-08 15:13:54 -07006511 @Override
6512 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006513 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006514 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6515 return;
6516 }
6517
Svet Ganovcc087f82015-05-12 20:35:54 -07006518 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006519
Svet Ganovcc087f82015-05-12 20:35:54 -07006520 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006521 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6522 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006523 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006524 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006525 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006526 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6527 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006528 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006529 // There has been issues when Sms raw table somehow stores orphan
6530 // fragments. They lead to garbled message when new fragments come
6531 // in and combined with those stale ones. In case this happens again,
6532 // user can reset all network settings which will clean up this table.
6533 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006534 // Clean up IMS settings as well here.
6535 int slotId = getSlotIndex(subId);
6536 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6537 ImsManager.getInstance(mApp, slotId).factoryReset();
6538 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006539
6540 // Erase modem config if erase modem on network setting is enabled.
6541 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6542 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6543 if (configValue != null && Boolean.parseBoolean(configValue)) {
6544 sendEraseModemConfig(getDefaultPhone());
6545 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006546 } finally {
6547 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006548 }
6549 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006550
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006551 private void cleanUpSmsRawTable(Context context) {
6552 ContentResolver resolver = context.getContentResolver();
6553 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6554 resolver.delete(uri, null, null);
6555 }
6556
Narayan Kamath1c496c22015-04-16 14:40:19 +01006557 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006558 public String getSimLocaleForSubscriber(int subId) {
6559 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6560 final Phone phone = getPhone(subId);
6561 if (phone == null) {
6562 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006563 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565 final long identity = Binder.clearCallingIdentity();
6566 try {
chen xu5d3637b2019-01-21 23:31:38 -08006567 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006568 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006569 if (info == null) {
6570 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6571 return null;
6572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573 // Try and fetch the locale from the carrier properties or from the SIM language
6574 // preferences (EF-PL and EF-LI)...
6575 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006576 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006577 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6578 if (localeFromDefaultSim != null) {
6579 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6580 if (DBG) log("Using locale from subId: " + subId + " locale: "
6581 + localeFromDefaultSim);
6582 return localeFromDefaultSim.toLanguageTag();
6583 } else {
6584 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006585 }
6586 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006587
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006588 // The SIM language preferences only store a language (e.g. fr = French), not an
6589 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6590 // the SIM and carrier preferences does not include a country we add the country
6591 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006592 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006593 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006594 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006595 return mccLocale.toLanguageTag();
6596 }
6597
6598 if (DBG) log("No locale found - returning null");
6599 return null;
6600 } finally {
6601 Binder.restoreCallingIdentity(identity);
6602 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006603 }
6604
6605 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006606 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6607 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006608 }
6609
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006610 /**
6611 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6612 */
6613 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006614 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6615 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006616 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006617
Chenjie Yu1ba97252018-01-11 18:16:20 -08006618 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006619 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006620
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006621 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006622 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6623 * representing the state of the modem.
6624 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006625 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6626 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006627 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006628 */
6629 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006630 public void requestModemActivityInfo(ResultReceiver result) {
6631 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006632 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633
6634 final long identity = Binder.clearCallingIdentity();
6635 try {
sqian1a1be542020-03-05 11:37:28 -08006636 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006637 } finally {
6638 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006639 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006640 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006641
Siddharth Rayb8114062018-06-17 15:02:38 -07006642 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6643 // less than total activity duration.
6644 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6645 if (info == null) {
6646 return false;
6647 }
6648 int activityDurationMs =
6649 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6650 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006651 int[] txTimeMs = info.getTransmitTimeMillis();
6652 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6653 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006654 }
6655 return (info.isValid()
6656 && (info.getSleepTimeMillis() <= activityDurationMs)
6657 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006658 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006659 && (totalTxTimeMs <= activityDurationMs));
6660 }
6661
Jack Yu85bd38a2015-11-09 11:34:32 -08006662 /**
6663 * {@hide}
6664 * Returns the service state information on specified subscription.
6665 */
6666 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006667 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6668 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006670 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006671 return null;
6672 }
6673
Hall Liuf19c44f2018-11-27 14:38:17 -08006674 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6675 LocationAccessPolicy.checkLocationPermission(mApp,
6676 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6677 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006678 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006679 .setCallingPid(Binder.getCallingPid())
6680 .setCallingUid(Binder.getCallingUid())
6681 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006682 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006683 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6684 .build());
6685
6686 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6687 LocationAccessPolicy.checkLocationPermission(mApp,
6688 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6689 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006690 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006691 .setCallingPid(Binder.getCallingPid())
6692 .setCallingUid(Binder.getCallingUid())
6693 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006694 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006695 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6696 .build());
6697 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6698 boolean hasFinePermission =
6699 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6700 boolean hasCoarsePermission =
6701 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6702
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703 final long identity = Binder.clearCallingIdentity();
6704 try {
6705 final Phone phone = getPhone(subId);
6706 if (phone == null) {
6707 return null;
6708 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006709
Hall Liuf19c44f2018-11-27 14:38:17 -08006710 ServiceState ss = phone.getServiceState();
6711
6712 // Scrub out the location info in ServiceState depending on what level of access
6713 // the caller has.
6714 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006715 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6716 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006717 } finally {
6718 Binder.restoreCallingIdentity(identity);
6719 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006720 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006721
6722 /**
6723 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6724 *
6725 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6726 * voicemail ringtone.
6727 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6728 * PhoneAccount.
6729 */
6730 @Override
6731 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732 final long identity = Binder.clearCallingIdentity();
6733 try {
6734 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6735 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006736 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006737 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006738
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006739 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6740 } finally {
6741 Binder.restoreCallingIdentity(identity);
6742 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006743 }
6744
6745 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006746 * Sets the per-account voicemail ringtone.
6747 *
6748 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6749 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6750 *
6751 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6752 * voicemail ringtone.
6753 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6754 * PhoneAccount.
6755 */
6756 @Override
6757 public void setVoicemailRingtoneUri(String callingPackage,
6758 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006759 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006760 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006761 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6762 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6764 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6765 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767
6768 final long identity = Binder.clearCallingIdentity();
6769 try {
6770 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6771 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006772 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006773 }
6774 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6775 } finally {
6776 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006777 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006778 }
6779
6780 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006781 * Returns whether vibration is set for voicemail notification in Phone settings.
6782 *
6783 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6784 * voicemail vibration setting.
6785 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6786 */
6787 @Override
6788 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006789 final long identity = Binder.clearCallingIdentity();
6790 try {
6791 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6792 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006793 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006794 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6797 } finally {
6798 Binder.restoreCallingIdentity(identity);
6799 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006800 }
6801
Youhan Wange64578a2016-05-02 15:32:42 -07006802 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006803 * Sets the per-account voicemail vibration.
6804 *
6805 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6806 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6807 *
6808 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6809 * voicemail vibration setting.
6810 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6811 * specific PhoneAccount.
6812 */
6813 @Override
6814 public void setVoicemailVibrationEnabled(String callingPackage,
6815 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006816 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006817 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006818 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6819 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6821 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6822 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006823 }
6824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825 final long identity = Binder.clearCallingIdentity();
6826 try {
6827 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6828 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006829 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006830 }
6831 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6832 } finally {
6833 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006834 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006835 }
6836
6837 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006838 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6839 *
6840 * @throws SecurityException if the caller does not have the required permission
6841 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006842 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006843 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006844 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006845 }
6846
6847 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006848 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6849 * permission.
6850 *
6851 * @throws SecurityException if the caller does not have the required permission
6852 */
6853 private void enforceSendSmsPermission() {
6854 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6855 }
6856
6857 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006858 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006859 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006860 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006861 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006862 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863 final long identity = Binder.clearCallingIdentity();
6864 try {
6865 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006866 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006867 if (componentName == null) {
6868 throw new SecurityException(
6869 "Caller not current active visual voicemail package[null]");
6870 }
6871 String vvmPackage = componentName.getPackageName();
6872 if (!callingPackage.equals(vvmPackage)) {
6873 throw new SecurityException("Caller not current active visual voicemail package["
6874 + vvmPackage + "]");
6875 }
6876 } finally {
6877 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006878 }
6879 }
6880
6881 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006882 * Return the application ID for the app type.
6883 *
6884 * @param subId the subscription ID that this request applies to.
6885 * @param appType the uicc app type.
6886 * @return Application ID for specificied app type, or null if no uicc.
6887 */
6888 @Override
6889 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006890 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006891 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006892
6893 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006894 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895 if (phone == null) {
6896 return null;
6897 }
6898 String aid = null;
6899 try {
6900 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6901 .getApplicationByType(appType).getAid();
6902 } catch (Exception e) {
6903 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6904 }
6905 return aid;
6906 } finally {
6907 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006908 }
Youhan Wange64578a2016-05-02 15:32:42 -07006909 }
6910
Youhan Wang4001d252016-05-11 10:29:41 -07006911 /**
6912 * Return the Electronic Serial Number.
6913 *
6914 * @param subId the subscription ID that this request applies to.
6915 * @return ESN or null if error.
6916 */
6917 @Override
6918 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006919 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006920 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921
6922 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006923 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006924 if (phone == null) {
6925 return null;
6926 }
6927 String esn = null;
6928 try {
6929 esn = phone.getEsn();
6930 } catch (Exception e) {
6931 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6932 }
6933 return esn;
6934 } finally {
6935 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006936 }
Youhan Wang4001d252016-05-11 10:29:41 -07006937 }
6938
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006939 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006940 * Return the Preferred Roaming List Version.
6941 *
6942 * @param subId the subscription ID that this request applies to.
6943 * @return PRLVersion or null if error.
6944 */
6945 @Override
6946 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006947 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006948 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006949
6950 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006951 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952 if (phone == null) {
6953 return null;
6954 }
6955 String cdmaPrlVersion = null;
6956 try {
6957 cdmaPrlVersion = phone.getCdmaPrlVersion();
6958 } catch (Exception e) {
6959 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6960 }
6961 return cdmaPrlVersion;
6962 } finally {
6963 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006964 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006965 }
6966
6967 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006968 * Get snapshot of Telephony histograms
6969 * @return List of Telephony histograms
6970 * @hide
6971 */
6972 @Override
6973 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6975 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006976
6977 final long identity = Binder.clearCallingIdentity();
6978 try {
6979 return RIL.getTelephonyRILTimingHistograms();
6980 } finally {
6981 Binder.restoreCallingIdentity(identity);
6982 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006983 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006984
6985 /**
6986 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006987 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6988 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006989 * Require system privileges. In the future we may add this to carrier APIs.
6990 *
Michele Berionne482f8202018-11-27 18:57:59 -08006991 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006992 */
6993 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006994 @TelephonyManager.SetCarrierRestrictionResult
6995 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006996 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006997 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006998
Michele Berionne482f8202018-11-27 18:57:59 -08006999 if (carrierRestrictionRules == null) {
7000 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007001 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 final long identity = Binder.clearCallingIdentity();
7004 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007005 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007006 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007 } finally {
7008 Binder.restoreCallingIdentity(identity);
7009 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007010 }
7011
7012 /**
7013 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007014 * Get the allowed carrier list and the excluded carrier list, including the priority between
7015 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007016 * Require system privileges. In the future we may add this to carrier APIs.
7017 *
Michele Berionne482f8202018-11-27 18:57:59 -08007018 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007019 */
7020 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007021 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007022 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007023 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024
7025 final long identity = Binder.clearCallingIdentity();
7026 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007027 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7028 if (response instanceof CarrierRestrictionRules) {
7029 return (CarrierRestrictionRules) response;
7030 }
7031 // Response is an Exception of some kind,
7032 // which is signalled to the user as a NULL retval
7033 return null;
7034 } catch (Exception e) {
7035 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7036 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007037 } finally {
7038 Binder.restoreCallingIdentity(identity);
7039 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007040 }
7041
fionaxu59545b42016-05-25 15:53:37 -07007042 /**
7043 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7044 * @param subId the subscription ID that this action applies to.
7045 * @param enabled control enable or disable metered apns.
7046 * {@hide}
7047 */
7048 @Override
7049 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7050 enforceModifyPermission();
7051 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052
7053 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007054 if (phone == null) {
7055 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7056 return;
7057 }
7058 try {
7059 phone.carrierActionSetMeteredApnsEnabled(enabled);
7060 } catch (Exception e) {
7061 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 } finally {
7063 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007064 }
7065 }
7066
7067 /**
7068 * Action set from carrier signalling broadcast receivers to enable/disable radio
7069 * @param subId the subscription ID that this action applies to.
7070 * @param enabled control enable or disable radio.
7071 * {@hide}
7072 */
7073 @Override
7074 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7075 enforceModifyPermission();
7076 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007077
7078 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007079 if (phone == null) {
7080 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7081 return;
7082 }
7083 try {
7084 phone.carrierActionSetRadioEnabled(enabled);
7085 } catch (Exception e) {
7086 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007087 } finally {
7088 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007089 }
7090 }
7091
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007092 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007093 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7094 * network status based on which carrier apps could apply actions accordingly,
7095 * enable/disable default url handler for example.
7096 *
7097 * @param subId the subscription ID that this action applies to.
7098 * @param report control start/stop reporting the default network status.
7099 * {@hide}
7100 */
7101 @Override
7102 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7103 enforceModifyPermission();
7104 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007105
7106 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007107 if (phone == null) {
7108 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7109 return;
7110 }
7111 try {
7112 phone.carrierActionReportDefaultNetworkStatus(report);
7113 } catch (Exception e) {
7114 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007115 } finally {
7116 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007117 }
7118 }
7119
7120 /**
fionaxud9622282017-07-17 17:51:30 -07007121 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7122 * @param subId the subscription ID that this action applies to.
7123 * {@hide}
7124 */
7125 @Override
7126 public void carrierActionResetAll(int subId) {
7127 enforceModifyPermission();
7128 final Phone phone = getPhone(subId);
7129 if (phone == null) {
7130 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7131 return;
7132 }
7133 try {
7134 phone.carrierActionResetAll();
7135 } catch (Exception e) {
7136 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7137 }
7138 }
7139
7140 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007141 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7142 * bug report is being generated.
7143 */
7144 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007145 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007146 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7147 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007148 writer.println("Permission Denial: can't dump Phone from pid="
7149 + Binder.getCallingPid()
7150 + ", uid=" + Binder.getCallingUid()
7151 + "without permission "
7152 + android.Manifest.permission.DUMP);
7153 return;
7154 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007155 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007156 }
Jack Yueb89b242016-06-22 13:27:47 -07007157
Brad Ebingerdac2f002018-04-03 15:17:52 -07007158 @Override
7159 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7160 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7161 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007162 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7163 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007164 }
7165
Jack Yueb89b242016-06-22 13:27:47 -07007166 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007167 * Policy control of data connection. Usually used when data limit is passed.
7168 * @param enabled True if enabling the data, otherwise disabling.
7169 * @param subId Subscription index
7170 * {@hide}
7171 */
7172 @Override
7173 public void setPolicyDataEnabled(boolean enabled, int subId) {
7174 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007175
7176 final long identity = Binder.clearCallingIdentity();
7177 try {
7178 Phone phone = getPhone(subId);
7179 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007180 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 }
7182 } finally {
7183 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007184 }
7185 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007186
7187 /**
7188 * Get Client request stats
7189 * @return List of Client Request Stats
7190 * @hide
7191 */
7192 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007193 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7194 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007195 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007196 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007197 return null;
7198 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007199 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201 final long identity = Binder.clearCallingIdentity();
7202 try {
7203 if (phone != null) {
7204 return phone.getClientRequestStats();
7205 }
7206
7207 return null;
7208 } finally {
7209 Binder.restoreCallingIdentity(identity);
7210 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007211 }
7212
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007213 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007214 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007215 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007216 }
Jack Yueb4124c2017-02-16 15:32:43 -08007217
7218 /**
Grace Chen70990072017-03-24 17:21:30 -07007219 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007220 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007221 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007222 * @param state State of SIM (power down, power up, pass through)
7223 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7224 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7225 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007226 *
7227 **/
7228 @Override
Grace Chen70990072017-03-24 17:21:30 -07007229 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007230 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007231 Phone phone = PhoneFactory.getPhone(slotIndex);
7232
vagdeviaf9a5b92018-08-15 16:01:53 -07007233 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 final long identity = Binder.clearCallingIdentity();
7236 try {
7237 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007238 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239 }
7240 } finally {
7241 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007242 }
7243 }
Shuo Qiandd210312017-04-12 22:11:33 +00007244
Tyler Gunn65d45c22017-06-05 11:22:26 -07007245 private boolean isUssdApiAllowed(int subId) {
7246 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007247 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007248 if (configManager == null) {
7249 return false;
7250 }
7251 PersistableBundle pb = configManager.getConfigForSubId(subId);
7252 if (pb == null) {
7253 return false;
7254 }
7255 return pb.getBoolean(
7256 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7257 }
7258
Shuo Qiandd210312017-04-12 22:11:33 +00007259 /**
7260 * Check if phone is in emergency callback mode
7261 * @return true if phone is in emergency callback mode
7262 * @param subId sub id
7263 */
goneil9c5f4872017-12-05 14:07:56 -08007264 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007265 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007266 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007267 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007268
7269 final long identity = Binder.clearCallingIdentity();
7270 try {
7271 if (phone != null) {
7272 return phone.isInEcm();
7273 } else {
7274 return false;
7275 }
7276 } finally {
7277 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007278 }
7279 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007280
7281 /**
7282 * Get the current signal strength information for the given subscription.
7283 * Because this information is not updated when the device is in a low power state
7284 * it should not be relied-upon to be current.
7285 * @param subId Subscription index
7286 * @return the most recent cached signal strength info from the modem
7287 */
7288 @Override
7289 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007290 final long identity = Binder.clearCallingIdentity();
7291 try {
7292 Phone p = getPhone(subId);
7293 if (p == null) {
7294 return null;
7295 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007297 return p.getSignalStrength();
7298 } finally {
7299 Binder.restoreCallingIdentity(identity);
7300 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007301 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007302
Pengquan Meng77b7f132018-08-22 14:49:57 -07007303 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007304 * Get the current modem radio state for the given slot.
7305 * @param slotIndex slot index.
7306 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007307 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007308 * @return the current radio power state from the modem
7309 */
7310 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007311 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007312 Phone phone = PhoneFactory.getPhone(slotIndex);
7313 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007314 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7315 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007316 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7317 }
7318
7319 final long identity = Binder.clearCallingIdentity();
7320 try {
7321 return phone.getRadioPowerState();
7322 } finally {
7323 Binder.restoreCallingIdentity(identity);
7324 }
7325 }
7326 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7327 }
7328
7329 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007330 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7331 *
7332 * <p>Requires one of the following permissions:
7333 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7334 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7335 * privileges.
7336 *
7337 * @param subId subscription id
7338 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7339 * {@code false}.
7340 */
7341 @Override
7342 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007343 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7344 null /* message */);
7345
Pengquan Menga1bb6272018-09-06 09:59:22 -07007346 boolean isEnabled = false;
7347 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007348 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007349 Phone phone = getPhone(subId);
7350 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007351 } catch (Exception e) {
7352 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7353 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007354 } finally {
7355 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007356 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007357 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007358 }
7359
7360
7361 /**
7362 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7363 *
7364 * <p> Requires permission:
7365 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7366 * privileges.
7367 *
7368 * @param subId subscription id
7369 * @param isEnabled {@code true} means enable, {@code false} means disable.
7370 */
7371 @Override
7372 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7374 mApp, subId, "setDataRoamingEnabled");
7375
Pengquan Menga1bb6272018-09-06 09:59:22 -07007376 final long identity = Binder.clearCallingIdentity();
7377 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007378 Phone phone = getPhone(subId);
7379 if (phone != null) {
7380 phone.setDataRoamingEnabled(isEnabled);
7381 }
7382 } finally {
7383 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007384 }
7385 }
7386
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007387 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007388 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007389 TelephonyPermissions
7390 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007391 mApp, subId, "isManualNetworkSelectionAllowed");
7392
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007393 boolean isAllowed = true;
7394 final long identity = Binder.clearCallingIdentity();
7395 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007396 Phone phone = getPhone(subId);
7397 if (phone != null) {
7398 isAllowed = phone.isCspPlmnEnabled();
7399 }
7400 } finally {
7401 Binder.restoreCallingIdentity(identity);
7402 }
7403 return isAllowed;
7404 }
7405
7406 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007407 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007408 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007409 try {
7410 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007411 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007412 } catch (SecurityException e) {
7413 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7414 // has carrier privileges on an active UICC
7415 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7416 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007417 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007418 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007419 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007420
7421 final long identity = Binder.clearCallingIdentity();
7422 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007423 UiccController uiccController = UiccController.getInstance();
7424 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007425 if (hasReadPermission) {
7426 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007427 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007428
7429 // Remove private info if the caller doesn't have access
7430 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7431 for (UiccCardInfo cardInfo : cardInfos) {
7432 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7433 // is available
7434 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7435 if (card == null || card.getUiccProfile() == null) {
7436 // assume no access if the card or profile is unavailable
7437 filteredInfos.add(cardInfo.getUnprivileged());
7438 continue;
7439 }
7440 UiccProfile profile = card.getUiccProfile();
7441 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7442 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7443 filteredInfos.add(cardInfo);
7444 } else {
7445 filteredInfos.add(cardInfo.getUnprivileged());
7446 }
7447 }
7448 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007449 } finally {
7450 Binder.restoreCallingIdentity(identity);
7451 }
7452 }
7453
7454 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007455 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007456 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007458 final long identity = Binder.clearCallingIdentity();
7459 try {
7460 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7461 if (slots == null) {
7462 Rlog.i(LOG_TAG, "slots is null.");
7463 return null;
7464 }
7465
7466 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7467 for (int i = 0; i < slots.length; i++) {
7468 UiccSlot slot = slots[i];
7469 if (slot == null) {
7470 continue;
7471 }
7472
Jordan Liu7be7e652019-05-06 18:55:02 +00007473 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474 UiccCard card = slot.getUiccCard();
7475 if (card != null) {
7476 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007477 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007478 cardId = slot.getEid();
7479 if (TextUtils.isEmpty(cardId)) {
7480 cardId = slot.getIccId();
7481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 }
7483
Jordan Liu857451f2019-05-09 16:35:35 -07007484 if (cardId != null) {
7485 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7486 // if cardId is an EID, it's all digits so this is fine
7487 cardId = IccUtils.stripTrailingFs(cardId);
7488 }
7489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 int cardState = 0;
7491 switch (slot.getCardState()) {
7492 case CARDSTATE_ABSENT:
7493 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7494 break;
7495 case CARDSTATE_PRESENT:
7496 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7497 break;
7498 case CARDSTATE_ERROR:
7499 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7500 break;
7501 case CARDSTATE_RESTRICTED:
7502 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7503 break;
7504 default:
7505 break;
7506
7507 }
7508
7509 infos[i] = new UiccSlotInfo(
7510 slot.isActive(),
7511 slot.isEuicc(),
7512 cardId,
7513 cardState,
7514 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007515 slot.isExtendedApduSupported(),
7516 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517 }
7518 return infos;
7519 } finally {
7520 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007521 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007522 }
7523
7524 @Override
7525 public boolean switchSlots(int[] physicalSlots) {
7526 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527
7528 final long identity = Binder.clearCallingIdentity();
7529 try {
7530 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7531 } finally {
7532 Binder.restoreCallingIdentity(identity);
7533 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007534 }
Jack Yu4c988042018-02-27 15:30:01 -08007535
7536 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007537 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007538 final long identity = Binder.clearCallingIdentity();
7539 try {
7540 return UiccController.getInstance().getCardIdForDefaultEuicc();
7541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
7544 }
7545
7546 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007547 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7548 enforceModifyPermission();
7549 final Phone phone = getPhone(subId);
7550 if (phone == null) {
7551 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7552 return;
7553 }
7554
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007555 final long identity = Binder.clearCallingIdentity();
7556 try {
7557 phone.setRadioIndicationUpdateMode(filters, mode);
7558 } finally {
7559 Binder.restoreCallingIdentity(identity);
7560 }
Jack Yu4c988042018-02-27 15:30:01 -08007561 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007562
7563 /**
goneil47ffb6e2018-04-06 15:40:58 -07007564 * A test API to reload the UICC profile.
7565 *
7566 * <p>Requires that the calling app has permission
7567 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7568 * @hide
7569 */
7570 @Override
7571 public void refreshUiccProfile(int subId) {
7572 enforceModifyPermission();
7573
7574 final long identity = Binder.clearCallingIdentity();
7575 try {
7576 Phone phone = getPhone(subId);
7577 if (phone == null) {
7578 return;
7579 }
7580 UiccCard uiccCard = phone.getUiccCard();
7581 if (uiccCard == null) {
7582 return;
7583 }
7584 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7585 if (uiccProfile == null) {
7586 return;
7587 }
7588 uiccProfile.refresh();
7589 } finally {
7590 Binder.restoreCallingIdentity(identity);
7591 }
7592 }
7593
7594 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007595 * Returns false if the mobile data is disabled by default, otherwise return true.
7596 */
7597 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007598 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007599 }
7600
7601 /**
7602 * Returns true if the data roaming is enabled by default, i.e the system property
7603 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7604 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7605 */
7606 private boolean getDefaultDataRoamingEnabled(int subId) {
7607 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007608 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007609 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007610 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7611 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7612 return isDataRoamingEnabled;
7613 }
7614
7615 /**
7616 * Returns the default network type for the given {@code subId}, if the default network type is
7617 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7618 */
7619 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007620 List<Integer> list = TelephonyProperties.default_network();
7621 int phoneId = mSubscriptionController.getPhoneId(subId);
7622 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7623 return list.get(phoneId);
7624 }
7625 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007626 }
fionaxua13278b2018-03-21 00:08:13 -07007627
7628 @Override
7629 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007630 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007631 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007632
7633 final long identity = Binder.clearCallingIdentity();
7634 try {
7635 final Phone phone = getPhone(subId);
7636 if (phone == null) {
7637 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7638 return;
7639 }
chen xueaba88a2019-03-15 13:15:10 -07007640 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7641 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007642 } finally {
7643 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007644 }
fionaxua13278b2018-03-21 00:08:13 -07007645 }
7646
7647 @Override
7648 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007649 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007650
7651 final long identity = Binder.clearCallingIdentity();
7652 try {
7653 final Phone phone = getPhone(subId);
7654 if (phone == null) {
7655 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7656 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7657 }
7658 return phone.getCarrierIdListVersion();
7659 } finally {
7660 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007661 }
fionaxua13278b2018-03-21 00:08:13 -07007662 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007663
7664 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007665 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7666 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007667 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007668 mApp, subId, callingPackage, callingFeatureId,
7669 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007670 return -1;
7671 }
7672
7673 final long identity = Binder.clearCallingIdentity();
7674 try {
7675 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7676 } finally {
7677 Binder.restoreCallingIdentity(identity);
7678 }
7679 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007680
7681 @Override
7682 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007683 TelephonyPermissions
7684 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007685 mApp, subId, "getCdmaRoamingMode");
7686
7687 final long identity = Binder.clearCallingIdentity();
7688 try {
7689 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7690 } finally {
7691 Binder.restoreCallingIdentity(identity);
7692 }
7693 }
7694
7695 @Override
7696 public boolean setCdmaRoamingMode(int subId, int mode) {
7697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7698 mApp, subId, "setCdmaRoamingMode");
7699
7700 final long identity = Binder.clearCallingIdentity();
7701 try {
7702 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7703 } finally {
7704 Binder.restoreCallingIdentity(identity);
7705 }
7706 }
7707
7708 @Override
7709 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7711 mApp, subId, "setCdmaSubscriptionMode");
7712
7713 final long identity = Binder.clearCallingIdentity();
7714 try {
7715 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7716 } finally {
7717 Binder.restoreCallingIdentity(identity);
7718 }
7719 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007720
sqianc5eccab2018-10-19 18:46:41 -07007721 @Override
sqian8c685422019-02-22 15:55:18 -08007722 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007723 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007725 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7726 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007727 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7728 }
7729 final long identity = Binder.clearCallingIdentity();
7730 try {
sqian854d44b2018-12-12 16:48:18 -08007731 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7732 for (Phone phone: PhoneFactory.getPhones()) {
7733 if (phone.getEmergencyNumberTracker() != null
7734 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7735 emergencyNumberListInternal.put(
7736 phone.getSubId(),
7737 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7738 }
sqian11b7a0e2018-12-05 18:48:28 -08007739 }
sqian854d44b2018-12-12 16:48:18 -08007740 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007741 } finally {
7742 Binder.restoreCallingIdentity(identity);
7743 }
sqianc5eccab2018-10-19 18:46:41 -07007744 }
7745
7746 @Override
sqian8c685422019-02-22 15:55:18 -08007747 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007748 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007749 if (!exactMatch) {
7750 TelephonyPermissions
7751 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007752 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007753 }
7754 final long identity = Binder.clearCallingIdentity();
7755 try {
sqian854d44b2018-12-12 16:48:18 -08007756 for (Phone phone: PhoneFactory.getPhones()) {
7757 if (phone.getEmergencyNumberTracker() != null
7758 && phone.getEmergencyNumberTracker() != null) {
7759 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7760 number, exactMatch)) {
7761 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007762 }
7763 }
sqian11b7a0e2018-12-05 18:48:28 -08007764 }
7765 return false;
7766 } finally {
7767 Binder.restoreCallingIdentity(identity);
7768 }
7769 }
7770
sqianf4ca7ed2019-01-15 18:32:07 -08007771 /**
7772 * Update emergency number list for test mode.
7773 */
7774 @Override
7775 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7776 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7777 "updateEmergencyNumberListTestMode");
7778
7779 final long identity = Binder.clearCallingIdentity();
7780 try {
7781 for (Phone phone: PhoneFactory.getPhones()) {
7782 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7783 if (tracker != null) {
7784 tracker.executeEmergencyNumberTestModeCommand(action, num);
7785 }
7786 }
7787 } finally {
7788 Binder.restoreCallingIdentity(identity);
7789 }
7790 }
7791
7792 /**
7793 * Get the full emergency number list for test mode.
7794 */
7795 @Override
7796 public List<String> getEmergencyNumberListTestMode() {
7797 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7798 "getEmergencyNumberListTestMode");
7799
7800 final long identity = Binder.clearCallingIdentity();
7801 try {
7802 Set<String> emergencyNumbers = new HashSet<>();
7803 for (Phone phone: PhoneFactory.getPhones()) {
7804 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7805 if (tracker != null) {
7806 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7807 emergencyNumbers.add(num.getNumber());
7808 }
7809 }
7810 }
7811 return new ArrayList<>(emergencyNumbers);
7812 } finally {
7813 Binder.restoreCallingIdentity(identity);
7814 }
7815 }
7816
chen xud6b45bd2018-10-30 22:27:10 -07007817 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007818 public int getEmergencyNumberDbVersion(int subId) {
7819 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7820
7821 final long identity = Binder.clearCallingIdentity();
7822 try {
7823 final Phone phone = getPhone(subId);
7824 if (phone == null) {
7825 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7826 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7827 }
7828 return phone.getEmergencyNumberDbVersion();
7829 } finally {
7830 Binder.restoreCallingIdentity(identity);
7831 }
7832 }
7833
7834 @Override
7835 public void notifyOtaEmergencyNumberDbInstalled() {
7836 enforceModifyPermission();
7837
7838 final long identity = Binder.clearCallingIdentity();
7839 try {
7840 for (Phone phone: PhoneFactory.getPhones()) {
7841 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7842 if (tracker != null) {
7843 tracker.updateOtaEmergencyNumberDatabase();
7844 }
7845 }
7846 } finally {
7847 Binder.restoreCallingIdentity(identity);
7848 }
7849 }
7850
7851 @Override
7852 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7853 enforceActiveEmergencySessionPermission();
7854
7855 final long identity = Binder.clearCallingIdentity();
7856 try {
7857 for (Phone phone: PhoneFactory.getPhones()) {
7858 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7859 if (tracker != null) {
7860 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7861 }
7862 }
7863 } finally {
7864 Binder.restoreCallingIdentity(identity);
7865 }
7866 }
7867
7868 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007869 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7870 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7871 Phone phone = getPhone(subId);
7872 if (phone == null) {
7873 return null;
7874 }
7875 final long identity = Binder.clearCallingIdentity();
7876 try {
7877 UiccProfile profile = UiccController.getInstance()
7878 .getUiccProfileForPhone(phone.getPhoneId());
7879 if (profile != null) {
7880 return profile.getCertsFromCarrierPrivilegeAccessRules();
7881 }
7882 } finally {
7883 Binder.restoreCallingIdentity(identity);
7884 }
7885 return null;
7886 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007887
7888 /**
7889 * Enable or disable a modem stack.
7890 */
7891 @Override
7892 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7893 enforceModifyPermission();
7894
7895 final long identity = Binder.clearCallingIdentity();
7896 try {
7897 Phone phone = PhoneFactory.getPhone(slotIndex);
7898 if (phone == null) {
7899 return false;
7900 } else {
7901 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7902 }
7903 } finally {
7904 Binder.restoreCallingIdentity(identity);
7905 }
7906 }
Michelecea4cf22018-12-21 15:00:11 -08007907
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007908 /**
7909 * Whether a modem stack is enabled or not.
7910 */
7911 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007912 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7913 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007914 Phone phone = PhoneFactory.getPhone(slotIndex);
7915 if (phone == null) return false;
7916
7917 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007918 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7919 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007920 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7921 }
7922
7923 final long identity = Binder.clearCallingIdentity();
7924 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007925 try {
7926 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7927 } catch (NoSuchElementException ex) {
7928 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7929 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007930 } finally {
7931 Binder.restoreCallingIdentity(identity);
7932 }
7933 }
7934
Michelecea4cf22018-12-21 15:00:11 -08007935 @Override
Michele0ea7d782019-03-19 14:58:42 -07007936 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007937 enforceModifyPermission();
7938
7939 final long identity = Binder.clearCallingIdentity();
7940 try {
7941 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007942 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007943 .commit();
7944 } finally {
7945 Binder.restoreCallingIdentity(identity);
7946 }
7947 }
7948
7949 @Override
Michele0ea7d782019-03-19 14:58:42 -07007950 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007951 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007952 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007953 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7954 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007955 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007956 }
Michelecea4cf22018-12-21 15:00:11 -08007957
7958 final long identity = Binder.clearCallingIdentity();
7959 try {
Michele0ea7d782019-03-19 14:58:42 -07007960 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007961 } finally {
7962 Binder.restoreCallingIdentity(identity);
7963 }
7964 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007965
Michele0ea7d782019-03-19 14:58:42 -07007966 @TelephonyManager.IsMultiSimSupportedResult
7967 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007968 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7969 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7970 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007971 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7972 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007973 }
7974 // Check if the hardware supports multisim functionality. If usage of multisim is not
7975 // supported by the modem, indicate that it is restricted.
7976 PhoneCapability staticCapability =
7977 mPhoneConfigurationManager.getStaticPhoneCapability();
7978 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007979 loge("isMultiSimSupportedInternal: no static configuration available");
7980 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007981 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00007982 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007983 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7984 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007985 }
7986 // Check if support of multiple SIMs is restricted by carrier
7987 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007988 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007989 }
7990
Michele0ea7d782019-03-19 14:58:42 -07007991 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007992 }
7993
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007994 /**
7995 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007996 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7997 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7998 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007999 * @param numOfSims number of active sims we want to switch to
8000 */
8001 @Override
8002 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008003 if (numOfSims == 1) {
8004 enforceModifyPermission();
8005 } else {
8006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8007 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8008 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008009 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008010
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008011 try {
Michele30b57b22019-03-01 12:01:14 -08008012 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008013 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008014 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8015 return;
8016 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008017 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8018 } finally {
8019 Binder.restoreCallingIdentity(identity);
8020 }
8021 }
8022
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008023 @Override
8024 public boolean isApplicationOnUicc(int subId, int appType) {
8025 enforceReadPrivilegedPermission("isApplicationOnUicc");
8026 Phone phone = getPhone(subId);
8027 if (phone == null) {
8028 return false;
8029 }
8030 final long identity = Binder.clearCallingIdentity();
8031 try {
8032 UiccCard uiccCard = phone.getUiccCard();
8033 if (uiccCard == null) {
8034 return false;
8035 }
8036 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8037 if (uiccProfile == null) {
8038 return false;
8039 }
8040 if (TelephonyManager.APPTYPE_SIM <= appType
8041 && appType <= TelephonyManager.APPTYPE_ISIM) {
8042 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8043 }
8044 return false;
8045 } finally {
8046 Binder.restoreCallingIdentity(identity);
8047 }
8048 }
8049
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008050 /**
chen xub4baa772019-04-03 10:23:41 -07008051 * Get whether making changes to modem configurations will trigger reboot.
8052 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008053 */
8054 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008055 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8056 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008057 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008058 mApp, subId, callingPackage, callingFeatureId,
8059 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008060 return false;
8061 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008062 final long identity = Binder.clearCallingIdentity();
8063 try {
8064 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8065 } finally {
8066 Binder.restoreCallingIdentity(identity);
8067 }
8068 }
8069
Nathan Harold29f5f052019-02-15 13:41:57 -08008070 private void updateModemStateMetrics() {
8071 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8072 // TODO: check the state for each modem if the api is ready.
8073 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8074 }
8075
Pengquan Meng3889a572019-01-23 11:16:29 -08008076 @Override
8077 public int[] getSlotsMapping() {
8078 enforceReadPrivilegedPermission("getSlotsMapping");
8079
8080 final long identity = Binder.clearCallingIdentity();
8081 try {
8082 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8083 // All logical slots should have a mapping to a physical slot.
8084 int[] logicalSlotsMapping = new int[phoneCount];
8085 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8086 for (int i = 0; i < slotInfos.length; i++) {
8087 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8088 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8089 }
8090 }
8091 return logicalSlotsMapping;
8092 } finally {
8093 Binder.restoreCallingIdentity(identity);
8094 }
8095 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008096
8097 /**
8098 * Get the IRadio HAL Version
8099 */
8100 @Override
8101 public int getRadioHalVersion() {
8102 Phone phone = getDefaultPhone();
8103 if (phone == null) return -1;
8104 HalVersion hv = phone.getHalVersion();
8105 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8106 return hv.major * 100 + hv.minor;
8107 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008108
8109 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008110 * Get the current calling package name.
8111 * @return the current calling package name
8112 */
8113 @Override
8114 public String getCurrentPackageName() {
8115 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8116 }
8117
8118 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008119 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8120 * corresponding network requests on a subId.
8121 *
8122 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008123 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008124 * 2) APN is un-metered for this subscription, or
8125 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008126 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008127 *
8128 * @return whether data is allowed for a apn type.
8129 *
8130 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008131 */
8132 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008133 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008134 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8135 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008136
8137 // Now that all security checks passes, perform the operation as ourselves.
8138 final long identity = Binder.clearCallingIdentity();
8139 try {
8140 Phone phone = getPhone(subId);
8141 if (phone == null) return false;
8142
Jack Yu41407ee2019-05-13 16:54:09 -07008143 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008144 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8145 } finally {
8146 Binder.restoreCallingIdentity(identity);
8147 }
8148 }
8149
8150 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008151 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008152 enforceReadPrivilegedPermission("isApnMetered");
8153
8154 // Now that all security checks passes, perform the operation as ourselves.
8155 final long identity = Binder.clearCallingIdentity();
8156 try {
8157 Phone phone = getPhone(subId);
8158 if (phone == null) return true; // By default return true.
8159
Jack Yu41407ee2019-05-13 16:54:09 -07008160 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008161 } finally {
8162 Binder.restoreCallingIdentity(identity);
8163 }
8164 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008165
8166 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008167 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8168 int subscriptionId, IBooleanConsumer resultCallback) {
8169 enforceModifyPermission();
8170 long token = Binder.clearCallingIdentity();
8171 try {
8172 Phone phone = getPhone(subscriptionId);
8173 if (phone == null) {
8174 try {
8175 if (resultCallback != null) {
8176 resultCallback.accept(false);
8177 }
8178 } catch (RemoteException e) {
8179 // ignore
8180 }
8181 return;
8182 }
8183 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8184 Pair.create(specifiers, (x) -> {
8185 try {
8186 if (resultCallback != null) {
8187 resultCallback.accept(x);
8188 }
8189 } catch (RemoteException e) {
8190 // ignore
8191 }
8192 });
8193 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8194 } finally {
8195 Binder.restoreCallingIdentity(token);
8196 }
8197 }
8198
8199 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008200 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8201 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8202 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8203 if (iccRecords == null) {
8204 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8205 return false;
8206 }
8207 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8208 }
8209
8210 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008211 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008212 if (callingPackage == null) {
8213 callingPackage = getCurrentPackageName();
8214 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008215 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8216 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8217 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8218 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8219 }
8220 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8221 Intent intent = new Intent();
8222 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8223 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8224 // Bring up choose default SMS subscription dialog right now
8225 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8226 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8227 mApp.startActivity(intent);
8228 }
chen xud5ca2d52019-05-28 15:20:57 -07008229
8230 @Override
8231 public String getMmsUAProfUrl(int subId) {
8232 //TODO investigate if this API should require proper permission check in R b/133791609
8233 final long identity = Binder.clearCallingIdentity();
8234 try {
8235 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8236 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8237 } finally {
8238 Binder.restoreCallingIdentity(identity);
8239 }
8240 }
8241
8242 @Override
8243 public String getMmsUserAgent(int subId) {
8244 //TODO investigate if this API should require proper permission check in R b/133791609
8245 final long identity = Binder.clearCallingIdentity();
8246 try {
8247 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8248 .getString(com.android.internal.R.string.config_mms_user_agent);
8249 } finally {
8250 Binder.restoreCallingIdentity(identity);
8251 }
8252 }
Jack Yub07d4972019-05-28 16:12:25 -07008253
8254 @Override
8255 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8256 enforceModifyPermission();
8257
8258 // Now that all security checks passes, perform the operation as ourselves.
8259 final long identity = Binder.clearCallingIdentity();
8260 try {
8261 Phone phone = getPhone(subId);
8262 if (phone == null) return false;
8263
8264 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8265 } finally {
8266 Binder.restoreCallingIdentity(identity);
8267 }
8268 }
8269
8270 @Override
8271 public boolean isDataAllowedInVoiceCall(int subId) {
8272 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8273
8274 // Now that all security checks passes, perform the operation as ourselves.
8275 final long identity = Binder.clearCallingIdentity();
8276 try {
8277 Phone phone = getPhone(subId);
8278 if (phone == null) return false;
8279
8280 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8281 } finally {
8282 Binder.restoreCallingIdentity(identity);
8283 }
8284 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008285
changbetty97defcf2019-12-24 15:40:37 +08008286 @Override
8287 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8288 enforceModifyPermission();
8289
8290 // Now that all security checks passes, perform the operation as ourselves.
8291 final long identity = Binder.clearCallingIdentity();
8292 try {
8293 Phone phone = getPhone(subId);
8294 if (phone == null) return false;
8295
8296 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8297 } finally {
8298 Binder.restoreCallingIdentity(identity);
8299 }
8300 }
8301
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008302 /**
8303 * Updates whether conference event pacakge handling is enabled.
8304 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8305 * otherwise.
8306 */
8307 @Override
8308 public void setCepEnabled(boolean isCepEnabled) {
8309 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8310
8311 final long identity = Binder.clearCallingIdentity();
8312 try {
8313 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8314 for (Phone phone : PhoneFactory.getPhones()) {
8315 Phone defaultPhone = phone.getImsPhone();
8316 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8317 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8318 ImsPhoneCallTracker imsPhoneCallTracker =
8319 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8320 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8321 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8322 + imsPhone.getMsisdn());
8323 }
8324 }
8325 } finally {
8326 Binder.restoreCallingIdentity(identity);
8327 }
8328 }
allenwtsu46dcc572020-01-08 18:24:03 +08008329
8330 /**
8331 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8332 *
8333 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8334 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8335 * before being read.
8336 */
8337 @Override
8338 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8339 isCompressed) {
8340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8341 mApp, subId, "notifyRcsAutoConfigurationReceived");
8342 try {
8343 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8344 if (configBinder == null) {
8345 Rlog.e(LOG_TAG, "null result for getImsConfig");
8346 } else {
8347 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8348 }
8349 } catch (RemoteException e) {
8350 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8351 }
8352 }
zoey chenf95ca592019-12-30 16:11:23 +08008353
8354 @Override
8355 public boolean isIccLockEnabled(int subId) {
8356 enforceReadPrivilegedPermission("isIccLockEnabled");
8357
8358 // Now that all security checks passes, perform the operation as ourselves.
8359 final long identity = Binder.clearCallingIdentity();
8360 try {
8361 Phone phone = getPhone(subId);
8362 if (phone != null && phone.getIccCard() != null) {
8363 return phone.getIccCard().getIccLockEnabled();
8364 } else {
8365 return false;
8366 }
8367 } finally {
8368 Binder.restoreCallingIdentity(identity);
8369 }
8370 }
8371
8372 /**
8373 * Set the ICC pin lock enabled or disabled..
8374 *
8375 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8376 * 0 or a positive integer as the attempts remaining value.
8377 *
8378 */
8379 @Override
8380 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8381 enforceModifyPermission();
8382
8383 Phone phone = getPhone(subId);
8384 if (phone == null) {
8385 return 0;
8386 }
8387 // Now that all security checks passes, perform the operation as ourselves.
8388 final long identity = Binder.clearCallingIdentity();
8389 try {
8390 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8391 new Pair<Boolean, String>(enabled, password), phone, null);
8392 return attemptsRemaining;
8393
8394 } catch (Exception e) {
8395 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
8398 }
8399 return 0;
8400 }
8401
8402 /**
8403 * Change the ICC password used in ICC pin lock.
8404 *
8405 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8406 * 0 or a positive integer as the attempts remaining value.
8407 *
8408 */
8409 @Override
8410 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8411 enforceModifyPermission();
8412
8413 Phone phone = getPhone(subId);
8414 if (phone == null) {
8415 return 0;
8416 }
8417 // Now that all security checks passes, perform the operation as ourselves.
8418 final long identity = Binder.clearCallingIdentity();
8419 try {
8420 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8421 new Pair<String, String>(oldPassword, newPassword), phone, null);
8422 return attemptsRemaining;
8423
8424 } catch (Exception e) {
8425 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8426 } finally {
8427 Binder.restoreCallingIdentity(identity);
8428 }
8429 return 0;
8430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008431}