blob: ffb4ec172a7d27a57fe0dbc124eed356cc8fff55 [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;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700133import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800134import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800136import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700137import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700138import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700141import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800142import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700143import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700144import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700145import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700146import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700147import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700148import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700149import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700150import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800151import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800152import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700153import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800154import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700155import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800156import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700157import com.android.internal.telephony.imsphone.ImsPhone;
158import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800159import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900160import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800162import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700165import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000169import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800170import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700171import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800172import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800175import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700176import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700177import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800178import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800179
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700180import java.io.FileDescriptor;
181import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800184import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800186import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100187import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800188import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700189import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800190import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191
192/**
193 * Implementation of the ITelephony interface.
194 */
Santos Cordon117fee72014-05-16 17:56:12 -0700195public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196 private static final String LOG_TAG = "PhoneInterfaceManager";
197 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
198 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800199 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200
201 // Message codes used with mMainThreadHandler
202 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700203 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
204 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700205 private static final int CMD_OPEN_CHANNEL = 9;
206 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
207 private static final int CMD_CLOSE_CHANNEL = 11;
208 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800209 private static final int CMD_NV_READ_ITEM = 13;
210 private static final int EVENT_NV_READ_ITEM_DONE = 14;
211 private static final int CMD_NV_WRITE_ITEM = 15;
212 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
213 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
214 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700215 private static final int CMD_RESET_MODEM_CONFIG = 19;
216 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800217 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
218 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
219 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
220 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800221 private static final int CMD_SEND_ENVELOPE = 25;
222 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000223 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
224 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700225 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
226 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
227 private static final int CMD_EXCHANGE_SIM_IO = 31;
228 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800229 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
230 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700231 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
232 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700233 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
234 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700235 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
236 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
237 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
238 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700239 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
240 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
241 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
242 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700243 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800244 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
245 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000246 private static final int CMD_SWITCH_SLOTS = 50;
247 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700248 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
249 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
250 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
251 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
252 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
253 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
254 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
255 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700256 private static final int CMD_GET_ALL_CELL_INFO = 60;
257 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
258 private static final int CMD_GET_CELL_LOCATION = 62;
259 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700260 private static final int CMD_MODEM_REBOOT = 64;
261 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700262 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
263 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800264 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
265 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700266 private static final int CMD_GET_MODEM_STATUS = 70;
267 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700268 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
269 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700270 private static final int CMD_ERASE_MODEM_CONFIG = 74;
271 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800272 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
273 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
274 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
275 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
sqian80370722020-01-29 15:02:51 -0800276 private static final int CMD_GET_CALL_FORWARDING = 83;
277 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
278 private static final int CMD_SET_CALL_FORWARDING = 85;
279 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
280 private static final int CMD_GET_CALL_WAITING = 87;
281 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
282 private static final int CMD_SET_CALL_WAITING = 89;
283 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800285 // Parameters of select command.
286 private static final int SELECT_COMMAND = 0xA4;
287 private static final int SELECT_P1 = 0x04;
288 private static final int SELECT_P2 = 0;
289 private static final int SELECT_P3 = 0x10;
290
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291 /** The singleton instance. */
292 private static PhoneInterfaceManager sInstance;
293
Wink Saville3ab207e2014-11-20 13:07:20 -0800294 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800295 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800296 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700297 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800298 private AppOpsManager mAppOps;
299 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800300 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800301 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700302 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303
Derek Tan97ebb422014-09-05 16:55:38 -0700304 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
305 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800306 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800307 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700308
Michelecea4cf22018-12-21 15:00:11 -0800309 // String to store multi SIM allowed
310 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
311
Derek Tan740e1672017-06-27 14:56:27 -0700312 // The AID of ISD-R.
313 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
314
yinxub1bed742017-04-17 11:45:04 -0700315 private NetworkScanRequestTracker mNetworkScanRequestTracker;
316
David Kelly5e06a7f2018-03-12 14:10:59 +0000317 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
318 private static final int MANUFACTURER_CODE_LENGTH = 8;
319
Derek Tan89e89d42014-07-08 17:00:10 -0700320 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700321 * Experiment flag to enable erase modem config on reset network, default value is false
322 */
323 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
324 "reset_network_erase_modem_config_enabled";
325
326 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700327 * A request object to use for transmitting data to an ICC.
328 */
329 private static final class IccAPDUArgument {
330 public int channel, cla, command, p1, p2, p3;
331 public String data;
332
333 public IccAPDUArgument(int channel, int cla, int command,
334 int p1, int p2, int p3, String data) {
335 this.channel = channel;
336 this.cla = cla;
337 this.command = command;
338 this.p1 = p1;
339 this.p2 = p2;
340 this.p3 = p3;
341 this.data = data;
342 }
343 }
344
345 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700346 * A request object to use for transmitting data to an ICC.
347 */
348 private static final class ManualNetworkSelectionArgument {
349 public OperatorInfo operatorInfo;
350 public boolean persistSelection;
351
352 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
353 this.operatorInfo = operatorInfo;
354 this.persistSelection = persistSelection;
355 }
356 }
357
358 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
360 * request after sending. The main thread will notify the request when it is complete.
361 */
362 private static final class MainThreadRequest {
363 /** The argument to use for the request */
364 public Object argument;
365 /** The result of the request that is run on the main thread */
366 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800367 // The subscriber id that this request applies to. Defaults to
368 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
369 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
Nathan Harold92bed182018-10-12 18:16:49 -0700371 // In cases where subId is unavailable, the caller needs to specify the phone.
372 public Phone phone;
373
vagdeviaf9a5b92018-08-15 16:01:53 -0700374 public WorkSource workSource;
375
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 public MainThreadRequest(Object argument) {
377 this.argument = argument;
378 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800379
Nathan Harold92bed182018-10-12 18:16:49 -0700380 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
381 this.argument = argument;
382 if (phone != null) {
383 this.phone = phone;
384 }
385 this.workSource = workSource;
386 }
387
vagdeviaf9a5b92018-08-15 16:01:53 -0700388 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800389 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800390 if (subId != null) {
391 this.subId = subId;
392 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700393 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800394 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 }
396
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800397 private static final class IncomingThirdPartyCallArgs {
398 public final ComponentName component;
399 public final String callId;
400 public final String callerDisplayName;
401
402 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
403 String callerDisplayName) {
404 this.component = component;
405 this.callId = callId;
406 this.callerDisplayName = callerDisplayName;
407 }
408 }
409
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 /**
411 * A handler that processes messages on the main thread in the phone process. Since many
412 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
413 * inbound binder threads to the main thread in the phone process. The Binder thread
414 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
415 * on, which will be notified when the operation completes and will contain the result of the
416 * request.
417 *
418 * <p>If a MainThreadRequest object is provided in the msg.obj field,
419 * note that request.result must be set to something non-null for the calling thread to
420 * unblock.
421 */
422 private final class MainThreadHandler extends Handler {
423 @Override
424 public void handleMessage(Message msg) {
425 MainThreadRequest request;
426 Message onCompleted;
427 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800428 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700429 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800430 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431
432 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700433 case CMD_HANDLE_USSD_REQUEST: {
434 request = (MainThreadRequest) msg.obj;
435 final Phone phone = getPhoneFromRequest(request);
436 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
437 String ussdRequest = ussdObject.first;
438 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700439
Pengquan Menga1bb6272018-09-06 09:59:22 -0700440 if (!isUssdApiAllowed(request.subId)) {
441 // Carrier does not support use of this API, return failure.
442 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
443 UssdResponse response = new UssdResponse(ussdRequest, null);
444 Bundle returnData = new Bundle();
445 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
446 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700447
Pengquan Menga1bb6272018-09-06 09:59:22 -0700448 request.result = true;
449 notifyRequester(request);
450 return;
451 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700452
Pengquan Menga1bb6272018-09-06 09:59:22 -0700453 try {
454 request.result = phone != null
455 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
456 } catch (CallStateException cse) {
457 request.result = false;
458 }
459 // Wake up the requesting thread
460 notifyRequester(request);
461 break;
pkanwar32d516d2016-10-14 19:37:38 -0700462 }
463
Yorke Lee716f67e2015-06-17 15:39:16 -0700464 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700465 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700466 final Phone phone = getPhoneFromRequest(request);
467 request.result = phone != null ?
468 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
469 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700471 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700475 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800478 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700479 if (uiccCard == null) {
480 loge("iccTransmitApduLogicalChannel: No UICC");
481 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700482 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700483 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
485 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700486 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 iccArgument.channel, iccArgument.cla, iccArgument.command,
488 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700490 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700491 break;
492
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 ar = (AsyncResult) msg.obj;
495 request = (MainThreadRequest) ar.userObj;
496 if (ar.exception == null && ar.result != null) {
497 request.result = ar.result;
498 } else {
499 request.result = new IccIoResult(0x6F, 0, (byte[])null);
500 if (ar.result == null) {
501 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800502 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800504 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 } else {
506 loge("iccTransmitApduLogicalChannel: Unknown exception");
507 }
508 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700509 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700510 break;
511
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700512 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
513 request = (MainThreadRequest) msg.obj;
514 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800515 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 if (uiccCard == null) {
517 loge("iccTransmitApduBasicChannel: No UICC");
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700520 } else {
521 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
522 request);
523 uiccCard.iccTransmitApduBasicChannel(
524 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
525 iccArgument.p3, iccArgument.data, onCompleted);
526 }
527 break;
528
529 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
530 ar = (AsyncResult) msg.obj;
531 request = (MainThreadRequest) ar.userObj;
532 if (ar.exception == null && ar.result != null) {
533 request.result = ar.result;
534 } else {
535 request.result = new IccIoResult(0x6F, 0, (byte[])null);
536 if (ar.result == null) {
537 loge("iccTransmitApduBasicChannel: Empty response");
538 } else if (ar.exception instanceof CommandException) {
539 loge("iccTransmitApduBasicChannel: CommandException: " +
540 ar.exception);
541 } else {
542 loge("iccTransmitApduBasicChannel: Unknown exception");
543 }
544 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700546 break;
547
548 case CMD_EXCHANGE_SIM_IO:
549 request = (MainThreadRequest) msg.obj;
550 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800551 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 if (uiccCard == null) {
553 loge("iccExchangeSimIO: No UICC");
554 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700555 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 } else {
557 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
558 request);
559 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
560 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
561 iccArgument.data, onCompleted);
562 }
563 break;
564
565 case EVENT_EXCHANGE_SIM_IO_DONE:
566 ar = (AsyncResult) msg.obj;
567 request = (MainThreadRequest) ar.userObj;
568 if (ar.exception == null && ar.result != null) {
569 request.result = ar.result;
570 } else {
571 request.result = new IccIoResult(0x6f, 0, (byte[])null);
572 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 break;
575
Derek Tan4d5e5c12014-02-04 11:54:58 -0800576 case CMD_SEND_ENVELOPE:
577 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800578 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 if (uiccCard == null) {
580 loge("sendEnvelopeWithStatus: No UICC");
581 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 } else {
584 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
585 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
586 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800587 break;
588
589 case EVENT_SEND_ENVELOPE_DONE:
590 ar = (AsyncResult) msg.obj;
591 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700592 if (ar.exception == null && ar.result != null) {
593 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800594 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700595 request.result = new IccIoResult(0x6F, 0, (byte[])null);
596 if (ar.result == null) {
597 loge("sendEnvelopeWithStatus: Empty response");
598 } else if (ar.exception instanceof CommandException) {
599 loge("sendEnvelopeWithStatus: CommandException: " +
600 ar.exception);
601 } else {
602 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
603 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800604 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700605 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800606 break;
607
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 case CMD_OPEN_CHANNEL:
609 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800610 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800611 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700612 if (uiccCard == null) {
613 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800614 request.result = new IccOpenLogicalChannelResponse(-1,
615 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700617 } else {
618 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800619 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
620 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700621 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 break;
623
624 case EVENT_OPEN_CHANNEL_DONE:
625 ar = (AsyncResult) msg.obj;
626 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 int[] result = (int[]) ar.result;
630 int channelId = result[0];
631 byte[] selectResponse = null;
632 if (result.length > 1) {
633 selectResponse = new byte[result.length - 1];
634 for (int i = 1; i < result.length; ++i) {
635 selectResponse[i - 1] = (byte) result[i];
636 }
637 }
638 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700639 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 if (ar.result == null) {
642 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 if (ar.exception != null) {
645 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
646 }
647
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700648 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700649 if (ar.exception instanceof CommandException) {
650 CommandException.Error error =
651 ((CommandException) (ar.exception)).getCommandError();
652 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700653 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700654 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700655 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 }
657 }
658 openChannelResp = new IccOpenLogicalChannelResponse(
659 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700661 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700662 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 break;
664
665 case CMD_CLOSE_CHANNEL:
666 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800667 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700668 if (uiccCard == null) {
669 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900670 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700671 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700672 } else {
673 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
674 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
675 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 break;
677
678 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800679 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
680 break;
681
682 case CMD_NV_READ_ITEM:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800685 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
686 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800687 break;
688
689 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 ar = (AsyncResult) msg.obj;
691 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800692 if (ar.exception == null && ar.result != null) {
693 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800695 request.result = "";
696 if (ar.result == null) {
697 loge("nvReadItem: Empty response");
698 } else if (ar.exception instanceof CommandException) {
699 loge("nvReadItem: CommandException: " +
700 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800702 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700703 }
704 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700705 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 break;
707
Jake Hambye994d462014-02-03 13:10:13 -0800708 case CMD_NV_WRITE_ITEM:
709 request = (MainThreadRequest) msg.obj;
710 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
711 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800712 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700713 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800714 break;
715
716 case EVENT_NV_WRITE_ITEM_DONE:
717 handleNullReturnEvent(msg, "nvWriteItem");
718 break;
719
720 case CMD_NV_WRITE_CDMA_PRL:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800723 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800724 break;
725
726 case EVENT_NV_WRITE_CDMA_PRL_DONE:
727 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
728 break;
729
chen xu6dac5ab2018-10-26 17:39:23 -0700730 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800731 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700732 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800733 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800734 break;
735
chen xu6dac5ab2018-10-26 17:39:23 -0700736 case EVENT_RESET_MODEM_CONFIG_DONE:
737 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800738 break;
739
Jake Hamby7c27be32014-03-03 13:25:59 -0800740 case CMD_GET_PREFERRED_NETWORK_TYPE:
741 request = (MainThreadRequest) msg.obj;
742 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700743 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800744 break;
745
746 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
747 ar = (AsyncResult) msg.obj;
748 request = (MainThreadRequest) ar.userObj;
749 if (ar.exception == null && ar.result != null) {
750 request.result = ar.result; // Integer
751 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800752 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800753 if (ar.result == null) {
754 loge("getPreferredNetworkType: Empty response");
755 } else if (ar.exception instanceof CommandException) {
756 loge("getPreferredNetworkType: CommandException: " +
757 ar.exception);
758 } else {
759 loge("getPreferredNetworkType: Unknown exception");
760 }
761 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700762 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800763 break;
764
765 case CMD_SET_PREFERRED_NETWORK_TYPE:
766 request = (MainThreadRequest) msg.obj;
767 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
768 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700769 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800770 break;
771
772 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
773 handleNullReturnEvent(msg, "setPreferredNetworkType");
774 break;
775
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000776 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
777 request = (MainThreadRequest)msg.obj;
778 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800779 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000780 break;
781
782 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
783 ar = (AsyncResult)msg.obj;
784 request = (MainThreadRequest)ar.userObj;
785 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700786 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000787 break;
788
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800789 case CMD_SET_VOICEMAIL_NUMBER:
790 request = (MainThreadRequest) msg.obj;
791 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
792 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800793 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
794 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800795 break;
796
797 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
798 handleNullReturnEvent(msg, "setVoicemailNumber");
799 break;
800
Stuart Scott54788802015-03-30 13:18:01 -0700801 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
804 request);
805 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
806 break;
807
808 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
809 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
810 break;
811
Shishir Agrawal302c8692015-06-19 13:49:39 -0700812 case CMD_PERFORM_NETWORK_SCAN:
813 request = (MainThreadRequest) msg.obj;
814 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
815 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
816 break;
817
sqian80370722020-01-29 15:02:51 -0800818 case CMD_GET_CALL_FORWARDING:
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
821 int callForwardingReason = (Integer) request.argument;
822 getPhoneFromRequest(request).getCallForwardingOption(
823 callForwardingReason, onCompleted);
824 break;
825
826 case EVENT_GET_CALL_FORWARDING_DONE:
827 ar = (AsyncResult) msg.obj;
828 request = (MainThreadRequest) ar.userObj;
829 CallForwardingInfo callForwardingInfo = null;
830 if (ar.exception == null && ar.result != null) {
831 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
832 for (CallForwardInfo callForwardInfo : callForwardInfos) {
833 // Service Class is a bit mask per 3gpp 27.007. Search for
834 // any service for voice call.
835 if ((callForwardInfo.serviceClass
836 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
837 callForwardingInfo = new CallForwardingInfo(
838 callForwardInfo.serviceClass, callForwardInfo.reason,
839 callForwardInfo.number,
840 callForwardInfo.timeSeconds);
841 break;
842 }
843 }
844 // Didn't find a call forward info for voice call.
845 if (callForwardingInfo == null) {
846 callForwardingInfo = new CallForwardingInfo(
847 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
848 0 /* reason */, null /* number */, 0 /* timeout */);
849 }
850 } else {
851 if (ar.result == null) {
852 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
853 }
854 if (ar.exception != null) {
855 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
856 }
857 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
858 if (ar.exception instanceof CommandException) {
859 CommandException.Error error =
860 ((CommandException) (ar.exception)).getCommandError();
861 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
862 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
863 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
864 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
865 }
866 }
867 callForwardingInfo = new CallForwardingInfo(
868 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
869 }
870 request.result = callForwardingInfo;
871 notifyRequester(request);
872 break;
873
874 case CMD_SET_CALL_FORWARDING:
875 request = (MainThreadRequest) msg.obj;
876 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
877 CallForwardingInfo callForwardingInfoToSet =
878 (CallForwardingInfo) request.argument;
879 getPhoneFromRequest(request).setCallForwardingOption(
880 callForwardingInfoToSet.getStatus(),
881 callForwardingInfoToSet.getReason(),
882 callForwardingInfoToSet.getNumber(),
883 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
884 break;
885
886 case EVENT_SET_CALL_FORWARDING_DONE:
887 ar = (AsyncResult) msg.obj;
888 request = (MainThreadRequest) ar.userObj;
889 if (ar.exception == null) {
890 request.result = true;
891 } else {
892 request.result = false;
893 loge("setCallForwarding exception: " + ar.exception);
894 }
895 notifyRequester(request);
896 break;
897
898 case CMD_GET_CALL_WAITING:
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
901 getPhoneFromRequest(request).getCallWaiting(onCompleted);
902 break;
903
904 case EVENT_GET_CALL_WAITING_DONE:
905 ar = (AsyncResult) msg.obj;
906 request = (MainThreadRequest) ar.userObj;
907 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
908 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800909 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -0800910 // Service Class is a bit mask per 3gpp 27.007.
911 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800912 if (callForwardResults.length > 1
913 && ((callForwardResults[1]
914 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
915 callForwardingStatus = callForwardResults[0] == 0
sqian80370722020-01-29 15:02:51 -0800916 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
917 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
918 } else {
919 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
920 }
921 } else {
922 if (ar.result == null) {
923 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
924 }
925 if (ar.exception != null) {
926 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
927 }
928 if (ar.exception instanceof CommandException) {
929 CommandException.Error error =
930 ((CommandException) (ar.exception)).getCommandError();
931 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
932 callForwardingStatus =
933 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
934 }
935 }
936 }
937 request.result = callForwardingStatus;
938 notifyRequester(request);
939 break;
940
941 case CMD_SET_CALL_WAITING:
942 request = (MainThreadRequest) msg.obj;
943 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
944 boolean isEnable = (Boolean) request.argument;
945 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
946 break;
947
948 case EVENT_SET_CALL_WAITING_DONE:
949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
951 if (ar.exception == null) {
952 request.result = true;
953 } else {
954 request.result = false;
955 loge("setCallWaiting exception: " + ar.exception);
956 }
957 notifyRequester(request);
958 break;
959
Shishir Agrawal302c8692015-06-19 13:49:39 -0700960 case EVENT_PERFORM_NETWORK_SCAN_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 CellNetworkScanResult cellScanResult;
964 if (ar.exception == null && ar.result != null) {
965 cellScanResult = new CellNetworkScanResult(
966 CellNetworkScanResult.STATUS_SUCCESS,
967 (List<OperatorInfo>) ar.result);
968 } else {
969 if (ar.result == null) {
970 loge("getCellNetworkScanResults: Empty response");
971 }
972 if (ar.exception != null) {
973 loge("getCellNetworkScanResults: Exception: " + ar.exception);
974 }
975 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
976 if (ar.exception instanceof CommandException) {
977 CommandException.Error error =
978 ((CommandException) (ar.exception)).getCommandError();
979 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
980 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
981 } else if (error == CommandException.Error.GENERIC_FAILURE) {
982 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
983 }
984 }
985 cellScanResult = new CellNetworkScanResult(errorCode, null);
986 }
987 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700988 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700989 break;
990
991 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
992 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700993 ManualNetworkSelectionArgument selArg =
994 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700995 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
996 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700997 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
998 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700999 break;
1000
1001 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
1004 if (ar.exception == null) {
1005 request.result = true;
1006 } else {
1007 request.result = false;
1008 loge("setNetworkSelectionModeManual " + ar.exception);
1009 }
1010 notifyRequester(request);
1011 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001012 break;
1013
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001014 case CMD_GET_MODEM_ACTIVITY_INFO:
1015 request = (MainThreadRequest) msg.obj;
1016 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001017 if (defaultPhone != null) {
1018 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001019 } else {
1020 ResultReceiver result = (ResultReceiver) request.argument;
1021 Bundle bundle = new Bundle();
1022 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1023 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1024 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001025 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001026 break;
1027
1028 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001031 ResultReceiver result = (ResultReceiver) request.argument;
1032
1033 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001034 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001035 // Update the last modem activity info and the result of the request.
1036 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1037 if (isModemActivityInfoValid(info)) {
1038 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1039 int[] txTimeMs = info.getTransmitTimeMillis();
1040 int[] lastModemTxTimeMs = mLastModemActivityInfo
1041 .getTransmitTimeMillis();
1042 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1043 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1044 }
1045 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1046 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1047 + mLastModemActivityInfo.getSleepTimeMillis());
1048 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1049 + mLastModemActivityInfo.getIdleTimeMillis());
1050 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1051 mLastModemActivityInfo.setReceiveTimeMillis(
1052 info.getReceiveTimeMillis()
1053 + mLastModemActivityInfo.getReceiveTimeMillis());
1054 }
1055 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1056 mLastModemActivityInfo.getSleepTimeMillis(),
1057 mLastModemActivityInfo.getIdleTimeMillis(),
1058 mLastModemActivityInfo.getTransmitTimeMillis(),
1059 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001060 } else {
1061 if (ar.result == null) {
1062 loge("queryModemActivityInfo: Empty response");
1063 } else if (ar.exception instanceof CommandException) {
1064 loge("queryModemActivityInfo: CommandException: " +
1065 ar.exception);
1066 } else {
1067 loge("queryModemActivityInfo: Unknown exception");
1068 }
1069 }
sqian1a1be542020-03-05 11:37:28 -08001070 Bundle bundle = new Bundle();
1071 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1072 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001073 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001074 break;
1075
Meng Wang1a7c35a2016-05-05 20:56:15 -07001076 case CMD_SET_ALLOWED_CARRIERS:
1077 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001078 CarrierRestrictionRules argument =
1079 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001080 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001081 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001082 break;
1083
1084 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1085 ar = (AsyncResult) msg.obj;
1086 request = (MainThreadRequest) ar.userObj;
1087 if (ar.exception == null && ar.result != null) {
1088 request.result = ar.result;
1089 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001090 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1091 if (ar.exception instanceof CommandException) {
1092 loge("setAllowedCarriers: CommandException: " + ar.exception);
1093 CommandException.Error error =
1094 ((CommandException) (ar.exception)).getCommandError();
1095 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1096 request.result =
1097 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1098 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001099 } else {
1100 loge("setAllowedCarriers: Unknown exception");
1101 }
1102 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001103 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001104 break;
1105
1106 case CMD_GET_ALLOWED_CARRIERS:
1107 request = (MainThreadRequest) msg.obj;
1108 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001109 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001110 break;
1111
1112 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1113 ar = (AsyncResult) msg.obj;
1114 request = (MainThreadRequest) ar.userObj;
1115 if (ar.exception == null && ar.result != null) {
1116 request.result = ar.result;
1117 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001118 request.result = new IllegalStateException(
1119 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001120 if (ar.result == null) {
1121 loge("getAllowedCarriers: Empty response");
1122 } else if (ar.exception instanceof CommandException) {
1123 loge("getAllowedCarriers: CommandException: " +
1124 ar.exception);
1125 } else {
1126 loge("getAllowedCarriers: Unknown exception");
1127 }
1128 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001129 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001130 break;
1131
Nathan Haroldb3014052017-01-25 15:57:32 -08001132 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1133 ar = (AsyncResult) msg.obj;
1134 request = (MainThreadRequest) ar.userObj;
1135 if (ar.exception == null && ar.result != null) {
1136 request.result = ar.result;
1137 } else {
1138 request.result = new IllegalArgumentException(
1139 "Failed to retrieve Forbidden Plmns");
1140 if (ar.result == null) {
1141 loge("getForbiddenPlmns: Empty response");
1142 } else {
1143 loge("getForbiddenPlmns: Unknown exception");
1144 }
1145 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001146 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001147 break;
1148
1149 case CMD_GET_FORBIDDEN_PLMNS:
1150 request = (MainThreadRequest) msg.obj;
1151 uiccCard = getUiccCardFromRequest(request);
1152 if (uiccCard == null) {
1153 loge("getForbiddenPlmns() UiccCard is null");
1154 request.result = new IllegalArgumentException(
1155 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001156 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001157 break;
1158 }
1159 Integer appType = (Integer) request.argument;
1160 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1161 if (uiccApp == null) {
1162 loge("getForbiddenPlmns() no app with specified type -- "
1163 + appType);
1164 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001165 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001166 break;
1167 } else {
1168 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1169 + " specified type -- " + appType);
1170 }
1171 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1172 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1173 onCompleted);
1174 break;
1175
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001176 case CMD_SWITCH_SLOTS:
1177 request = (MainThreadRequest) msg.obj;
1178 int[] physicalSlots = (int[]) request.argument;
1179 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1180 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1181 break;
1182
1183 case EVENT_SWITCH_SLOTS_DONE:
1184 ar = (AsyncResult) msg.obj;
1185 request = (MainThreadRequest) ar.userObj;
1186 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001187 notifyRequester(request);
1188 break;
1189 case CMD_GET_NETWORK_SELECTION_MODE:
1190 request = (MainThreadRequest) msg.obj;
1191 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1192 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1193 break;
1194
1195 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1196 ar = (AsyncResult) msg.obj;
1197 request = (MainThreadRequest) ar.userObj;
1198 if (ar.exception != null) {
1199 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1200 } else {
1201 int mode = ((int[]) ar.result)[0];
1202 if (mode == 0) {
1203 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1204 } else {
1205 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1206 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001207 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001208 notifyRequester(request);
1209 break;
1210 case CMD_GET_CDMA_ROAMING_MODE:
1211 request = (MainThreadRequest) msg.obj;
1212 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1213 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1214 break;
1215 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1216 ar = (AsyncResult) msg.obj;
1217 request = (MainThreadRequest) ar.userObj;
1218 if (ar.exception != null) {
1219 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1220 } else {
1221 request.result = ((int[]) ar.result)[0];
1222 }
1223 notifyRequester(request);
1224 break;
1225 case CMD_SET_CDMA_ROAMING_MODE:
1226 request = (MainThreadRequest) msg.obj;
1227 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1228 int mode = (int) request.argument;
1229 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1230 break;
1231 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1232 ar = (AsyncResult) msg.obj;
1233 request = (MainThreadRequest) ar.userObj;
1234 request.result = ar.exception == null;
1235 notifyRequester(request);
1236 break;
1237 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1238 request = (MainThreadRequest) msg.obj;
1239 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1240 int subscriptionMode = (int) request.argument;
1241 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1242 break;
1243 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1244 ar = (AsyncResult) msg.obj;
1245 request = (MainThreadRequest) ar.userObj;
1246 request.result = ar.exception == null;
1247 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001248 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001249 case CMD_GET_ALL_CELL_INFO:
1250 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001251 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001252 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001253 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001254 case EVENT_GET_ALL_CELL_INFO_DONE:
1255 ar = (AsyncResult) msg.obj;
1256 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001257 // If a timeout occurs, the response will be null
1258 request.result = (ar.exception == null && ar.result != null)
1259 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001260 synchronized (request) {
1261 request.notifyAll();
1262 }
1263 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001264 case CMD_REQUEST_CELL_INFO_UPDATE:
1265 request = (MainThreadRequest) msg.obj;
1266 request.phone.requestCellInfoUpdate(request.workSource,
1267 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1268 break;
1269 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1270 ar = (AsyncResult) msg.obj;
1271 request = (MainThreadRequest) ar.userObj;
1272 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1273 try {
1274 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001275 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001276 cb.onError(
1277 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1278 ar.exception.getClass().getName(),
1279 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001280 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001281 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001282 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001283 } else {
1284 // use the result as returned
1285 cb.onCellInfo((List<CellInfo>) ar.result);
1286 }
1287 } catch (RemoteException re) {
1288 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1289 }
1290 break;
1291 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001292 request = (MainThreadRequest) msg.obj;
1293 WorkSource ws = (WorkSource) request.argument;
1294 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001295 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001296 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001297 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001298 ar = (AsyncResult) msg.obj;
1299 request = (MainThreadRequest) ar.userObj;
1300 if (ar.exception == null) {
1301 request.result = ar.result;
1302 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001303 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001304 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001305 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001306 }
1307
1308 synchronized (request) {
1309 request.notifyAll();
1310 }
1311 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001312 case CMD_MODEM_REBOOT:
1313 request = (MainThreadRequest) msg.obj;
1314 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001315 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001316 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001317 case EVENT_CMD_MODEM_REBOOT_DONE:
1318 handleNullReturnEvent(msg, "rebootModem");
1319 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001320 case CMD_REQUEST_ENABLE_MODEM:
1321 request = (MainThreadRequest) msg.obj;
1322 boolean enable = (boolean) request.argument;
1323 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001324 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001325 PhoneConfigurationManager.getInstance()
1326 .enablePhone(request.phone, enable, onCompleted);
1327 break;
1328 case EVENT_ENABLE_MODEM_DONE:
1329 ar = (AsyncResult) msg.obj;
1330 request = (MainThreadRequest) ar.userObj;
1331 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001332 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001333 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001334 if ((boolean) request.result) {
1335 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1336 updateModemStateMetrics();
1337 } else {
1338 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1339 + ar.exception);
1340 }
1341 notifyRequester(request);
1342 break;
1343 case CMD_GET_MODEM_STATUS:
1344 request = (MainThreadRequest) msg.obj;
1345 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1346 PhoneConfigurationManager.getInstance()
1347 .getPhoneStatusFromModem(request.phone, onCompleted);
1348 break;
1349 case EVENT_GET_MODEM_STATUS_DONE:
1350 ar = (AsyncResult) msg.obj;
1351 request = (MainThreadRequest) ar.userObj;
1352 int id = request.phone.getPhoneId();
1353 if (ar.exception == null && ar.result != null) {
1354 request.result = ar.result;
1355 //update the cache as modem status has changed
1356 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1357 (boolean) request.result);
1358 } else {
1359 // Return true if modem status cannot be retrieved. For most cases,
1360 // modem status is on. And for older version modems, GET_MODEM_STATUS
1361 // and disable modem are not supported. Modem is always on.
1362 // TODO: this should be fixed in R to support a third
1363 // status UNKNOWN b/131631629
1364 request.result = true;
1365 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1366 + ar.exception);
1367 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001368 notifyRequester(request);
1369 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001370 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1371 ar = (AsyncResult) msg.obj;
1372 request = (MainThreadRequest) ar.userObj;
1373 if (ar.exception == null && ar.result != null) {
1374 request.result = ar.result;
1375 } else {
1376 request.result = -1;
1377 loge("Failed to set Forbidden Plmns");
1378 if (ar.result == null) {
1379 loge("setForbidenPlmns: Empty response");
1380 } else if (ar.exception != null) {
1381 loge("setForbiddenPlmns: Exception: " + ar.exception);
1382 request.result = -1;
1383 } else {
1384 loge("setForbiddenPlmns: Unknown exception");
1385 }
1386 }
1387 notifyRequester(request);
1388 break;
1389 case CMD_SET_FORBIDDEN_PLMNS:
1390 request = (MainThreadRequest) msg.obj;
1391 uiccCard = getUiccCardFromRequest(request);
1392 if (uiccCard == null) {
1393 loge("setForbiddenPlmns: UiccCard is null");
1394 request.result = -1;
1395 notifyRequester(request);
1396 break;
1397 }
1398 Pair<Integer, List<String>> setFplmnsArgs =
1399 (Pair<Integer, List<String>>) request.argument;
1400 appType = setFplmnsArgs.first;
1401 List<String> fplmns = setFplmnsArgs.second;
1402 uiccApp = uiccCard.getApplicationByType(appType);
1403 if (uiccApp == null) {
1404 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1405 request.result = -1;
1406 loge("Failed to get UICC App");
1407 notifyRequester(request);
1408 } else {
1409 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1410 ((SIMRecords) uiccApp.getIccRecords())
1411 .setForbiddenPlmns(onCompleted, fplmns);
1412 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001413 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001414 case CMD_ERASE_MODEM_CONFIG:
1415 request = (MainThreadRequest) msg.obj;
1416 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1417 defaultPhone.eraseModemConfig(onCompleted);
1418 break;
1419 case EVENT_ERASE_MODEM_CONFIG_DONE:
1420 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001421 break;
zoey chenf95ca592019-12-30 16:11:23 +08001422
1423 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1424 request = (MainThreadRequest) msg.obj;
1425 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1426 Pair<String, String> changed = (Pair<String, String>) request.argument;
1427 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1428 changed.first, changed.second, onCompleted);
1429 break;
1430 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1431 ar = (AsyncResult) msg.obj;
1432 request = (MainThreadRequest) ar.userObj;
1433 if (ar.exception == null) {
1434 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1435 } else {
1436 request.result = msg.arg1;
1437 }
1438 notifyRequester(request);
1439 break;
1440
1441 case CMD_SET_ICC_LOCK_ENABLED:
1442 request = (MainThreadRequest) msg.obj;
1443 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1444 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1445 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1446 enabled.first, enabled.second, onCompleted);
1447 break;
1448 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
1451 if (ar.exception == null) {
1452 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1453 } else {
1454 request.result = msg.arg1;
1455 }
1456 notifyRequester(request);
1457 break;
1458
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 default:
1460 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1461 break;
1462 }
1463 }
Jake Hambye994d462014-02-03 13:10:13 -08001464
Pengquan Menga1bb6272018-09-06 09:59:22 -07001465 private void notifyRequester(MainThreadRequest request) {
1466 synchronized (request) {
1467 request.notifyAll();
1468 }
1469 }
1470
Jake Hambye994d462014-02-03 13:10:13 -08001471 private void handleNullReturnEvent(Message msg, String command) {
1472 AsyncResult ar = (AsyncResult) msg.obj;
1473 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1474 if (ar.exception == null) {
1475 request.result = true;
1476 } else {
1477 request.result = false;
1478 if (ar.exception instanceof CommandException) {
1479 loge(command + ": CommandException: " + ar.exception);
1480 } else {
1481 loge(command + ": Unknown exception");
1482 }
1483 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001484 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486 }
1487
1488 /**
1489 * Posts the specified command to be executed on the main thread,
1490 * waits for the request to complete, and returns the result.
1491 * @see #sendRequestAsync
1492 */
1493 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001494 return sendRequest(
1495 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001496 }
1497
1498 /**
1499 * Posts the specified command to be executed on the main thread,
1500 * waits for the request to complete, and returns the result.
1501 * @see #sendRequestAsync
1502 */
1503 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1504 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001505 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001506 }
1507
1508 /**
1509 * Posts the specified command to be executed on the main thread,
1510 * waits for the request to complete, and returns the result.
1511 * @see #sendRequestAsync
1512 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001513 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001514 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001515 }
1516
1517 /**
1518 * Posts the specified command to be executed on the main thread,
1519 * waits for the request to complete, and returns the result.
1520 * @see #sendRequestAsync
1521 */
Nathan Harold92bed182018-10-12 18:16:49 -07001522 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1523 return sendRequest(command, argument, subId, null, workSource);
1524 }
1525
1526 /**
1527 * Posts the specified command to be executed on the main thread,
1528 * waits for the request to complete, and returns the result.
1529 * @see #sendRequestAsync
1530 */
1531 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1532 return sendRequest(
1533 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1534 }
1535
1536 /**
1537 * Posts the specified command to be executed on the main thread,
1538 * waits for the request to complete, and returns the result.
1539 * @see #sendRequestAsync
1540 */
1541 private Object sendRequest(
1542 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1544 throw new RuntimeException("This method will deadlock if called from the main thread.");
1545 }
1546
Nathan Harold92bed182018-10-12 18:16:49 -07001547 MainThreadRequest request = null;
1548 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1549 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1550 } else if (phone != null) {
1551 request = new MainThreadRequest(argument, phone, workSource);
1552 } else {
1553 request = new MainThreadRequest(argument, subId, workSource);
1554 }
1555
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 Message msg = mMainThreadHandler.obtainMessage(command, request);
1557 msg.sendToTarget();
1558
1559 // Wait for the request to complete
1560 synchronized (request) {
1561 while (request.result == null) {
1562 try {
1563 request.wait();
1564 } catch (InterruptedException e) {
1565 // Do nothing, go back and wait until the request is complete
1566 }
1567 }
1568 }
1569 return request.result;
1570 }
1571
1572 /**
1573 * Asynchronous ("fire and forget") version of sendRequest():
1574 * Posts the specified command to be executed on the main thread, and
1575 * returns immediately.
1576 * @see #sendRequest
1577 */
1578 private void sendRequestAsync(int command) {
1579 mMainThreadHandler.sendEmptyMessage(command);
1580 }
1581
1582 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001583 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001584 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001585 */
1586 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001587 sendRequestAsync(command, argument, null, null);
1588 }
1589
1590 /**
1591 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1592 * @see {@link #sendRequest(int,Object)}
1593 */
1594 private void sendRequestAsync(
1595 int command, Object argument, Phone phone, WorkSource workSource) {
1596 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001597 Message msg = mMainThreadHandler.obtainMessage(command, request);
1598 msg.sendToTarget();
1599 }
1600
1601 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001602 * Initialize the singleton PhoneInterfaceManager instance.
1603 * This is only done once, at startup, from PhoneApp.onCreate().
1604 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001605 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 synchronized (PhoneInterfaceManager.class) {
1607 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001608 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 } else {
1610 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1611 }
1612 return sInstance;
1613 }
1614 }
1615
1616 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001617 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001619 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001620 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001621 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1623 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001624 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001625 mTelephonySharedPreferences =
1626 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001627 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001628 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001629
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 publish();
1631 }
1632
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001633 private Phone getDefaultPhone() {
1634 Phone thePhone = getPhone(getDefaultSubscription());
1635 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1636 }
1637
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 private void publish() {
1639 if (DBG) log("publish: " + this);
1640
1641 ServiceManager.addService("phone", this);
1642 }
1643
Stuart Scott584921c2015-01-15 17:10:34 -08001644 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001645 if (request.phone != null) {
1646 return request.phone;
1647 } else {
1648 return getPhoneFromSubId(request.subId);
1649 }
1650 }
1651
1652 private Phone getPhoneFromSubId(int subId) {
1653 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1654 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001655 }
1656
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001657 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1658 Phone phone = getPhoneFromRequest(request);
1659 return phone == null ? null :
1660 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1661 }
1662
Wink Saville36469e72014-06-11 15:17:00 -07001663 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001664 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001665 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001668 private void sendEraseModemConfig(Phone phone) {
1669 if (phone != null) {
1670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1671 mApp, phone.getSubId(), "eraseModemConfig");
1672 final long identity = Binder.clearCallingIdentity();
1673 try {
1674 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1675 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1676 } finally {
1677 Binder.restoreCallingIdentity(identity);
1678 }
1679 }
1680 }
1681
Peter Wang050bb052020-01-13 23:33:09 -08001682 private boolean isImsAvailableOnDevice() {
1683 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1684 if (pm == null) {
1685 // For some reason package manger is not available.. This will fail internally anyway,
1686 // so do not throw error and allow.
1687 return true;
1688 }
1689 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1690 }
1691
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001693 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001694 }
1695
Wink Savilleb564aae2014-10-23 10:18:09 -07001696 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 if (DBG) log("dial: " + number);
1698 // No permission check needed here: This is just a wrapper around the
1699 // ACTION_DIAL intent, which is available to any app since it puts up
1700 // the UI before it does anything.
1701
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001702 final long identity = Binder.clearCallingIdentity();
1703 try {
1704 String url = createTelUrl(number);
1705 if (url == null) {
1706 return;
1707 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001709 // PENDING: should we just silently fail if phone is offhook or ringing?
1710 PhoneConstants.State state = mCM.getState(subId);
1711 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1712 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1713 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1714 mApp.startActivity(intent);
1715 }
1716 } finally {
1717 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 }
1719 }
1720
1721 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001722 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001723 }
1724
Wink Savilleb564aae2014-10-23 10:18:09 -07001725 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 if (DBG) log("call: " + number);
1727
1728 // This is just a wrapper around the ACTION_CALL intent, but we still
1729 // need to do a permission check since we're calling startActivity()
1730 // from the context of the phone app.
1731 enforceCallPermission();
1732
Jordan Liu1617b712019-07-10 15:06:26 -07001733 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 != AppOpsManager.MODE_ALLOWED) {
1735 return;
1736 }
1737
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001738 final long identity = Binder.clearCallingIdentity();
1739 try {
1740 String url = createTelUrl(number);
1741 if (url == null) {
1742 return;
1743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001745 boolean isValid = false;
1746 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1747 if (slist != null) {
1748 for (SubscriptionInfo subInfoRecord : slist) {
1749 if (subInfoRecord.getSubscriptionId() == subId) {
1750 isValid = true;
1751 break;
1752 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001753 }
Wink Saville08874612014-08-31 19:19:58 -07001754 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001755 if (!isValid) {
1756 return;
1757 }
Wink Saville08874612014-08-31 19:19:58 -07001758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001759 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1760 intent.putExtra(SUBSCRIPTION_KEY, subId);
1761 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1762 mApp.startActivity(intent);
1763 } finally {
1764 Binder.restoreCallingIdentity(identity);
1765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 }
1767
Wink Savilleb564aae2014-10-23 10:18:09 -07001768 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001769 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001770 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1771 }
1772
Wink Savilleb564aae2014-10-23 10:18:09 -07001773 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001774 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001775 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1776 }
1777
Wink Savilleb564aae2014-10-23 10:18:09 -07001778 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001780
1781 final long identity = Binder.clearCallingIdentity();
1782 try {
1783 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1784 checkSimPin.start();
1785 return checkSimPin.unlockSim(null, pin);
1786 } finally {
1787 Binder.restoreCallingIdentity(identity);
1788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
1790
Wink Savilleb564aae2014-10-23 10:18:09 -07001791 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001793
1794 final long identity = Binder.clearCallingIdentity();
1795 try {
1796 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1797 checkSimPuk.start();
1798 return checkSimPuk.unlockSim(puk, pin);
1799 } finally {
1800 Binder.restoreCallingIdentity(identity);
1801 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001802 }
1803
1804 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001805 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 * a synchronous one.
1807 */
1808 private static class UnlockSim extends Thread {
1809
1810 private final IccCard mSimCard;
1811
1812 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001813 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1814 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815
1816 // For replies from SimCard interface
1817 private Handler mHandler;
1818
1819 // For async handler to identify request type
1820 private static final int SUPPLY_PIN_COMPLETE = 100;
1821
1822 public UnlockSim(IccCard simCard) {
1823 mSimCard = simCard;
1824 }
1825
1826 @Override
1827 public void run() {
1828 Looper.prepare();
1829 synchronized (UnlockSim.this) {
1830 mHandler = new Handler() {
1831 @Override
1832 public void handleMessage(Message msg) {
1833 AsyncResult ar = (AsyncResult) msg.obj;
1834 switch (msg.what) {
1835 case SUPPLY_PIN_COMPLETE:
1836 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1837 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001838 mRetryCount = msg.arg1;
1839 if (ar.exception != null) {
1840 if (ar.exception instanceof CommandException &&
1841 ((CommandException)(ar.exception)).getCommandError()
1842 == CommandException.Error.PASSWORD_INCORRECT) {
1843 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1844 } else {
1845 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1846 }
1847 } else {
1848 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 mDone = true;
1851 UnlockSim.this.notifyAll();
1852 }
1853 break;
1854 }
1855 }
1856 };
1857 UnlockSim.this.notifyAll();
1858 }
1859 Looper.loop();
1860 }
1861
1862 /*
1863 * Use PIN or PUK to unlock SIM card
1864 *
1865 * If PUK is null, unlock SIM card with PIN
1866 *
1867 * If PUK is not null, unlock SIM card with PUK and set PIN code
1868 */
Wink Saville9de0f752013-10-22 19:04:03 -07001869 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870
1871 while (mHandler == null) {
1872 try {
1873 wait();
1874 } catch (InterruptedException e) {
1875 Thread.currentThread().interrupt();
1876 }
1877 }
1878 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1879
1880 if (puk == null) {
1881 mSimCard.supplyPin(pin, callback);
1882 } else {
1883 mSimCard.supplyPuk(puk, pin, callback);
1884 }
1885
1886 while (!mDone) {
1887 try {
1888 Log.d(LOG_TAG, "wait for done");
1889 wait();
1890 } catch (InterruptedException e) {
1891 // Restore the interrupted status
1892 Thread.currentThread().interrupt();
1893 }
1894 }
1895 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001896 int[] resultArray = new int[2];
1897 resultArray[0] = mResult;
1898 resultArray[1] = mRetryCount;
1899 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001900 }
1901 }
1902
1903 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001904 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001905
1906 }
1907
Wink Savilleb564aae2014-10-23 10:18:09 -07001908 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 // No permission check needed here: this call is harmless, and it's
1910 // needed for the ServiceState.requestStateUpdate() call (which is
1911 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001912 final long identity = Binder.clearCallingIdentity();
1913 try {
1914 final Phone phone = getPhone(subId);
1915 if (phone != null) {
1916 phone.updateServiceLocation();
1917 }
1918 } finally {
1919 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 }
1922
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001923 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001924 @Override
1925 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001926 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001927 }
1928
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001929 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001930 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1931 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1932 callingFeatureId);
1933 }
1934
1935 @Deprecated
1936 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001937 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001938 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1939 }
1940
1941 @Override
1942 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1943 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001945 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001946 return false;
1947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001948
1949 final long identity = Binder.clearCallingIdentity();
1950 try {
1951 return isRadioOnForSubscriber(subId);
1952 } finally {
1953 Binder.restoreCallingIdentity(identity);
1954 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001955 }
1956
1957 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001958 final long identity = Binder.clearCallingIdentity();
1959 try {
1960 final Phone phone = getPhone(subId);
1961 if (phone != null) {
1962 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1963 } else {
1964 return false;
1965 }
1966 } finally {
1967 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001968 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 }
1970
1971 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001972 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 }
Wink Saville36469e72014-06-11 15:17:00 -07001974
Wink Savilleb564aae2014-10-23 10:18:09 -07001975 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001977
1978 final long identity = Binder.clearCallingIdentity();
1979 try {
1980 final Phone phone = getPhone(subId);
1981 if (phone != null) {
1982 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1983 }
1984 } finally {
1985 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001986 }
Wink Saville36469e72014-06-11 15:17:00 -07001987 }
1988
1989 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001990 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001991 }
1992
Wink Savilleb564aae2014-10-23 10:18:09 -07001993 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001994 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001995
1996 final long identity = Binder.clearCallingIdentity();
1997 try {
1998 final Phone phone = getPhone(subId);
1999 if (phone == null) {
2000 return false;
2001 }
2002 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2003 toggleRadioOnOffForSubscriber(subId);
2004 }
2005 return true;
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
Wink Saville36469e72014-06-11 15:17:00 -07002010
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002011 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002012 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002013 /*
2014 * If any of the Radios are available, it will need to be
2015 * shutdown. So return true if any Radio is available.
2016 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002017 final long identity = Binder.clearCallingIdentity();
2018 try {
2019 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2020 Phone phone = PhoneFactory.getPhone(i);
2021 if (phone != null && phone.isRadioAvailable()) return true;
2022 }
2023 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2024 return false;
2025 } finally {
2026 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002027 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002028 }
2029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002030 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002031 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002032 enforceModifyPermission();
2033
2034 final long identity = Binder.clearCallingIdentity();
2035 try {
2036 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2037 logv("Shutting down Phone " + i);
2038 shutdownRadioUsingPhoneId(i);
2039 }
2040 } finally {
2041 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002042 }
2043 }
2044
2045 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002046 Phone phone = PhoneFactory.getPhone(phoneId);
2047 if (phone != null && phone.isRadioAvailable()) {
2048 phone.shutdownRadio();
2049 }
2050 }
2051
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002052 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002053 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054
2055 final long identity = Binder.clearCallingIdentity();
2056 try {
2057 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2058 if (defaultPhone != null) {
2059 defaultPhone.setRadioPower(turnOn);
2060 return true;
2061 } else {
2062 loge("There's no default phone.");
2063 return false;
2064 }
2065 } finally {
2066 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002067 }
Wink Saville36469e72014-06-11 15:17:00 -07002068 }
2069
Wink Savilleb564aae2014-10-23 10:18:09 -07002070 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072
2073 final long identity = Binder.clearCallingIdentity();
2074 try {
2075 final Phone phone = getPhone(subId);
2076 if (phone != null) {
2077 phone.setRadioPower(turnOn);
2078 return true;
2079 } else {
2080 return false;
2081 }
2082 } finally {
2083 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002084 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 }
2086
Wink Saville36469e72014-06-11 15:17:00 -07002087 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002088 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 public boolean enableDataConnectivity() {
2090 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002091
2092 final long identity = Binder.clearCallingIdentity();
2093 try {
2094 int subId = mSubscriptionController.getDefaultDataSubId();
2095 final Phone phone = getPhone(subId);
2096 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002097 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002098 return true;
2099 } else {
2100 return false;
2101 }
2102 } finally {
2103 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105 }
2106
Wink Saville36469e72014-06-11 15:17:00 -07002107 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002108 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 public boolean disableDataConnectivity() {
2110 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002111
2112 final long identity = Binder.clearCallingIdentity();
2113 try {
2114 int subId = mSubscriptionController.getDefaultDataSubId();
2115 final Phone phone = getPhone(subId);
2116 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002117 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002118 return true;
2119 } else {
2120 return false;
2121 }
2122 } finally {
2123 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002124 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002125 }
2126
Sanket Padawe356d7632015-06-22 14:03:32 -07002127 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002128 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002129 final long identity = Binder.clearCallingIdentity();
2130 try {
2131 final Phone phone = getPhone(subId);
2132 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002133 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002134 } else {
2135 return false;
2136 }
2137 } finally {
2138 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002139 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140 }
2141
2142 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002143 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002144 }
2145
pkanwarae03a6b2016-11-06 20:37:09 -08002146 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002147 enforceCallPermission();
2148
2149 final long identity = Binder.clearCallingIdentity();
2150 try {
2151 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2152 return;
2153 }
2154 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2155 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2156 } finally {
2157 Binder.restoreCallingIdentity(identity);
2158 }
pkanwar32d516d2016-10-14 19:37:38 -07002159 };
2160
Wink Savilleb564aae2014-10-23 10:18:09 -07002161 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002163
2164 final long identity = Binder.clearCallingIdentity();
2165 try {
2166 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2167 return false;
2168 }
2169 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2170 } finally {
2171 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 }
2174
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002176 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002177 }
2178
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002179 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002180 final long identity = Binder.clearCallingIdentity();
2181 try {
2182 Phone phone = PhoneFactory.getPhone(slotIndex);
2183 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2184 PhoneConstantConversions.convertCallState(phone.getState());
2185 } finally {
2186 Binder.restoreCallingIdentity(identity);
2187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 }
2189
Sanket Padawe356d7632015-06-22 14:03:32 -07002190 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002191 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002192 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2193 }
2194
2195 @Override
2196 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002197 final long identity = Binder.clearCallingIdentity();
2198 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002199 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002200 if (phone != null) {
2201 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2202 } else {
2203 return PhoneConstantConversions.convertDataState(
2204 PhoneConstants.DataState.DISCONNECTED);
2205 }
2206 } finally {
2207 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002208 }
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 getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002213 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2214 }
2215
2216 @Override
2217 public int getDataActivityForSubId(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 DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2223 } else {
2224 return TelephonyManager.DATA_ACTIVITY_NONE;
2225 }
2226 } finally {
2227 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 }
2230
2231 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002232 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002233 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002234 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002235
2236 LocationAccessPolicy.LocationPermissionResult locationResult =
2237 LocationAccessPolicy.checkLocationPermission(mApp,
2238 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2239 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002240 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002241 .setCallingPid(Binder.getCallingPid())
2242 .setCallingUid(Binder.getCallingUid())
2243 .setMethod("getCellLocation")
2244 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2245 .build());
2246 switch (locationResult) {
2247 case DENIED_HARD:
2248 throw new SecurityException("Not allowed to access cell location");
2249 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002250 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2251 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 }
2253
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002254 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002255 final long identity = Binder.clearCallingIdentity();
2256 try {
2257 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002258 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002259 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260 } finally {
2261 Binder.restoreCallingIdentity(identity);
2262 }
Svetoslav64fad262015-04-14 14:35:21 -07002263 }
2264
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002266 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2267 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002268 if (!TextUtils.isEmpty(callingPackage)) {
2269 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2271 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002272 return "";
2273 }
2274 }
2275
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002276 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2277 // registered cell info, so return a NULL country instead.
2278 final long identity = Binder.clearCallingIdentity();
2279 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002280 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2281 // Get default phone in this case.
2282 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2283 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002284 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002285 // Todo: fix this when we can get the actual cellular network info when the device
2286 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002287 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002288 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2289 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002290 return "";
2291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292 Phone phone = PhoneFactory.getPhone(phoneId);
2293 if (phone != null) {
2294 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002295 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002296 if (sst != null) {
2297 LocaleTracker lt = sst.getLocaleTracker();
2298 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002299 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2300 return lt.getCurrentCountry();
2301 } else if (emergencyNumberTracker != null) {
2302 return emergencyNumberTracker.getEmergencyCountryIso();
2303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002304 }
2305 }
2306 }
2307 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002308 } finally {
2309 Binder.restoreCallingIdentity(identity);
2310 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002311 }
2312
2313 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002315 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002316 }
2317
Sanket Padawe356d7632015-06-22 14:03:32 -07002318 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002319 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 mApp.enforceCallingOrSelfPermission(
2321 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002322
2323 final long identity = Binder.clearCallingIdentity();
2324 try {
2325 final Phone phone = getPhone(subId);
2326 if (phone != null) {
2327 phone.enableLocationUpdates();
2328 }
2329 } finally {
2330 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 }
2333
2334 @Override
2335 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002336 disableLocationUpdatesForSubscriber(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 disableLocationUpdatesForSubscriber(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.disableLocationUpdates();
2349 }
2350 } finally {
2351 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 }
2354
Nathan Harold31d7ff32018-10-15 20:20:30 -07002355 /**
2356 * Returns the target SDK version number for a given package name.
2357 *
Nathan Haroldec184742019-07-10 17:04:16 -07002358 * This call MUST be invoked before clearing the calling UID.
2359 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002360 * @return target SDK if the package is found or INT_MAX.
2361 */
2362 private int getTargetSdk(String packageName) {
2363 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002364 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002365 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002366 if (ai != null) return ai.targetSdkVersion;
2367 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002368 loge("Failed to get package info for pkg="
2369 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002370 }
2371 return Integer.MAX_VALUE;
2372 }
2373
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 @Override
2375 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002376 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2377 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002378 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002379 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2380 throw new SecurityException(
2381 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2382 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002383
Jordan Liu1617b712019-07-10 15:06:26 -07002384 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2386 return null;
2387 }
Svetoslav64fad262015-04-14 14:35:21 -07002388
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002389 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002391 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002392 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393
Nathan Haroldf180aac2018-06-01 18:43:55 -07002394 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2395 for (CellInfo ci : info) {
2396 if (ci instanceof CellInfoGsm) {
2397 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2398 } else if (ci instanceof CellInfoWcdma) {
2399 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002402 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 }
2404
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002405 private List<CellInfo> getCachedCellInfo() {
2406 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2407 for (Phone phone : PhoneFactory.getPhones()) {
2408 List<CellInfo> info = phone.getAllCellInfo();
2409 if (info != null) cellInfos.addAll(info);
2410 }
2411 return cellInfos;
2412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413
2414 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002415 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002416 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002417 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002418
2419 LocationAccessPolicy.LocationPermissionResult locationResult =
2420 LocationAccessPolicy.checkLocationPermission(mApp,
2421 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2422 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002423 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002424 .setCallingPid(Binder.getCallingPid())
2425 .setCallingUid(Binder.getCallingUid())
2426 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002427 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002428 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2429 .build());
2430 switch (locationResult) {
2431 case DENIED_HARD:
2432 throw new SecurityException("Not allowed to access cell info");
2433 case DENIED_SOFT:
2434 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 }
2436
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002437 final int targetSdk = getTargetSdk(callingPackage);
2438 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2439 return getCachedCellInfo();
2440 }
2441
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002442 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002443 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002444 final long identity = Binder.clearCallingIdentity();
2445 try {
2446 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2447 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002448 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002449 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002450 if (info != null) cellInfos.addAll(info);
2451 }
2452 return cellInfos;
2453 } finally {
2454 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 }
2456 }
2457
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002458 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002459 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2460 String callingFeatureId) {
2461 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2462 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002463 }
2464
2465 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002466 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2467 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002468 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002469 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002470 }
2471
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002472 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2473 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002474 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002475 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002476
2477 LocationAccessPolicy.LocationPermissionResult locationResult =
2478 LocationAccessPolicy.checkLocationPermission(mApp,
2479 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2480 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002481 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002482 .setCallingPid(Binder.getCallingPid())
2483 .setCallingUid(Binder.getCallingUid())
2484 .setMethod("requestCellInfoUpdate")
2485 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2486 .build());
2487 switch (locationResult) {
2488 case DENIED_HARD:
2489 throw new SecurityException("Not allowed to access cell info");
2490 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002491 try {
2492 cb.onCellInfo(new ArrayList<CellInfo>());
2493 } catch (RemoteException re) {
2494 // Drop without consequences
2495 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002496 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002497 }
2498
Nathan Harolda939a962019-05-09 10:13:47 -07002499
2500 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002501 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2502
2503 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2504 }
2505
2506 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002508 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002509 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510
2511 final long identity = Binder.clearCallingIdentity();
2512 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002513 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002514 } finally {
2515 Binder.restoreCallingIdentity(identity);
2516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
Shishir Agrawala9f32182016-04-12 12:00:16 -07002519 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002520 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002521 Phone phone = PhoneFactory.getPhone(slotIndex);
2522 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002523 return null;
2524 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002525 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002526 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002527 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002528 return null;
2529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530
2531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 return phone.getImei();
2534 } finally {
2535 Binder.restoreCallingIdentity(identity);
2536 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002537 }
2538
2539 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002540 public String getTypeAllocationCodeForSlot(int slotIndex) {
2541 Phone phone = PhoneFactory.getPhone(slotIndex);
2542 String tac = null;
2543 if (phone != null) {
2544 String imei = phone.getImei();
2545 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2546 }
2547 return tac;
2548 }
2549
2550 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002551 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002552 Phone phone = PhoneFactory.getPhone(slotIndex);
2553 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002554 return null;
2555 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002556
Jeff Davidson913390f2018-02-23 17:11:49 -08002557 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002558 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002559 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002560 return null;
2561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562
2563 final long identity = Binder.clearCallingIdentity();
2564 try {
2565 return phone.getMeid();
2566 } finally {
2567 Binder.restoreCallingIdentity(identity);
2568 }
Jack Yu2af8d712017-03-15 17:14:14 -07002569 }
2570
2571 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002572 public String getManufacturerCodeForSlot(int slotIndex) {
2573 Phone phone = PhoneFactory.getPhone(slotIndex);
2574 String manufacturerCode = null;
2575 if (phone != null) {
2576 String meid = phone.getMeid();
2577 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2578 }
2579 return manufacturerCode;
2580 }
2581
2582 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002583 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2584 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002585 Phone phone = PhoneFactory.getPhone(slotIndex);
2586 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002587 return null;
2588 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002589 int subId = phone.getSubId();
2590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002591 mApp, subId, callingPackage, callingFeatureId,
2592 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002593 return null;
2594 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595
2596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 return phone.getDeviceSvn();
2599 } finally {
2600 Binder.restoreCallingIdentity(identity);
2601 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002602 }
2603
fionaxu43304da2017-11-27 22:51:16 -08002604 @Override
2605 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606 final long identity = Binder.clearCallingIdentity();
2607 try {
2608 final Phone phone = getPhone(subId);
2609 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2610 } finally {
2611 Binder.restoreCallingIdentity(identity);
2612 }
fionaxu43304da2017-11-27 22:51:16 -08002613 }
2614
2615 @Override
2616 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617 final long identity = Binder.clearCallingIdentity();
2618 try {
2619 final Phone phone = getPhone(subId);
2620 return phone == null ? null : phone.getCarrierName();
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
2623 }
fionaxu43304da2017-11-27 22:51:16 -08002624 }
2625
calvinpanffe225e2018-11-01 19:43:06 +08002626 @Override
chen xu0026ca62019-03-06 15:28:50 -08002627 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002628 final long identity = Binder.clearCallingIdentity();
2629 try {
2630 final Phone phone = getPhone(subId);
2631 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002632 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
2636 }
2637
2638 @Override
chen xu0026ca62019-03-06 15:28:50 -08002639 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002640 final long identity = Binder.clearCallingIdentity();
2641 try {
2642 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002643 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002644 } finally {
2645 Binder.restoreCallingIdentity(identity);
2646 }
2647 }
2648
chen xu651eec72018-11-11 19:03:44 -08002649 @Override
chen xu864e11c2018-12-06 22:10:03 -08002650 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2651 if (!isSubscriptionMccMnc) {
2652 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2653 }
chen xu651eec72018-11-11 19:03:44 -08002654 final Phone phone = PhoneFactory.getPhone(slotIndex);
2655 if (phone == null) {
2656 return TelephonyManager.UNKNOWN_CARRIER_ID;
2657 }
2658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
2663 }
2664 }
2665
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 //
2667 // Internal helper methods.
2668 //
2669
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002670 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002671 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2672 *
2673 * @throws SecurityException if the caller does not have the required permission
2674 */
2675 private void enforceModifyPermission() {
2676 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2677 }
2678
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002679 /**
2680 * Make sure the caller is system.
2681 *
2682 * @throws SecurityException if the caller is not system.
2683 */
2684 private void enforceSystemCaller() {
2685 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2686 throw new SecurityException("Caller must be system");
2687 }
2688 }
2689
Shuo Qianf2b2df42019-11-13 17:43:31 -08002690 private void enforceActiveEmergencySessionPermission() {
2691 mApp.enforceCallingOrSelfPermission(
2692 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2693 }
2694
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 /**
2696 * Make sure the caller has the CALL_PHONE permission.
2697 *
2698 * @throws SecurityException if the caller does not have the required permission
2699 */
2700 private void enforceCallPermission() {
2701 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2702 }
2703
paulhu423b5f22019-08-23 19:17:33 +08002704 private void enforceSettingsPermission() {
2705 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002706 }
2707
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 private String createTelUrl(String number) {
2709 if (TextUtils.isEmpty(number)) {
2710 return null;
2711 }
2712
Jake Hambye994d462014-02-03 13:10:13 -08002713 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
2715
Ihab Awadf9e92732013-12-05 18:02:52 -08002716 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2718 }
2719
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002720 private static void logv(String msg) {
2721 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2722 }
2723
Ihab Awadf9e92732013-12-05 18:02:52 -08002724 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2726 }
2727
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002728 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002730 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002731 }
2732
Sanket Padawe356d7632015-06-22 14:03:32 -07002733 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002734 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 final long identity = Binder.clearCallingIdentity();
2736 try {
2737 final Phone phone = PhoneFactory.getPhone(slotIndex);
2738 if (phone == null) {
2739 return PhoneConstants.PHONE_TYPE_NONE;
2740 } else {
2741 return phone.getPhoneType();
2742 }
2743 } finally {
2744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 }
2747
2748 /**
2749 * Returns the CDMA ERI icon index to display
2750 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002751 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002752 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2753 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2754 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002755 }
2756
Sanket Padawe356d7632015-06-22 14:03:32 -07002757 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002758 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2759 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002761 mApp, subId, callingPackage, callingFeatureId,
2762 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002763 return -1;
2764 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765
2766 final long identity = Binder.clearCallingIdentity();
2767 try {
2768 final Phone phone = getPhone(subId);
2769 if (phone != null) {
2770 return phone.getCdmaEriIconIndex();
2771 } else {
2772 return -1;
2773 }
2774 } finally {
2775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 }
2778
2779 /**
2780 * Returns the CDMA ERI icon mode,
2781 * 0 - ON
2782 * 1 - FLASHING
2783 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002784 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002785 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2786 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2787 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002788 }
2789
Sanket Padawe356d7632015-06-22 14:03:32 -07002790 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002791 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2792 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002793 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002794 mApp, subId, callingPackage, callingFeatureId,
2795 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002796 return -1;
2797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 final Phone phone = getPhone(subId);
2802 if (phone != null) {
2803 return phone.getCdmaEriIconMode();
2804 } else {
2805 return -1;
2806 }
2807 } finally {
2808 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002810 }
2811
2812 /**
2813 * Returns the CDMA ERI text,
2814 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002815 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002816 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2817 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2818 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002819 }
2820
Sanket Padawe356d7632015-06-22 14:03:32 -07002821 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002822 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2823 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002825 mApp, subId, callingPackage, callingFeatureId,
2826 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002827 return null;
2828 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829
2830 final long identity = Binder.clearCallingIdentity();
2831 try {
2832 final Phone phone = getPhone(subId);
2833 if (phone != null) {
2834 return phone.getCdmaEriText();
2835 } else {
2836 return null;
2837 }
2838 } finally {
2839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 }
2842
2843 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002844 * Returns the CDMA MDN.
2845 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002847 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2849 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850
2851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002854 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002855 return phone.getLine1Number();
2856 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002857 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 return null;
2859 }
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002862 }
2863 }
2864
2865 /**
2866 * Returns the CDMA MIN.
2867 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002868 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002869 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2871 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872
2873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 final Phone phone = getPhone(subId);
2876 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2877 return phone.getCdmaMin();
2878 } else {
2879 return null;
2880 }
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002883 }
2884 }
2885
Hall Liud892bec2018-11-30 14:51:45 -08002886 @Override
2887 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2888 INumberVerificationCallback callback, String callingPackage) {
2889 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2890 != PERMISSION_GRANTED) {
2891 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2892 }
2893 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2894
2895 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2896 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2897 throw new SecurityException("Calling package must be configured in the device config");
2898 }
2899
2900 if (range == null) {
2901 throw new NullPointerException("Range must be non-null");
2902 }
2903
2904 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002905 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002906
2907 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2908 }
2909
Junda Liuca05d5d2014-08-14 22:36:34 -07002910 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002911 * Returns true if CDMA provisioning needs to run.
2912 */
2913 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002914 final long identity = Binder.clearCallingIdentity();
2915 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002916 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917 } finally {
2918 Binder.restoreCallingIdentity(identity);
2919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 }
2921
2922 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002923 * Sets the voice mail number of a given subId.
2924 */
2925 @Override
2926 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002927 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2928 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2933 new Pair<String, String>(alphaTag, number), new Integer(subId));
2934 return success;
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
2937 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002938 }
2939
Ta-wei Yen87c49842016-05-13 21:19:52 -07002940 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002941 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2942 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002943 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2944 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002945 if (!TextUtils.equals(callingPackage, systemDialer)) {
2946 throw new SecurityException("caller must be system dialer");
2947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948
2949 final long identity = Binder.clearCallingIdentity();
2950 try {
2951 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2952 if (phoneAccountHandle == null) {
2953 return null;
2954 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002955 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956 } finally {
2957 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002958 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002959 }
2960
2961 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002962 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2963 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002964 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002965 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002966 mApp, subId, callingPackage, callingFeatureId,
2967 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002968 return null;
2969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002970
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002971 final long identity = Binder.clearCallingIdentity();
2972 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002973 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002974 } finally {
2975 Binder.restoreCallingIdentity(identity);
2976 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002977 }
2978
2979 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002980 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2981 VisualVoicemailSmsFilterSettings settings) {
2982 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002987 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002988 } finally {
2989 Binder.restoreCallingIdentity(identity);
2990 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002991 }
2992
2993 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002994 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2995 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996
2997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003000 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 } finally {
3002 Binder.restoreCallingIdentity(identity);
3003 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003004 }
3005
3006 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003007 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3008 String callingPackage, int subId) {
3009 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003010
3011 final long identity = Binder.clearCallingIdentity();
3012 try {
3013 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003014 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 } finally {
3016 Binder.restoreCallingIdentity(identity);
3017 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003018 }
3019
3020 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003021 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003022 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023
3024 final long identity = Binder.clearCallingIdentity();
3025 try {
3026 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003027 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003031 }
3032
3033 @Override
3034 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3035 String number, int port, String text, PendingIntent sentIntent) {
3036 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003037 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003038 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003039 SmsController smsController = PhoneFactory.getSmsController();
3040 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3041 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003042 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003043
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003044 /**
fionaxu0152e512016-11-14 13:36:14 -08003045 * Sets the voice activation state of a given subId.
3046 */
3047 @Override
3048 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3050 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051
3052 final long identity = Binder.clearCallingIdentity();
3053 try {
3054 final Phone phone = getPhone(subId);
3055 if (phone != null) {
3056 phone.setVoiceActivationState(activationState);
3057 } else {
3058 loge("setVoiceActivationState fails with invalid subId: " + subId);
3059 }
3060 } finally {
3061 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003062 }
3063 }
3064
3065 /**
3066 * Sets the data activation state of a given subId.
3067 */
3068 @Override
3069 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3071 mApp, subId, "setDataActivationState");
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.setDataActivationState(activationState);
3078 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003079 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080 }
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003083 }
3084 }
3085
3086 /**
3087 * Returns the voice activation state of a given subId.
3088 */
3089 @Override
3090 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003091 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003092
fionaxu0152e512016-11-14 13:36:14 -08003093 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003094 final long identity = Binder.clearCallingIdentity();
3095 try {
3096 if (phone != null) {
3097 return phone.getVoiceActivationState();
3098 } else {
3099 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3100 }
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003103 }
3104 }
3105
3106 /**
3107 * Returns the data activation state of a given subId.
3108 */
3109 @Override
3110 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003111 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112
fionaxu0152e512016-11-14 13:36:14 -08003113 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 if (phone != null) {
3117 return phone.getDataActivationState();
3118 } else {
3119 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3120 }
3121 } finally {
3122 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003123 }
3124 }
3125
3126 /**
Wink Saville36469e72014-06-11 15:17:00 -07003127 * Returns the unread count of voicemails for a subId
3128 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003129 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003130 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3131 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003133 mApp, subId, callingPackage, callingFeatureId,
3134 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003135 return 0;
3136 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 final Phone phone = getPhone(subId);
3140 if (phone != null) {
3141 return phone.getVoiceMessageCount();
3142 } else {
3143 return 0;
3144 }
3145 } finally {
3146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 }
3149
3150 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003151 * returns true, if the device is in a state where both voice and data
3152 * are supported simultaneously. This can change based on location or network condition.
3153 */
3154 @Override
3155 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156 final long identity = Binder.clearCallingIdentity();
3157 try {
3158 final Phone phone = getPhone(subId);
3159 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3160 } finally {
3161 Binder.restoreCallingIdentity(identity);
3162 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003163 }
3164
3165 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003166 * Send the dialer code if called from the current default dialer or the caller has
3167 * carrier privilege.
3168 * @param inputCode The dialer code to send
3169 */
3170 @Override
3171 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003172 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003173 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003174 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3175 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003176 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003177 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003178 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003180
3181 final long identity = Binder.clearCallingIdentity();
3182 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003183 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184 } finally {
3185 Binder.restoreCallingIdentity(identity);
3186 }
fionaxu235cc5e2017-03-06 22:25:57 -08003187 }
3188
Pengquan Menga1bb6272018-09-06 09:59:22 -07003189 @Override
3190 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003191 TelephonyPermissions
3192 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3193 mApp, subId, "getNetworkSelectionMode");
3194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 if (!isActiveSubscription(subId)) {
3197 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3198 }
3199 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3200 } finally {
3201 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003202 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003203 }
3204
Brad Ebinger35c841c2018-10-01 10:40:55 -07003205 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003206 public boolean isInEmergencySmsMode() {
3207 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 for (Phone phone : PhoneFactory.getPhones()) {
3211 if (phone.isInEmergencySmsMode()) {
3212 return true;
3213 }
3214 }
3215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
3218 return false;
3219 }
3220
shilu366312e2019-12-17 09:28:10 -08003221 /**
3222 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3223 * @param subId The subscription to use to check the configuration.
3224 * @param c The callback that will be used to send the result.
3225 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003226 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003227 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3228 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003229 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3230 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003231
Brad Ebinger77b832e2019-10-17 17:03:22 -07003232 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3233 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3234 "IMS not available on device.");
3235 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003236 final long token = Binder.clearCallingIdentity();
3237 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003238 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003239 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003241 } catch (ImsException e) {
3242 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003243 } finally {
3244 Binder.restoreCallingIdentity(token);
3245 }
3246 }
3247
shilu366312e2019-12-17 09:28:10 -08003248 /**
3249 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3250 * @param subId The subscription to use to check the configuration.
3251 * @param c The callback that will be used to send the result.
3252 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003253 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003254 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003255 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3256 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003257 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3258 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3259 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003260 final long token = Binder.clearCallingIdentity();
3261 try {
3262 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3263 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3264 .removeRegistrationCallbackForSubscription(c, subId);
3265 } catch (ImsException e) {
3266 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3267 + "is inactive, ignoring unregister.");
3268 // If the subscription is no longer active, just return, since the callback
3269 // will already have been removed internally.
3270 } finally {
3271 Binder.restoreCallingIdentity(token);
3272 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 }
3274
Brad Ebinger774ba362019-10-22 17:36:18 -07003275 /**
3276 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3277 */
3278 @Override
3279 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3280 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3281 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3282 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3283 "IMS not available on device.");
3284 }
3285 final long token = Binder.clearCallingIdentity();
3286 try {
3287 Phone phone = getPhone(subId);
3288 if (phone == null) {
3289 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3290 + subId + "'");
3291 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3292 }
3293 phone.getImsRegistrationState(regState -> {
3294 try {
3295 consumer.accept((regState == null)
3296 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3297 } catch (RemoteException e) {
3298 // Ignore if the remote process is no longer available to call back.
3299 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3300 }
3301 });
3302 } finally {
3303 Binder.restoreCallingIdentity(token);
3304 }
3305 }
3306
3307 /**
3308 * Get the transport type for the IMS service registration state.
3309 */
3310 @Override
3311 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003312 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3313 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003314 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3315 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3316 "IMS not available on device.");
3317 }
3318 final long token = Binder.clearCallingIdentity();
3319 try {
3320 Phone phone = getPhone(subId);
3321 if (phone == null) {
3322 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3323 + subId + "'");
3324 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3325 }
3326 phone.getImsRegistrationTech(regTech -> {
3327 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3328 int regTechConverted = (regTech == null)
3329 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3330 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3331 regTechConverted);
3332 try {
3333 consumer.accept(regTechConverted);
3334 } catch (RemoteException e) {
3335 // Ignore if the remote process is no longer available to call back.
3336 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3337 }
3338 });
3339 } finally {
3340 Binder.restoreCallingIdentity(token);
3341 }
3342 }
3343
shilu366312e2019-12-17 09:28:10 -08003344 /**
3345 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3346 * @param subId The subscription to use to check the configuration.
3347 * @param c The callback that will be used to send the result.
3348 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003350 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3351 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003352 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3353 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003354 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3355 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3356 "IMS not available on device.");
3357 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003358 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3359 final long token = Binder.clearCallingIdentity();
3360 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003361 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003362 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003363 } catch (ImsException e) {
3364 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 } finally {
3366 Binder.restoreCallingIdentity(token);
3367 }
3368 }
3369
shilu366312e2019-12-17 09:28:10 -08003370 /**
3371 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3372 * @param subId The subscription to use to check the configuration.
3373 * @param c The callback that will be used to send the result.
3374 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003375 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003376 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003377 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3378 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003379 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3380 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3381 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003382
3383 final long token = Binder.clearCallingIdentity();
3384 try {
3385 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3386 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003387 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003388 } catch (ImsException e) {
3389 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3390 + "is inactive, ignoring unregister.");
3391 // If the subscription is no longer active, just return, since the callback
3392 // will already have been removed internally.
3393 } finally {
3394 Binder.restoreCallingIdentity(token);
3395 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003396 }
3397
3398 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003399 public boolean isCapable(int subId, int capability, int regTech) {
3400 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003401 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3402 final long token = Binder.clearCallingIdentity();
3403 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003404 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003405 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003406 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003407 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3408 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003409 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003410 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3411 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003412 } finally {
3413 Binder.restoreCallingIdentity(token);
3414 }
3415 }
3416
3417 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003418 public boolean isAvailable(int subId, int capability, int regTech) {
3419 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003420 final long token = Binder.clearCallingIdentity();
3421 try {
3422 Phone phone = getPhone(subId);
3423 if (phone == null) return false;
3424 return phone.isImsCapabilityAvailable(capability, regTech);
3425 } finally {
3426 Binder.restoreCallingIdentity(token);
3427 }
3428 }
3429
Brad Ebinger77b832e2019-10-17 17:03:22 -07003430 /**
3431 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3432 * subscription.
3433 * @param subId The subscription to use to check the configuration.
3434 * @param callback The callback that will be used to send the result.
3435 * @param capability The MmTelFeature capability that will be used to send the result.
3436 * @param transportType The transport type of the MmTelFeature capability.
3437 */
3438 @Override
3439 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3440 int transportType) {
3441 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3442 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3443 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3444 "IMS not available on device.");
3445 }
3446 final long token = Binder.clearCallingIdentity();
3447 try {
3448 int slotId = getSlotIndex(subId);
3449 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3450 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3451 + subId + "'");
3452 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3453 }
3454 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3455 transportType, aBoolean -> {
3456 try {
3457 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3458 } catch (RemoteException e) {
3459 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3460 + "running. Ignore");
3461 }
3462 });
3463 } finally {
3464 Binder.restoreCallingIdentity(token);
3465 }
3466 }
3467
shilu366312e2019-12-17 09:28:10 -08003468 /**
3469 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3470 * @param subId The subscription to use to check the configuration.
3471 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003472 @Override
3473 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003474 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3475 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003476
Brad Ebinger35c841c2018-10-01 10:40:55 -07003477 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3478 final long token = Binder.clearCallingIdentity();
3479 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003480 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003481 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003482 } catch (ImsException e) {
3483 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003484 } finally {
3485 Binder.restoreCallingIdentity(token);
3486 }
3487 }
3488
3489 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003490 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003492 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003496 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003497 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003498 } catch (ImsException e) {
3499 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003500 } finally {
3501 Binder.restoreCallingIdentity(identity);
3502 }
3503 }
3504
shilu366312e2019-12-17 09:28:10 -08003505 /**
3506 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3507 * @param subId The subscription to use to check the configuration.
3508 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003509 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003510 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003511 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3512 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 final long identity = Binder.clearCallingIdentity();
3514 try {
3515 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003516 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3517 } catch (ImsException e) {
3518 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003519 } finally {
3520 Binder.restoreCallingIdentity(identity);
3521 }
3522 }
3523
3524 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003525 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003527 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003528 final long identity = Binder.clearCallingIdentity();
3529 try {
3530 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003531 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003532 } catch (ImsException e) {
3533 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003534 } finally {
3535 Binder.restoreCallingIdentity(identity);
3536 }
3537 }
3538
shilu366312e2019-12-17 09:28:10 -08003539 /**
3540 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3541 * @param subId The subscription to use to check the configuration.
3542 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003543 @Override
3544 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003545 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3546 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003550 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003551 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003552 } catch (ImsException e) {
3553 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003554 } finally {
3555 Binder.restoreCallingIdentity(identity);
3556 }
3557 }
3558
3559 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003560 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003562 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003566 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003567 } catch (ImsException e) {
3568 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003569 } finally {
3570 Binder.restoreCallingIdentity(identity);
3571 }
3572 }
3573
shilu366312e2019-12-17 09:28:10 -08003574 /**
3575 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3576 * @param subId The subscription to use to check the configuration.
3577 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003578 @Override
3579 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003580 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3581 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003585 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003586 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003587 } catch (ImsException e) {
3588 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003589 } finally {
3590 Binder.restoreCallingIdentity(identity);
3591 }
3592 }
3593
3594 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003595 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003597 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003601 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003603 } catch (ImsException e) {
3604 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003605 } finally {
3606 Binder.restoreCallingIdentity(identity);
3607 }
3608 }
3609
3610 @Override
3611 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3613 "setVoWiFiNonPersistent");
3614 final long identity = Binder.clearCallingIdentity();
3615 try {
3616 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003617 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003618 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003619 } catch (ImsException e) {
3620 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003621 } finally {
3622 Binder.restoreCallingIdentity(identity);
3623 }
3624 }
3625
shilu366312e2019-12-17 09:28:10 -08003626 /**
3627 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3628 * @param subId The subscription to use to check the configuration.
3629 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003630 @Override
3631 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003632 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3633 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003637 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003638 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003639 } catch (ImsException e) {
3640 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003641 } finally {
3642 Binder.restoreCallingIdentity(identity);
3643 }
3644 }
3645
3646 @Override
3647 public void setVoWiFiModeSetting(int subId, int mode) {
3648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3649 "setVoWiFiModeSetting");
3650 final long identity = Binder.clearCallingIdentity();
3651 try {
3652 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003653 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003654 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003655 } catch (ImsException e) {
3656 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
3660 }
3661
3662 @Override
3663 public int getVoWiFiRoamingModeSetting(int subId) {
3664 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003668 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003669 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003670 } catch (ImsException e) {
3671 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003672 } finally {
3673 Binder.restoreCallingIdentity(identity);
3674 }
3675 }
3676
3677 @Override
3678 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3680 "setVoWiFiRoamingModeSetting");
3681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003684 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003685 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003686 } catch (ImsException e) {
3687 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003688 } finally {
3689 Binder.restoreCallingIdentity(identity);
3690 }
3691 }
3692
3693 @Override
3694 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3696 "setRttCapabilityEnabled");
3697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003700 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3701 } catch (ImsException e) {
3702 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003703 } finally {
3704 Binder.restoreCallingIdentity(identity);
3705 }
3706 }
3707
shilu366312e2019-12-17 09:28:10 -08003708 /**
3709 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3710 * @param subId The subscription to use to check the configuration.
3711 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003712 @Override
3713 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003714 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3715 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003719 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003721 } catch (ImsException e) {
3722 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003723 } finally {
3724 Binder.restoreCallingIdentity(identity);
3725 }
3726 }
3727
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003728 @Override
3729 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3730 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3731 final long identity = Binder.clearCallingIdentity();
3732 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003733 if (!isImsAvailableOnDevice()) {
3734 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3735 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003736 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003737 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003738 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003739 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003740 } catch (ImsException e) {
3741 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003742 } finally {
3743 Binder.restoreCallingIdentity(identity);
3744 }
3745 }
3746
3747 @Override
3748 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3749 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3750 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003751 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3752 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3753 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003754 try {
3755 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003756 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003757 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003758 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003759 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3760 + "is inactive, ignoring unregister.");
3761 // If the subscription is no longer active, just return, since the callback will already
3762 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003763 } finally {
3764 Binder.restoreCallingIdentity(identity);
3765 }
3766 }
3767
allenwtsu99c623b2020-01-03 18:24:23 +08003768
3769 private void checkModifyPhoneStatePermission(int subId, String message) {
3770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3771 message);
3772 }
3773
3774 private boolean isImsProvisioningRequired(int subId, int capability,
3775 boolean isMmtelCapability) {
3776 Phone phone = getPhone(subId);
3777 if (phone == null) {
3778 loge("phone instance null for subid " + subId);
3779 return false;
3780 }
3781 if (isMmtelCapability) {
3782 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3783 return false;
3784 }
3785 } else {
3786 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3787 return false;
3788 }
3789 }
3790 return true;
3791 }
3792
3793 @Override
3794 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3795 boolean isProvisioned) {
3796 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3797
3798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3801 if (!isImsProvisioningRequired(subId, capability, false)) {
3802 return;
3803 }
3804
3805 // this capability requires provisioning, route to the correct API.
3806 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3807 switch (capability) {
3808 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3809 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3810 ims.setEabProvisioned(isProvisioned);
3811 break;
3812 default: {
3813 throw new IllegalArgumentException("Tried to set provisioning for "
3814 + "rcs capability '" + capability + "', which does not require "
3815 + "provisioning.");
3816 }
3817 }
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
3820 }
3821
3822 }
3823
3824
3825 @Override
3826 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3827 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3828 final long identity = Binder.clearCallingIdentity();
3829 try {
3830 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3831 if (!isImsProvisioningRequired(subId, capability, false)) {
3832 return true;
3833 }
3834
3835 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3836 switch (capability) {
3837 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3838 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3839 return ims.isEabProvisionedOnDevice();
3840
3841 default: {
3842 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3843 + "capability '" + capability + "', which does not require "
3844 + "provisioning.");
3845 }
3846 }
3847
3848 } finally {
3849 Binder.restoreCallingIdentity(identity);
3850 }
3851 }
3852
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003853 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003854 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3855 boolean isProvisioned) {
3856 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3857 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3858 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3859 }
allenwtsu99c623b2020-01-03 18:24:23 +08003860 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003864 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003865 return;
3866 }
3867
3868 // this capability requires provisioning, route to the correct API.
3869 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3870 switch (capability) {
3871 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3872 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3873 ims.setVolteProvisioned(isProvisioned);
3874 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3875 ims.setWfcProvisioned(isProvisioned);
3876 }
3877 break;
3878 }
3879 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3880 // There is currently no difference in VT provisioning type.
3881 ims.setVtProvisioned(isProvisioned);
3882 break;
3883 }
3884 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3885 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3886 // change the capability of the feature instead if needed.
3887 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3888 == isProvisioned) {
3889 // No change in provisioning.
3890 return;
3891 }
3892 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3893 try {
3894 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003895 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003896 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3897 + ", Exception" + e.getMessage());
3898 }
3899 break;
3900 }
3901 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003902 throw new IllegalArgumentException("Tried to set provisioning for "
3903 + "MmTel capability '" + capability + "', which does not require "
3904 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003905 }
3906 }
3907
3908 } finally {
3909 Binder.restoreCallingIdentity(identity);
3910 }
3911 }
3912
3913 @Override
3914 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3915 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3916 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3917 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3918 }
3919 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003923 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003924 return true;
3925 }
3926
3927 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3928 switch (capability) {
3929 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3930 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3931 return ims.isVolteProvisionedOnDevice();
3932 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3933 return ims.isWfcProvisionedOnDevice();
3934 }
3935 // This should never happen, since we are checking tech above to make sure it
3936 // is either LTE or IWLAN.
3937 throw new IllegalArgumentException("Invalid radio technology for voice "
3938 + "capability.");
3939 }
3940 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3941 // There is currently no difference in VT provisioning type.
3942 return ims.isVtProvisionedOnDevice();
3943 }
3944 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3945 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3946 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3947 }
3948 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003949 throw new IllegalArgumentException(
3950 "Tried to get provisioning for MmTel capability '" + capability
3951 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003952 }
3953 }
3954
3955 } finally {
3956 Binder.restoreCallingIdentity(identity);
3957 }
3958 }
3959
3960 @Override
3961 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3962 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3963 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3964 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3965 }
3966 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3967 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3968 return (provisionedBits & capability) > 0;
3969 }
3970
3971 @Override
3972 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3973 boolean isProvisioned) {
3974 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3975 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3976 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3977 }
3978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3979 "setProvisioningStatusForCapability");
3980 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3981 // If the current provisioning status for capability already matches isProvisioned,
3982 // do nothing.
3983 if (((provisionedBits & capability) > 0) == isProvisioned) {
3984 return;
3985 }
3986 if (isProvisioned) {
3987 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3988 } else {
3989 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3990 }
3991 }
3992
3993 /**
3994 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3995 * technology. The bitfield should mirror the bitfield defined by
3996 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3997 */
3998 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3999 String key = getMmTelProvisioningKey(subId, tech);
4000 // Default is no capabilities are provisioned.
4001 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4002 }
4003
4004 /**
4005 * Sets the MmTel capability provisioning bitfield (defined by
4006 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4007 * technology specified.
4008 *
4009 * Note: This is a synchronous command and should not be called on UI thread.
4010 */
4011 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4012 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4013 String key = getMmTelProvisioningKey(subId, tech);
4014 editor.putInt(key, newField);
4015 editor.commit();
4016 }
4017
4018 private static String getMmTelProvisioningKey(int subId, int tech) {
4019 // resulting key is provision_ims_mmtel_{subId}_{tech}
4020 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4021 }
4022
4023 /**
4024 * Query CarrierConfig to see if the specified capability requires provisioning for the
4025 * carrier associated with the subscription id.
4026 */
4027 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4028 int capability) {
4029 CarrierConfigManager configManager = new CarrierConfigManager(context);
4030 PersistableBundle c = configManager.getConfigForSubId(subId);
4031 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004032 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004033 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4034 false);
4035 boolean requireVoiceVtProvisioning = c.getBoolean(
4036 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4037
4038 // First check to make sure that the capability requires provisioning.
4039 switch (capability) {
4040 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4041 // intentional fallthrough
4042 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4043 if (requireVoiceVtProvisioning) {
4044 // Voice and Video requires provisioning
4045 return true;
4046 }
4047 break;
4048 }
4049 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4050 if (requireUtProvisioning) {
4051 // UT requires provisioning
4052 return true;
4053 }
4054 break;
4055 }
4056 }
4057 return false;
4058 }
4059
allenwtsu99c623b2020-01-03 18:24:23 +08004060 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4061 int capability) {
4062 CarrierConfigManager configManager = new CarrierConfigManager(context);
4063 PersistableBundle c = configManager.getConfigForSubId(subId);
4064
4065 boolean requireRcsProvisioning = c.getBoolean(
4066 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4067
4068 // First check to make sure that the capability requires provisioning.
4069 switch (capability) {
4070 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4071 // intentional fallthrough
4072 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4073 if (requireRcsProvisioning) {
4074 // OPTION or PRESENCE requires provisioning
4075 return true;
4076 }
4077 break;
4078 }
4079 }
4080 return false;
4081 }
4082
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004083 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004084 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004085 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4086 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4087 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004088 enforceReadPrivilegedPermission("getImsProvisioningInt");
4089 final long identity = Binder.clearCallingIdentity();
4090 try {
4091 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004092 int slotId = getSlotIndex(subId);
4093 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4094 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4095 + subId + "' for key:" + key);
4096 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4097 }
4098 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004099 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004100 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4101 + subId + "' for key:" + key);
4102 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004103 } finally {
4104 Binder.restoreCallingIdentity(identity);
4105 }
4106 }
4107
4108 @Override
4109 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004110 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4111 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4112 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004113 enforceReadPrivilegedPermission("getImsProvisioningString");
4114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004117 int slotId = getSlotIndex(subId);
4118 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4119 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4120 + subId + "' for key:" + key);
4121 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4122 }
4123 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004124 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004125 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4126 + subId + "' for key:" + key);
4127 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004128 } finally {
4129 Binder.restoreCallingIdentity(identity);
4130 }
4131 }
4132
4133 @Override
4134 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004135 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4136 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4137 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4139 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004140 final long identity = Binder.clearCallingIdentity();
4141 try {
4142 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004143 int slotId = getSlotIndex(subId);
4144 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4145 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4146 + subId + "' for key:" + key);
4147 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4148 }
4149 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004150 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004151 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4152 + "' for key:" + key);
4153 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004154 } finally {
4155 Binder.restoreCallingIdentity(identity);
4156 }
4157 }
4158
4159 @Override
4160 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004161 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4162 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4163 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4165 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004169 int slotId = getSlotIndex(subId);
4170 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4171 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4172 + subId + "' for key:" + key);
4173 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4174 }
4175 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004176 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004177 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4178 + "' for key:" + key);
4179 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004180 } finally {
4181 Binder.restoreCallingIdentity(identity);
4182 }
4183 }
4184
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004185 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004186 int slotId = SubscriptionManager.getSlotIndex(subId);
4187 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004188 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4189 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 }
4191 return slotId;
4192 }
4193
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004194 private int getSlotIndex(int subId) {
4195 int slotId = SubscriptionManager.getSlotIndex(subId);
4196 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4197 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4198 }
4199 return slotId;
4200 }
4201
Wink Saville36469e72014-06-11 15:17:00 -07004202 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004203 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004204 */
4205 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004206 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4207 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004208 final int targetSdk = getTargetSdk(callingPackage);
4209 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004210 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004211 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004212 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004213 mApp, subId, callingPackage, callingFeatureId,
4214 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004215 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4216 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004218 final long identity = Binder.clearCallingIdentity();
4219 try {
4220 final Phone phone = getPhone(subId);
4221 if (phone != null) {
4222 return phone.getServiceState().getDataNetworkType();
4223 } else {
4224 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4225 }
4226 } finally {
4227 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004229 }
4230
4231 /**
4232 * Returns the data network type
4233 */
4234 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004235 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4236 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4237 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004238 }
4239
4240 /**
4241 * Returns the data network type for a subId
4242 */
4243 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004244 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4245 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004247 mApp, subId, callingPackage, callingFeatureId,
4248 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004249 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4250 }
4251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252 final long identity = Binder.clearCallingIdentity();
4253 try {
4254 final Phone phone = getPhone(subId);
4255 if (phone != null) {
4256 return phone.getServiceState().getDataNetworkType();
4257 } else {
4258 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4259 }
4260 } finally {
4261 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004263 }
4264
4265 /**
Wink Saville36469e72014-06-11 15:17:00 -07004266 * Returns the Voice network type for a subId
4267 */
4268 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004269 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4270 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004272 mApp, subId, callingPackage, callingFeatureId,
4273 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004274 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4275 }
4276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004277 final long identity = Binder.clearCallingIdentity();
4278 try {
4279 final Phone phone = getPhone(subId);
4280 if (phone != null) {
4281 return phone.getServiceState().getVoiceNetworkType();
4282 } else {
4283 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4284 }
4285 } finally {
4286 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004288 }
4289
4290 /**
4291 * @return true if a ICC card is present
4292 */
4293 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004294 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004295 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4296 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004297 }
4298
4299 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004300 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004301 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004302 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004303 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004304 final long identity = Binder.clearCallingIdentity();
4305 try {
4306 final Phone phone = PhoneFactory.getPhone(slotIndex);
4307 if (phone != null) {
4308 return phone.getIccCard().hasIccCard();
4309 } else {
4310 return false;
4311 }
4312 } finally {
4313 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004315 }
4316
4317 /**
4318 * Return if the current radio is LTE on CDMA. This
4319 * is a tri-state return value as for a period of time
4320 * the mode may be unknown.
4321 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004322 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004323 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004324 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004325 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004326 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004327 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4328 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4329 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004330 }
4331
Sanket Padawe356d7632015-06-22 14:03:32 -07004332 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004333 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4334 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004335 try {
4336 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4337 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004338 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4339 }
4340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004341 final long identity = Binder.clearCallingIdentity();
4342 try {
4343 final Phone phone = getPhone(subId);
4344 if (phone == null) {
4345 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4346 } else {
4347 return phone.getLteOnCdmaMode();
4348 }
4349 } finally {
4350 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004351 }
Wink Saville36469e72014-06-11 15:17:00 -07004352 }
4353
Wink Saville36469e72014-06-11 15:17:00 -07004354 /**
4355 * {@hide}
4356 * Returns Default subId, 0 in the case of single standby.
4357 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004358 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004359 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004360 }
4361
Shishir Agrawala9f32182016-04-12 12:00:16 -07004362 private int getSlotForDefaultSubscription() {
4363 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4364 }
4365
Wink Savilleb564aae2014-10-23 10:18:09 -07004366 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004367 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004368 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004369
Pengquan Menge92a50d2018-09-21 15:54:48 -07004370 private boolean isActiveSubscription(int subId) {
4371 return mSubscriptionController.isActiveSubId(subId);
4372 }
4373
Ihab Awadf2177b72013-11-25 13:33:23 -08004374 /**
4375 * @see android.telephony.TelephonyManager.WifiCallingChoices
4376 */
4377 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004378 final long identity = Binder.clearCallingIdentity();
4379 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004380 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004381 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4382 getWhenToMakeWifiCallsDefaultPreference());
4383 } finally {
4384 Binder.restoreCallingIdentity(identity);
4385 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004386 }
4387
4388 /**
4389 * @see android.telephony.TelephonyManager.WifiCallingChoices
4390 */
4391 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004392 final long identity = Binder.clearCallingIdentity();
4393 try {
4394 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004395 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004396 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004400 }
4401
Sailesh Nepald1e68152013-12-12 19:08:02 -08004402 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004403 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004404 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004405 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004406
Jordan Liu4c733742019-02-28 12:03:40 -08004407 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4408 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4409 if (phoneId == -1) {
4410 throw new IllegalArgumentException("Given slot index: " + slotIndex
4411 + " does not correspond to an active phone");
4412 }
4413 return PhoneFactory.getPhone(phoneId);
4414 }
4415
Shishir Agrawal566b7612013-10-28 14:41:00 -07004416 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004417 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4418 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4420 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004421 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004422 if (DBG) {
4423 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4424 }
4425 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4426 p2);
4427 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004428
Jordan Liu4c733742019-02-28 12:03:40 -08004429
4430 @Override
4431 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4432 int slotIndex, String callingPackage, String aid, int p2) {
4433 enforceModifyPermission();
4434 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4435 if (DBG) {
4436 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4437 }
4438 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4439 callingPackage, aid, p2);
4440 }
4441
4442 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4443 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 final long identity = Binder.clearCallingIdentity();
4445 try {
4446 if (TextUtils.equals(ISDR_AID, aid)) {
4447 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004448 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4449 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450 if (bestComponent == null
4451 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4452 loge("The calling package is not allowed to access ISD-R.");
4453 throw new SecurityException(
4454 "The calling package is not allowed to access ISD-R.");
4455 }
Derek Tan740e1672017-06-27 14:56:27 -07004456 }
Derek Tan740e1672017-06-27 14:56:27 -07004457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004459 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4460 null /* workSource */);
4461 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004462 return response;
4463 } finally {
4464 Binder.restoreCallingIdentity(identity);
4465 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004466 }
4467
4468 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004469 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4471 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004472 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4473 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4474 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004475
Jordan Liu4c733742019-02-28 12:03:40 -08004476 @Override
4477 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4478 enforceModifyPermission();
4479 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4480 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4481 channel);
4482 }
4483
4484 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 final long identity = Binder.clearCallingIdentity();
4486 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004487 if (channel < 0) {
4488 return false;
4489 }
Jordan Liu4c733742019-02-28 12:03:40 -08004490 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4491 null /* workSource */);
4492 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004493 return success;
4494 } finally {
4495 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004496 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004497 }
4498
4499 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004500 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004501 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4503 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004504 if (DBG) {
4505 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4506 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4507 + p3 + " data=" + data);
4508 }
4509 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4510 command, p1, p2, p3, data);
4511 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004512
Jordan Liu4c733742019-02-28 12:03:40 -08004513 @Override
4514 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4515 int command, int p1, int p2, int p3, String data) {
4516 enforceModifyPermission();
4517 if (DBG) {
4518 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4519 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4520 + p3 + " data=" + data);
4521 }
4522 return iccTransmitApduLogicalChannelWithPermission(
4523 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4524 data);
4525 }
4526
4527 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4528 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529 final long identity = Binder.clearCallingIdentity();
4530 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004531 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004532 return "";
4533 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004534
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004535 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004536 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4537 null /* workSource */);
4538 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 // Append the returned status code to the end of the response payload.
4541 String s = Integer.toHexString(
4542 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4543 if (response.payload != null) {
4544 s = IccUtils.bytesToHexString(response.payload) + s;
4545 }
4546 return s;
4547 } finally {
4548 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004549 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004550 }
Jake Hambye994d462014-02-03 13:10:13 -08004551
Evan Charltonc66da362014-05-16 14:06:40 -07004552 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004553 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4554 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4556 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004557 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004558 if (DBG) {
4559 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4560 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4561 }
4562 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4563 cla, command, p1, p2, p3, data);
4564 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004565
Jordan Liu4c733742019-02-28 12:03:40 -08004566 @Override
4567 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4568 int command, int p1, int p2, int p3, String data) {
4569 enforceModifyPermission();
4570 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4571 if (DBG) {
4572 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4573 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4574 + " data=" + data);
4575 }
4576
4577 return iccTransmitApduBasicChannelWithPermission(
4578 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4579 p2, p3, data);
4580 }
4581
4582 // open APDU basic channel assuming the caller has sufficient permissions
4583 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4584 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004585 final long identity = Binder.clearCallingIdentity();
4586 try {
4587 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4588 && TextUtils.equals(ISDR_AID, data)) {
4589 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004590 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4591 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592 if (bestComponent == null
4593 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4594 loge("The calling package is not allowed to select ISD-R.");
4595 throw new SecurityException(
4596 "The calling package is not allowed to select ISD-R.");
4597 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004598 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004600 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004601 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4602 null /* workSource */);
4603 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004605 // Append the returned status code to the end of the response payload.
4606 String s = Integer.toHexString(
4607 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4608 if (response.payload != null) {
4609 s = IccUtils.bytesToHexString(response.payload) + s;
4610 }
4611 return s;
4612 } finally {
4613 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004614 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004615 }
4616
4617 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004618 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004619 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4621 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004623 final long identity = Binder.clearCallingIdentity();
4624 try {
4625 if (DBG) {
4626 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4627 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4628 }
4629
4630 IccIoResult response =
4631 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4632 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4633 subId);
4634
4635 if (DBG) {
4636 log("Exchange SIM_IO [R]" + response);
4637 }
4638
4639 byte[] result = null;
4640 int length = 2;
4641 if (response.payload != null) {
4642 length = 2 + response.payload.length;
4643 result = new byte[length];
4644 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4645 } else {
4646 result = new byte[length];
4647 }
4648
4649 result[length - 1] = (byte) response.sw2;
4650 result[length - 2] = (byte) response.sw1;
4651 return result;
4652 } finally {
4653 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004654 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004655 }
4656
Nathan Haroldb3014052017-01-25 15:57:32 -08004657 /**
4658 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4659 * on a particular subscription
4660 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004661 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4662 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004663 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004664 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004665 return null;
4666 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004667
4668 final long identity = Binder.clearCallingIdentity();
4669 try {
4670 if (appType != TelephonyManager.APPTYPE_USIM
4671 && appType != TelephonyManager.APPTYPE_SIM) {
4672 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4673 return null;
4674 }
4675 Object response = sendRequest(
4676 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4677 if (response instanceof String[]) {
4678 return (String[]) response;
4679 }
yincheng zhaod698b842019-09-06 17:06:54 -07004680 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004682 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683 } finally {
4684 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004685 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004686 }
4687
yincheng zhaod698b842019-09-06 17:06:54 -07004688 /**
4689 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4690 * subscription.
4691 *
4692 * @param subId the id of the subscription.
4693 * @param appType the uicc app type, must be USIM or SIM.
4694 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4695 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004696 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004697 * @return number of fplmns that is successfully written to the SIM.
4698 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004699 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4700 String callingFeatureId) {
4701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4702 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004703 if (DBG) logv("no permissions for setForbiddenplmns");
4704 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4705 }
4706 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4707 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4708 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4709 }
4710 if (fplmns == null) {
4711 throw new IllegalArgumentException("Fplmn List provided is null");
4712 }
4713 for (String fplmn : fplmns) {
4714 if (!CellIdentity.isValidPlmn(fplmn)) {
4715 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4716 }
4717 }
4718 final long identity = Binder.clearCallingIdentity();
4719 try {
4720 Object response = sendRequest(
4721 CMD_SET_FORBIDDEN_PLMNS,
4722 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4723 subId);
4724 return (int) response;
4725 } finally {
4726 Binder.restoreCallingIdentity(identity);
4727 }
4728 }
4729
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004730 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004731 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4733 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735 final long identity = Binder.clearCallingIdentity();
4736 try {
4737 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4738 if (response.payload == null) {
4739 return "";
4740 }
Evan Charltonc66da362014-05-16 14:06:40 -07004741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004742 // Append the returned status code to the end of the response payload.
4743 String s = Integer.toHexString(
4744 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4745 s = IccUtils.bytesToHexString(response.payload) + s;
4746 return s;
4747 } finally {
4748 Binder.restoreCallingIdentity(identity);
4749 }
Evan Charltonc66da362014-05-16 14:06:40 -07004750 }
4751
Jake Hambye994d462014-02-03 13:10:13 -08004752 /**
4753 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4754 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4755 *
4756 * @param itemID the ID of the item to read
4757 * @return the NV item as a String, or null on error.
4758 */
4759 @Override
4760 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004761 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4763 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004764
4765 final long identity = Binder.clearCallingIdentity();
4766 try {
4767 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004768 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4770 return value;
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
4773 }
Jake Hambye994d462014-02-03 13:10:13 -08004774 }
4775
4776 /**
4777 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4778 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4779 *
4780 * @param itemID the ID of the item to read
4781 * @param itemValue the value to write, as a String
4782 * @return true on success; false on any failure
4783 */
4784 @Override
4785 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004786 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4788 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789
4790 final long identity = Binder.clearCallingIdentity();
4791 try {
4792 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4793 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004794 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004795 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4796 return success;
4797 } finally {
4798 Binder.restoreCallingIdentity(identity);
4799 }
Jake Hambye994d462014-02-03 13:10:13 -08004800 }
4801
4802 /**
4803 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4804 * Used for device configuration by some CDMA operators.
4805 *
4806 * @param preferredRoamingList byte array containing the new PRL
4807 * @return true on success; false on any failure
4808 */
4809 @Override
4810 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4812 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813
4814 final long identity = Binder.clearCallingIdentity();
4815 try {
4816 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4817 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4818 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4819 return success;
4820 } finally {
4821 Binder.restoreCallingIdentity(identity);
4822 }
Jake Hambye994d462014-02-03 13:10:13 -08004823 }
4824
4825 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004826 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004827 * Used for device configuration by some CDMA operators.
4828 *
chen xu6dac5ab2018-10-26 17:39:23 -07004829 * @param slotIndex - device slot.
4830 *
Jake Hambye994d462014-02-03 13:10:13 -08004831 * @return true on success; false on any failure
4832 */
4833 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004834 public boolean resetModemConfig(int slotIndex) {
4835 Phone phone = PhoneFactory.getPhone(slotIndex);
4836 if (phone != null) {
4837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4838 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004839
chen xu6dac5ab2018-10-26 17:39:23 -07004840 final long identity = Binder.clearCallingIdentity();
4841 try {
4842 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4843 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4844 return success;
4845 } finally {
4846 Binder.restoreCallingIdentity(identity);
4847 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004848 }
chen xu6dac5ab2018-10-26 17:39:23 -07004849 return false;
4850 }
4851
4852 /**
4853 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4854 *
4855 * @param slotIndex - device slot.
4856 *
4857 * @return true on success; false on any failure
4858 */
4859 @Override
4860 public boolean rebootModem(int slotIndex) {
4861 Phone phone = PhoneFactory.getPhone(slotIndex);
4862 if (phone != null) {
4863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4864 mApp, phone.getSubId(), "rebootModem");
4865
4866 final long identity = Binder.clearCallingIdentity();
4867 try {
4868 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4869 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4870 return success;
4871 } finally {
4872 Binder.restoreCallingIdentity(identity);
4873 }
4874 }
4875 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004876 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004877
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004878 public String[] getPcscfAddress(String apnType, String callingPackage,
4879 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004880 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004881 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4882 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004883 return new String[0];
4884 }
4885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004886 final long identity = Binder.clearCallingIdentity();
4887 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004888 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 } finally {
4890 Binder.restoreCallingIdentity(identity);
4891 }
Wink Saville36469e72014-06-11 15:17:00 -07004892 }
4893
Brad Ebinger51f743a2017-01-23 13:50:20 -08004894 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004895 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4896 * {@link #disableIms(int)}.
4897 * @param slotIndex device slot.
4898 */
4899 public void resetIms(int slotIndex) {
4900 enforceModifyPermission();
4901
4902 final long identity = Binder.clearCallingIdentity();
4903 try {
4904 if (mImsResolver == null) {
4905 // may happen if the does not support IMS.
4906 return;
4907 }
4908 mImsResolver.disableIms(slotIndex);
4909 mImsResolver.enableIms(slotIndex);
4910 } finally {
4911 Binder.restoreCallingIdentity(identity);
4912 }
4913 }
4914
4915 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004916 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4917 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004918 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004919 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004920 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921
4922 final long identity = Binder.clearCallingIdentity();
4923 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004924 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004925 // may happen if the device does not support IMS.
4926 return;
4927 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004928 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004929 } finally {
4930 Binder.restoreCallingIdentity(identity);
4931 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004932 }
4933
4934 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004935 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4936 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004937 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004938 public void disableIms(int slotId) {
4939 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940
4941 final long identity = Binder.clearCallingIdentity();
4942 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004943 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004944 // may happen if the device does not support IMS.
4945 return;
4946 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004947 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948 } finally {
4949 Binder.restoreCallingIdentity(identity);
4950 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004951 }
4952
4953 /**
4954 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4955 * feature or {@link null} if the service is not available. If the feature is available, the
4956 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4957 */
4958 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004959 IImsServiceFeatureCallback callback) {
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 null;
4967 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004968 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969 } finally {
4970 Binder.restoreCallingIdentity(identity);
4971 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004972 }
4973
4974 /**
4975 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4976 * feature during emergency calling or {@link null} if the service is not available. If the
4977 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4978 * listener for feature updates.
4979 */
4980 public IImsRcsFeature getRcsFeatureAndListen(int slotId, 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.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004990 } finally {
4991 Binder.restoreCallingIdentity(identity);
4992 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004993 }
4994
Brad Ebinger5f64b052017-12-14 14:26:15 -08004995 /**
4996 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004997 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004998 */
4999 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5000 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001
5002 final long identity = Binder.clearCallingIdentity();
5003 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005004 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005005 // may happen if the device does not support IMS.
5006 return null;
5007 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005008 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009 } finally {
5010 Binder.restoreCallingIdentity(identity);
5011 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005012 }
5013
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005014 /**
5015 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005016 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005017 */
5018 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5019 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020
5021 final long identity = Binder.clearCallingIdentity();
5022 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005023 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005024 // may happen if the device does not support IMS.
5025 return null;
5026 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005027 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 } finally {
5029 Binder.restoreCallingIdentity(identity);
5030 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005031 }
5032
Brad Ebinger884c07b2018-02-15 16:17:40 -08005033 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005034 * Sets the ImsService Package Name that Telephony will bind to.
5035 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005036 * @param slotIndex the slot ID that the ImsService should bind for.
5037 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005038 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005039 * @param featureTypes An integer array of feature types associated with a packageName.
5040 * @param packageName The name of the package that the current configuration will be replaced
5041 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005042 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005043 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005044 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5045 int[] featureTypes, String packageName) {
5046 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5047 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5049 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005050 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 final long identity = Binder.clearCallingIdentity();
5053 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005054 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005055 // may happen if the device does not support IMS.
5056 return false;
5057 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005058 Map<Integer, String> featureConfig = new HashMap<>();
5059 for (int featureType : featureTypes) {
5060 featureConfig.put(featureType, packageName);
5061 }
5062 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5063 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005067 }
5068
5069 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005070 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005071 *
5072 * @param slotId The slot that the ImsService is associated with.
5073 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5074 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005075 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005076 * @return the package name of the ImsService configuration.
5077 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005078 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5079 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005080 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005081 TelephonyPermissions
5082 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5083 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5084 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 final long identity = Binder.clearCallingIdentity();
5087 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005088 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005089 // may happen if the device does not support IMS.
5090 return "";
5091 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005092 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005093 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5094 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 } finally {
5096 Binder.restoreCallingIdentity(identity);
5097 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005098 }
5099
Brad Ebinger77b832e2019-10-17 17:03:22 -07005100 /**
5101 * Get the MmTelFeature state associated with the requested subscription id.
5102 * @param subId The subscription that the MmTelFeature is associated with.
5103 * @param callback A callback with an integer containing the
5104 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5105 */
5106 @Override
5107 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5108 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5109 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5110 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5111 "IMS not available on device.");
5112 }
5113 final long token = Binder.clearCallingIdentity();
5114 try {
5115 int slotId = getSlotIndex(subId);
5116 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5117 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5118 + subId + "'");
5119 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5120 }
5121 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5122 try {
5123 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5124 } catch (RemoteException e) {
5125 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5126 + "Ignore");
5127 }
5128 });
5129 } finally {
5130 Binder.restoreCallingIdentity(token);
5131 }
5132 }
5133
Wink Saville36469e72014-06-11 15:17:00 -07005134 public void setImsRegistrationState(boolean registered) {
5135 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005136
5137 final long identity = Binder.clearCallingIdentity();
5138 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005139 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140 } finally {
5141 Binder.restoreCallingIdentity(identity);
5142 }
Wink Saville36469e72014-06-11 15:17:00 -07005143 }
5144
5145 /**
Stuart Scott54788802015-03-30 13:18:01 -07005146 * Set the network selection mode to automatic.
5147 *
5148 */
5149 @Override
5150 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5152 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153
5154 final long identity = Binder.clearCallingIdentity();
5155 try {
shilufc958392020-01-20 11:36:01 -08005156 if (!isActiveSubscription(subId)) {
5157 return;
5158 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5160 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5161 } finally {
5162 Binder.restoreCallingIdentity(identity);
5163 }
Stuart Scott54788802015-03-30 13:18:01 -07005164 }
5165
Pengquan Mengea84e042018-09-20 14:57:26 -07005166 /**
5167 * Ask the radio to connect to the input network and change selection mode to manual.
5168 *
5169 * @param subId the id of the subscription.
5170 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5171 * the operator to attach to.
5172 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5173 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5174 * normal network selection next time.
5175 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005176 */
5177 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005178 public boolean setNetworkSelectionModeManual(
5179 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5181 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005182
5183 if (!isActiveSubscription(subId)) {
5184 return false;
5185 }
5186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 final long identity = Binder.clearCallingIdentity();
5188 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005189 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005191 if (DBG) {
5192 log("setNetworkSelectionModeManual: subId: " + subId
5193 + " operator: " + operatorInfo);
5194 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5196 } finally {
5197 Binder.restoreCallingIdentity(identity);
5198 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005199 }
5200
5201 /**
5202 * Scans for available networks.
5203 */
5204 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005205 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5206 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5208 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005209 LocationAccessPolicy.LocationPermissionResult locationResult =
5210 LocationAccessPolicy.checkLocationPermission(mApp,
5211 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5212 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005213 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005214 .setCallingPid(Binder.getCallingPid())
5215 .setCallingUid(Binder.getCallingUid())
5216 .setMethod("getCellNetworkScanResults")
5217 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5218 .build());
5219 switch (locationResult) {
5220 case DENIED_HARD:
5221 throw new SecurityException("Not allowed to access scan results -- location");
5222 case DENIED_SOFT:
5223 return null;
5224 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225
Pengquan Menga1bb6272018-09-06 09:59:22 -07005226 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227 try {
5228 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005229 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 } finally {
5232 Binder.restoreCallingIdentity(identity);
5233 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005234 }
5235
5236 /**
sqian80370722020-01-29 15:02:51 -08005237 * Get the call forwarding info, given the call forwarding reason.
5238 */
5239 @Override
5240 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5241 enforceReadPrivilegedPermission("getCallForwarding");
5242 long identity = Binder.clearCallingIdentity();
5243 try {
5244 if (DBG) {
5245 log("getCallForwarding: subId " + subId
5246 + " callForwardingReason" + callForwardingReason);
5247 }
5248 return (CallForwardingInfo) sendRequest(
5249 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5250 } finally {
5251 Binder.restoreCallingIdentity(identity);
5252 }
5253 }
5254
5255 /**
5256 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5257 * reason, the number to forward, and the timeout before the forwarding is attempted.
5258 */
5259 @Override
5260 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5261 enforceModifyPermission();
5262 long identity = Binder.clearCallingIdentity();
5263 try {
5264 if (DBG) {
5265 log("setCallForwarding: subId " + subId
5266 + " callForwardingInfo" + callForwardingInfo);
5267 }
5268 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5269 } finally {
5270 Binder.restoreCallingIdentity(identity);
5271 }
5272 }
5273
5274 /**
5275 * Get the call forwarding info, given the call forwarding reason.
5276 */
5277 @Override
5278 public int getCallWaitingStatus(int subId) {
5279 enforceReadPrivilegedPermission("getCallForwarding");
5280 long identity = Binder.clearCallingIdentity();
5281 try {
5282 if (DBG) log("getCallWaitingStatus: subId " + subId);
5283 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
5287 }
5288
5289 /**
5290 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5291 * reason, the number to forward, and the timeout before the forwarding is attempted.
5292 */
5293 @Override
5294 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5295 enforceModifyPermission();
5296 long identity = Binder.clearCallingIdentity();
5297 try {
5298 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5299 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302 }
5303 }
5304
5305 /**
yinxub1bed742017-04-17 11:45:04 -07005306 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005307 *
yinxub1bed742017-04-17 11:45:04 -07005308 * @param subId id of the subscription
5309 * @param request contains the radio access networks with bands/channels to scan
5310 * @param messenger callback messenger for scan results or errors
5311 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005312 * @return the id of the requested scan which can be used to stop the scan.
5313 */
5314 @Override
5315 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005316 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5318 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005319 LocationAccessPolicy.LocationPermissionResult locationResult =
5320 LocationAccessPolicy.checkLocationPermission(mApp,
5321 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5322 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005323 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005324 .setCallingPid(Binder.getCallingPid())
5325 .setCallingUid(Binder.getCallingUid())
5326 .setMethod("requestNetworkScan")
5327 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5328 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005329 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005330 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005331 if (e != null) {
5332 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5333 throw e;
5334 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005335 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005336 return TelephonyScanManager.INVALID_SCAN_ID;
5337 }
5338 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005339 }
Hall Liu912dfd32019-04-25 14:02:26 -07005340 int callingUid = Binder.getCallingUid();
5341 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005342 final long identity = Binder.clearCallingIdentity();
5343 try {
5344 return mNetworkScanRequestTracker.startNetworkScan(
5345 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005346 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005347 } finally {
5348 Binder.restoreCallingIdentity(identity);
5349 }
yinxu504e1392017-04-12 16:03:22 -07005350 }
5351
Hall Liub2ac8ef2019-02-28 15:56:23 -08005352 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005353 NetworkScanRequest request, int subId) {
5354 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5355 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5356 boolean hasNetworkScanPermission =
5357 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5358 == PERMISSION_GRANTED;
5359
5360 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5361 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5362 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005363 }
5364
5365 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5366 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005367 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5368 return new SecurityException("Specific channels must not be"
5369 + " scanned without location access.");
5370 }
5371 }
5372 }
5373
Hall Liub2ac8ef2019-02-28 15:56:23 -08005374 return null;
5375 }
5376
yinxu504e1392017-04-12 16:03:22 -07005377 /**
5378 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005379 *
5380 * @param subId id of the subscription
5381 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005382 */
5383 @Override
5384 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5386 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005387
Hall Liu912dfd32019-04-25 14:02:26 -07005388 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 final long identity = Binder.clearCallingIdentity();
5390 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005391 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005392 } finally {
5393 Binder.restoreCallingIdentity(identity);
5394 }
yinxu504e1392017-04-12 16:03:22 -07005395 }
5396
5397 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005398 * Get the calculated preferred network type.
5399 * Used for debugging incorrect network type.
5400 *
5401 * @return the preferred network type, defined in RILConstants.java.
5402 */
5403 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005404 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005405 final Phone defaultPhone = getDefaultPhone();
5406 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005407 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005408 return RILConstants.PREFERRED_NETWORK_MODE;
5409 }
5410
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 final long identity = Binder.clearCallingIdentity();
5412 try {
5413 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005414 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415 } finally {
5416 Binder.restoreCallingIdentity(identity);
5417 }
Junda Liu84d15a22014-07-02 11:21:04 -07005418 }
5419
5420 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005421 * Get the preferred network type.
5422 * Used for device configuration by some CDMA operators.
5423 *
5424 * @return the preferred network type, defined in RILConstants.java.
5425 */
5426 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005427 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005428 TelephonyPermissions
5429 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5430 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431
5432 final long identity = Binder.clearCallingIdentity();
5433 try {
5434 if (DBG) log("getPreferredNetworkType");
5435 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5436 int networkType = (result != null ? result[0] : -1);
5437 if (DBG) log("getPreferredNetworkType: " + networkType);
5438 return networkType;
5439 } finally {
5440 Binder.restoreCallingIdentity(identity);
5441 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005442 }
5443
5444 /**
5445 * Set the preferred network type.
5446 * Used for device configuration by some CDMA operators.
5447 *
5448 * @param networkType the preferred network type, defined in RILConstants.java.
5449 * @return true on success; false on any failure.
5450 */
5451 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005452 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5454 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005455
5456 final long identity = Binder.clearCallingIdentity();
5457 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005458 Settings.Global.putInt(mApp.getContentResolver(),
5459 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5460 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 } finally {
5462 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005463 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005464 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005465
5466 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005467 * Get the allowed network types that store in the telephony provider.
5468 *
5469 * @param subId the id of the subscription.
5470 * @return allowedNetworkTypes the allowed network types.
5471 */
5472 @Override
5473 public long getAllowedNetworkTypes(int subId) {
5474 TelephonyPermissions
5475 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5476 mApp, subId, "getAllowedNetworkTypes");
5477
5478 final long identity = Binder.clearCallingIdentity();
5479 try {
5480 return SubscriptionManager.getLongSubscriptionProperty(
5481 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5482 } finally {
5483 Binder.restoreCallingIdentity(identity);
5484 }
5485 }
5486
5487 /**
5488 * Set the allowed network types.
5489 *
5490 * @param subId the id of the subscription.
5491 * @param allowedNetworkTypes the allowed network types.
5492 * @return true on success; false on any failure.
5493 */
5494 @Override
5495 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5497 mApp, subId, "setAllowedNetworkTypes");
5498 final long identity = Binder.clearCallingIdentity();
5499 try {
5500 SubscriptionManager.setSubscriptionProperty(subId,
5501 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5502 String.valueOf(allowedNetworkTypes));
5503 return setPreferredNetworkTypesInternal(subId);
5504 } finally {
5505 Binder.restoreCallingIdentity(identity);
5506 }
5507 }
5508
5509 private boolean setPreferredNetworkTypesInternal(int subId) {
5510 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5511 Settings.Global.getInt(mApp.getContentResolver(),
5512 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5513 RILConstants.PREFERRED_NETWORK_MODE));
5514 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5515 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5516 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5517 (int) (networkTypeBitMask & allowedNetworkTypes));
5518
5519 if (DBG) {
5520 log("setPreferredNetworkTypesInternal: subId " + subId
5521 + " networkTypes " + networkTypeBitMask
5522 + " allowedNetworkTypes " + allowedNetworkTypes
5523 + " networkMode " + networkMode);
5524 }
5525
5526 Boolean success = (Boolean) sendRequest(
5527 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5528 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5529 return success;
5530 }
5531
5532 /**
Miaoa84611c2019-03-15 09:21:10 +08005533 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005534 *
Miaoa84611c2019-03-15 09:21:10 +08005535 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005536 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005537 * @hide
5538 */
5539 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005540 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005541 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005542 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005543 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005544 try {
Miaoa84611c2019-03-15 09:21:10 +08005545 if (phone != null) {
5546 return phone.hasMatchedTetherApnSetting();
5547 } else {
5548 return false;
5549 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005550 } finally {
5551 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005552 }
Junda Liu475951f2014-11-07 16:45:03 -08005553 }
5554
5555 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005556 * Set mobile data enabled
5557 * Used by the user through settings etc to turn on/off mobile data
5558 *
5559 * @param enable {@code true} turn turn data on, else {@code false}
5560 */
5561 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005562 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5564 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565
5566 final long identity = Binder.clearCallingIdentity();
5567 try {
5568 int phoneId = mSubscriptionController.getPhoneId(subId);
5569 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5570 Phone phone = PhoneFactory.getPhone(phoneId);
5571 if (phone != null) {
5572 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005573 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005575 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005576 }
5577 } finally {
5578 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005579 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005580 }
5581
5582 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005583 * Enable or disable always reporting signal strength changes from radio.
5584 *
5585 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5586 */
5587 @Override
5588 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5589 enforceModifyPermission();
5590 enforceSystemCaller();
5591
5592 final long identity = Binder.clearCallingIdentity();
5593 final Phone phone = getPhone(subId);
5594 try {
5595 if (phone != null) {
5596 if (DBG) {
5597 log("setAlwaysReportSignalStrength: subId=" + subId
5598 + " isEnable=" + isEnable);
5599 }
5600 phone.setAlwaysReportSignalStrength(isEnable);
5601 } else {
5602 loge("setAlwaysReportSignalStrength: no phone found for subId="
5603 + subId);
5604 }
5605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
5608 }
5609
5610 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005611 * Get the user enabled state of Mobile Data.
5612 *
5613 * TODO: remove and use isUserDataEnabled.
5614 * This can't be removed now because some vendor codes
5615 * calls through ITelephony directly while they should
5616 * use TelephonyManager.
5617 *
5618 * @return true on enabled
5619 */
5620 @Override
5621 public boolean getDataEnabled(int subId) {
5622 return isUserDataEnabled(subId);
5623 }
5624
5625 /**
5626 * Get whether mobile data is enabled per user setting.
5627 *
5628 * There are other factors deciding whether mobile data is actually enabled, but they are
5629 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005630 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005631 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005632 *
5633 * @return {@code true} if data is enabled else {@code false}
5634 */
5635 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005636 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005637 try {
5638 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5639 null);
5640 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5642 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644
5645 final long identity = Binder.clearCallingIdentity();
5646 try {
5647 int phoneId = mSubscriptionController.getPhoneId(subId);
5648 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5649 Phone phone = PhoneFactory.getPhone(phoneId);
5650 if (phone != null) {
5651 boolean retVal = phone.isUserDataEnabled();
5652 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5653 return retVal;
5654 } else {
5655 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5656 return false;
5657 }
5658 } finally {
5659 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005660 }
5661 }
5662
5663 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005664 * Checks if the device is capable of mobile data by considering whether whether the
5665 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5666 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005667 *
Shuo Qian985d1232020-01-08 14:30:06 -08005668 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005669 */
5670 @Override
5671 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005672 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673
5674 final long identity = Binder.clearCallingIdentity();
5675 try {
5676 int phoneId = mSubscriptionController.getPhoneId(subId);
5677 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5678 Phone phone = PhoneFactory.getPhone(phoneId);
5679 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005680 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5682 return retVal;
5683 } else {
5684 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5685 return false;
5686 }
5687 } finally {
5688 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005689 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005690 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005691
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005692 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5693 Phone phone) {
5694 //load access rules from carrier configs, and check those as well: b/139133814
5695 SubscriptionController subController = SubscriptionController.getInstance();
5696 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5697 || subController == null) return privilegeFromSim;
5698
5699 int uid = Binder.getCallingUid();
5700 PackageManager pkgMgr = phone.getContext().getPackageManager();
5701 String[] packages = pkgMgr.getPackagesForUid(uid);
5702
5703 final long identity = Binder.clearCallingIdentity();
5704 try {
5705 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5706 SubscriptionManager subManager = (SubscriptionManager)
5707 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5708 for (String pkg : packages) {
5709 if (subManager.canManageSubscription(subInfo, pkg)) {
5710 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5711 }
5712 }
5713 return privilegeFromSim;
5714 } finally {
5715 Binder.restoreCallingIdentity(identity);
5716 }
5717 }
5718
5719 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5720 String pkgName) {
5721 //load access rules from carrier configs, and check those as well: b/139133814
5722 SubscriptionController subController = SubscriptionController.getInstance();
5723 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5724 || subController == null) return privilegeFromSim;
5725
5726 final long identity = Binder.clearCallingIdentity();
5727 try {
5728 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5729 SubscriptionManager subManager = (SubscriptionManager)
5730 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5731 return subManager.canManageSubscription(subInfo, pkgName)
5732 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5733 } finally {
5734 Binder.restoreCallingIdentity(identity);
5735 }
5736 }
5737
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005738 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005739 public int getCarrierPrivilegeStatus(int subId) {
5740 final Phone phone = getPhone(subId);
5741 if (phone == null) {
5742 loge("getCarrierPrivilegeStatus: Invalid subId");
5743 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5744 }
5745 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005746 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005747 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005748 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5749 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005750
5751 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5752 card.getCarrierPrivilegeStatusForCurrentTransaction(
5753 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005754 }
Junda Liu29340342014-07-10 15:23:27 -07005755
5756 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005757 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005758 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005759 final Phone phone = getPhone(subId);
5760 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005761 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005762 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5763 }
5764 UiccProfile profile =
5765 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5766 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005767 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005768 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5769 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005770 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005771 profile.getCarrierPrivilegeStatusForUid(
5772 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005773 }
5774
5775 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005776 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5777 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005778 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005779 }
5780
5781 int phoneId = SubscriptionManager.getPhoneId(subId);
5782 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005783 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005784 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005785 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5786 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005787 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5788 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5789 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005790 }
5791
5792 @Override
5793 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005794 if (TextUtils.isEmpty(pkgName))
5795 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005796 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5797 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5798 UiccCard card = UiccController.getInstance().getUiccCard(i);
5799 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005800 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005801 continue;
5802 }
5803
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005804 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5805 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5806 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005807 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5808 break;
5809 }
5810 }
5811
5812 return result;
Junda Liu29340342014-07-10 15:23:27 -07005813 }
Derek Tan89e89d42014-07-08 17:00:10 -07005814
5815 @Override
Junda Liue64de782015-04-16 17:19:16 -07005816 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5817 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5818 loge("phoneId " + phoneId + " is not valid.");
5819 return null;
5820 }
5821 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005822 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005823 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005824 return null ;
5825 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005826 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005827 }
5828
Amith Yamasani6e118872016-02-19 12:53:51 -08005829 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005830 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005831 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005832 List<String> privilegedPackages = new ArrayList<>();
5833 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005834 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5835 // has UICC in that slot.
5836 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005837 if (card.hasCarrierPrivilegeRules()) {
5838 if (packages == null) {
5839 // Only check packages in user 0 for now
5840 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005841 PackageManager.MATCH_DISABLED_COMPONENTS
5842 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005843 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005844 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005845 }
5846 for (int p = packages.size() - 1; p >= 0; p--) {
5847 PackageInfo pkgInfo = packages.get(p);
5848 if (pkgInfo != null && pkgInfo.packageName != null
5849 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005850 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005851 privilegedPackages.add(pkgInfo.packageName);
5852 }
5853 }
5854 }
5855 }
5856 return privilegedPackages;
5857 }
5858
chen xuf7e9fe82019-05-09 19:31:02 -07005859 @Override
5860 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005861 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5862
5863 final long identity = Binder.clearCallingIdentity();
5864
chen xuf7e9fe82019-05-09 19:31:02 -07005865 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005866 try {
5867 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5868 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5869 }
5870 } finally {
5871 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005872 }
5873 return privilegedPackages;
5874 }
5875
Wink Savilleb564aae2014-10-23 10:18:09 -07005876 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005877 final Phone phone = getPhone(subId);
5878 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005879 if (card == null) {
5880 loge("getIccId: No UICC");
5881 return null;
5882 }
5883 String iccId = card.getIccId();
5884 if (TextUtils.isEmpty(iccId)) {
5885 loge("getIccId: ICC ID is null or empty.");
5886 return null;
5887 }
5888 return iccId;
5889 }
5890
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005891 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005892 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5893 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005894 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005895 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 final long identity = Binder.clearCallingIdentity();
5898 try {
5899 final String iccId = getIccId(subId);
5900 final Phone phone = getPhone(subId);
5901 if (phone == null) {
5902 return false;
5903 }
5904 final String subscriberId = phone.getSubscriberId();
5905
5906 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005907 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 + subscriberId + " to " + number);
5909 }
5910
5911 if (TextUtils.isEmpty(iccId)) {
5912 return false;
5913 }
5914
5915 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5916
5917 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5918 if (alphaTag == null) {
5919 editor.remove(alphaTagPrefKey);
5920 } else {
5921 editor.putString(alphaTagPrefKey, alphaTag);
5922 }
5923
5924 // Record both the line number and IMSI for this ICCID, since we need to
5925 // track all merged IMSIs based on line number
5926 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5927 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5928 if (number == null) {
5929 editor.remove(numberPrefKey);
5930 editor.remove(subscriberPrefKey);
5931 } else {
5932 editor.putString(numberPrefKey, number);
5933 editor.putString(subscriberPrefKey, subscriberId);
5934 }
5935
5936 editor.commit();
5937 return true;
5938 } finally {
5939 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005940 }
Derek Tan7226c842014-07-02 17:42:23 -07005941 }
5942
5943 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005944 public String getLine1NumberForDisplay(int subId, String callingPackage,
5945 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005946 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005947 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005948 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005949 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005950 return null;
5951 }
Derek Tan97ebb422014-09-05 16:55:38 -07005952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953 final long identity = Binder.clearCallingIdentity();
5954 try {
5955 String iccId = getIccId(subId);
5956 if (iccId != null) {
5957 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5958 if (DBG_MERGE) {
5959 log("getLine1NumberForDisplay returning "
5960 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5961 }
5962 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005964 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5965 return null;
5966 } finally {
5967 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005968 }
Derek Tan7226c842014-07-02 17:42:23 -07005969 }
5970
5971 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005972 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5973 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005974 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005975 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005976 return null;
5977 }
Derek Tan97ebb422014-09-05 16:55:38 -07005978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 final long identity = Binder.clearCallingIdentity();
5980 try {
5981 String iccId = getIccId(subId);
5982 if (iccId != null) {
5983 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5984 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5985 }
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 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005991
5992 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005993 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5994 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005995 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5996 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005997 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005998 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005999 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006000 return null;
6001 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006002
Jordan Liub49b04b2019-05-06 14:45:15 -07006003 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6004 // the process, where TelephonyManager was instantiated.
6005 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006006 final long identity = Binder.clearCallingIdentity();
6007 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006008 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 final TelephonyManager tele = TelephonyManager.from(context);
6010 final SubscriptionManager sub = SubscriptionManager.from(context);
6011
6012 // Figure out what subscribers are currently active
6013 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014
Jordan Liub49b04b2019-05-06 14:45:15 -07006015 // Only consider subs which match the current subId
6016 // This logic can be simplified. See b/131189269 for progress.
6017 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006018 activeSubscriberIds.add(tele.getSubscriberId(subId));
6019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020
6021 // First pass, find a number override for an active subscriber
6022 String mergeNumber = null;
6023 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6024 for (String key : prefs.keySet()) {
6025 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6026 final String subscriberId = (String) prefs.get(key);
6027 if (activeSubscriberIds.contains(subscriberId)) {
6028 final String iccId = key.substring(
6029 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6030 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6031 mergeNumber = (String) prefs.get(numberKey);
6032 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006033 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034 + " for active subscriber " + subscriberId);
6035 }
6036 if (!TextUtils.isEmpty(mergeNumber)) {
6037 break;
6038 }
6039 }
6040 }
6041 }
6042
6043 // Shortcut when no active merged subscribers
6044 if (TextUtils.isEmpty(mergeNumber)) {
6045 return null;
6046 }
6047
6048 // Second pass, find all subscribers under that line override
6049 final ArraySet<String> result = new ArraySet<>();
6050 for (String key : prefs.keySet()) {
6051 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6052 final String number = (String) prefs.get(key);
6053 if (mergeNumber.equals(number)) {
6054 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6055 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6056 final String subscriberId = (String) prefs.get(subscriberKey);
6057 if (!TextUtils.isEmpty(subscriberId)) {
6058 result.add(subscriberId);
6059 }
6060 }
6061 }
6062 }
6063
6064 final String[] resultArray = result.toArray(new String[result.size()]);
6065 Arrays.sort(resultArray);
6066 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006067 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6069 }
6070 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006071 } finally {
6072 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006073 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006074 }
6075
6076 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006077 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6078 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6079
6080 final long identity = Binder.clearCallingIdentity();
6081 try {
6082 final TelephonyManager telephonyManager = mApp.getSystemService(
6083 TelephonyManager.class);
6084 String subscriberId = telephonyManager.getSubscriberId(subId);
6085 if (subscriberId == null) {
6086 if (DBG) {
6087 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6088 + subId);
6089 }
6090 return null;
6091 }
6092
6093 final SubscriptionInfo info = SubscriptionController.getInstance()
6094 .getSubscriptionInfo(subId);
6095 final ParcelUuid groupUuid = info.getGroupUuid();
6096 // If it doesn't belong to any group, return just subscriberId of itself.
6097 if (groupUuid == null) {
6098 return new String[]{subscriberId};
6099 }
6100
6101 // Get all subscriberIds from the group.
6102 final List<String> mergedSubscriberIds = new ArrayList<>();
6103 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006104 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6105 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006106 for (SubscriptionInfo subInfo : groupInfos) {
6107 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6108 if (subscriberId != null) {
6109 mergedSubscriberIds.add(subscriberId);
6110 }
6111 }
6112
6113 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6114 } finally {
6115 Binder.restoreCallingIdentity(identity);
6116
6117 }
6118 }
6119
6120 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006121 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006122 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006123 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006124
6125 final long identity = Binder.clearCallingIdentity();
6126 try {
6127 final Phone phone = getPhone(subId);
6128 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6129 } finally {
6130 Binder.restoreCallingIdentity(identity);
6131 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006132 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006133
6134 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006135 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006136 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6137 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006138 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6139 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140
6141 final long identity = Binder.clearCallingIdentity();
6142 try {
6143 final Phone phone = getPhone(subId);
6144 if (phone == null) {
6145 return false;
6146 }
6147 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6148 cdmaNonRoamingList);
6149 } finally {
6150 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006151 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006152 }
6153
6154 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006155 @Deprecated
6156 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6157 enforceModifyPermission();
6158
6159 int returnValue = 0;
6160 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006161 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006162 if(result.exception == null) {
6163 if (result.result != null) {
6164 byte[] responseData = (byte[])(result.result);
6165 if(responseData.length > oemResp.length) {
6166 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6167 responseData.length + "bytes. Buffer Size is " +
6168 oemResp.length + "bytes.");
6169 }
6170 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6171 returnValue = responseData.length;
6172 }
6173 } else {
6174 CommandException ex = (CommandException) result.exception;
6175 returnValue = ex.getCommandError().ordinal();
6176 if(returnValue > 0) returnValue *= -1;
6177 }
6178 } catch (RuntimeException e) {
6179 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6180 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6181 if(returnValue > 0) returnValue *= -1;
6182 }
6183
6184 return returnValue;
6185 }
6186
6187 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006188 public void setRadioCapability(RadioAccessFamily[] rafs) {
6189 try {
6190 ProxyController.getInstance().setRadioCapability(rafs);
6191 } catch (RuntimeException e) {
6192 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6193 }
6194 }
6195
6196 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006197 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006198 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006199 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006200 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006201 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006202 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006203 final long identity = Binder.clearCallingIdentity();
6204 try {
chen xub97461a2018-10-26 14:17:57 -07006205 TelephonyPermissions
6206 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6207 mApp, phone.getSubId(), "getRadioAccessFamily");
6208 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006209 } finally {
6210 Binder.restoreCallingIdentity(identity);
6211 }
chen xub97461a2018-10-26 14:17:57 -07006212 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006213 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006214
6215 @Override
6216 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006217 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006218 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219
6220 final long identity = Binder.clearCallingIdentity();
6221 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006222 ImsManager.getInstance(defaultPhone.getContext(),
6223 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 } finally {
6225 Binder.restoreCallingIdentity(identity);
6226 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006227 }
6228
6229 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006230 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006231 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6233 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006234 return false;
6235 }
Svet Ganovb320e182015-04-16 12:30:10 -07006236
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 final long identity = Binder.clearCallingIdentity();
6238 try {
6239 // Check the user preference and the system-level IMS setting. Even if the user has
6240 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6241 // In the long run, we may instead need to check if there exists a connection service
6242 // which can support video calling.
6243 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006244 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006245 return imsManager.isVtEnabledByPlatform()
6246 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6247 && imsManager.isVtEnabledByUser();
6248 } finally {
6249 Binder.restoreCallingIdentity(identity);
6250 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006251 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006252
Andrew Leea1239f22015-03-02 17:44:07 -08006253 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006254 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6255 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006256 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006257 mApp, subId, callingPackage, callingFeatureId,
6258 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 return false;
6260 }
6261
6262 final long identity = Binder.clearCallingIdentity();
6263 try {
6264 CarrierConfigManager configManager =
6265 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006266 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6268 } finally {
6269 Binder.restoreCallingIdentity(identity);
6270 }
Andrew Leea1239f22015-03-02 17:44:07 -08006271 }
6272
6273 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006274 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006276 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006277 return false;
6278 }
6279
6280 final long identity = Binder.clearCallingIdentity();
6281 try {
6282 CarrierConfigManager configManager =
6283 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006284 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006285 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6286 } finally {
6287 Binder.restoreCallingIdentity(identity);
6288 }
Andrew Leea1239f22015-03-02 17:44:07 -08006289 }
6290
Andrew Lee9431b832015-03-09 18:46:45 -07006291 @Override
6292 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006293 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006294 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006295 }
6296
6297 @Override
6298 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 final long identity = Binder.clearCallingIdentity();
6300 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006301 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006302 } finally {
6303 Binder.restoreCallingIdentity(identity);
6304 }
Andrew Lee9431b832015-03-09 18:46:45 -07006305 }
6306
Hall Liuf6668912018-10-31 17:05:23 -07006307 /**
6308 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6309 * support for the feature and device firmware support.
6310 *
6311 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6312 */
6313 @Override
6314 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006316 final Phone phone = getPhone(subscriptionId);
6317 if (phone == null) {
6318 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6319 return false;
6320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006322 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006323 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6324 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006325 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006326 return isCarrierSupported && isDeviceSupported;
6327 } finally {
6328 Binder.restoreCallingIdentity(identity);
6329 }
Hall Liu98187582018-01-22 19:15:32 -08006330 }
6331
Hall Liuf6668912018-10-31 17:05:23 -07006332 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006333 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6334 * RTT setting, will return true if the device and carrier both support RTT.
6335 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006336 */
6337 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006338 final long identity = Binder.clearCallingIdentity();
6339 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006340 boolean isRttSupported = isRttSupported(subscriptionId);
6341 boolean isUserRttSettingOn = Settings.Secure.getInt(
6342 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6343 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6344 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6345 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 } finally {
6347 Binder.restoreCallingIdentity(identity);
6348 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006349 }
6350
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006351 @Deprecated
6352 @Override
6353 public String getDeviceId(String callingPackage) {
6354 return getDeviceIdWithFeature(callingPackage, null);
6355 }
6356
Sanket Padawe7310cc72015-01-14 09:53:20 -08006357 /**
6358 * Returns the unique device ID of phone, for example, the IMEI for
6359 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6360 *
6361 * <p>Requires Permission:
6362 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6363 */
6364 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006365 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006366 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006367 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006368 return null;
6369 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006370 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006371 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006372 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006373 return null;
6374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375
6376 final long identity = Binder.clearCallingIdentity();
6377 try {
6378 return phone.getDeviceId();
6379 } finally {
6380 Binder.restoreCallingIdentity(identity);
6381 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006382 }
6383
Ping Sunc67b7c22016-03-02 19:16:45 +08006384 /**
6385 * {@hide}
6386 * Returns the IMS Registration Status on a particular subid
6387 *
6388 * @param subId
6389 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006390 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006391 Phone phone = getPhone(subId);
6392 if (phone != null) {
6393 return phone.isImsRegistered();
6394 } else {
6395 return false;
6396 }
6397 }
6398
Santos Cordon7a1885b2015-02-03 11:15:19 -08006399 @Override
6400 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 final long identity = Binder.clearCallingIdentity();
6402 try {
6403 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6404 } finally {
6405 Binder.restoreCallingIdentity(identity);
6406 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006407 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006408
Tyler Gunnf70ed162019-04-03 15:28:53 -07006409 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006410 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006411 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006412 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006413 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006414 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6415 }
6416 final long identity = Binder.clearCallingIdentity();
6417 try {
6418 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6419 } finally {
6420 Binder.restoreCallingIdentity(identity);
6421 }
6422 }
6423
6424 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006425 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6426 final long identity = Binder.clearCallingIdentity();
6427 try {
6428 Phone phone = getPhone(subscriptionId);
6429 if (phone == null) {
6430 return null;
6431 }
6432 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435 }
6436 }
6437
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006438 /**
6439 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006440 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006441 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006442 final long identity = Binder.clearCallingIdentity();
6443 try {
6444 Phone phone = getPhone(subId);
6445 if (phone != null) {
6446 return phone.isWifiCallingEnabled();
6447 } else {
6448 return false;
6449 }
6450 } finally {
6451 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006452 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006453 }
6454
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006455 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006456 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006457 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006458 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006459 final long identity = Binder.clearCallingIdentity();
6460 try {
6461 Phone phone = getPhone(subId);
6462 if (phone != null) {
6463 return phone.isVideoEnabled();
6464 } else {
6465 return false;
6466 }
6467 } finally {
6468 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006469 }
6470 }
6471
6472 /**
6473 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6474 * defined in {@link ImsRegistrationImplBase}.
6475 */
6476 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477 final long identity = Binder.clearCallingIdentity();
6478 try {
6479 Phone phone = getPhone(subId);
6480 if (phone != null) {
6481 return phone.getImsRegistrationTech();
6482 } else {
6483 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6484 }
6485 } finally {
6486 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006487 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006488 }
6489
Stuart Scott8eef64f2015-04-08 15:13:54 -07006490 @Override
6491 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006492 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006493 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6494 return;
6495 }
6496
Svet Ganovcc087f82015-05-12 20:35:54 -07006497 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006498
Svet Ganovcc087f82015-05-12 20:35:54 -07006499 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006500 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6501 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006502 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006503 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006504 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006505 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6506 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006507 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006508 // There has been issues when Sms raw table somehow stores orphan
6509 // fragments. They lead to garbled message when new fragments come
6510 // in and combined with those stale ones. In case this happens again,
6511 // user can reset all network settings which will clean up this table.
6512 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006513 // Clean up IMS settings as well here.
6514 int slotId = getSlotIndex(subId);
6515 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6516 ImsManager.getInstance(mApp, slotId).factoryReset();
6517 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006518
6519 // Erase modem config if erase modem on network setting is enabled.
6520 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6521 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6522 if (configValue != null && Boolean.parseBoolean(configValue)) {
6523 sendEraseModemConfig(getDefaultPhone());
6524 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006525 } finally {
6526 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006527 }
6528 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006529
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006530 private void cleanUpSmsRawTable(Context context) {
6531 ContentResolver resolver = context.getContentResolver();
6532 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6533 resolver.delete(uri, null, null);
6534 }
6535
Narayan Kamath1c496c22015-04-16 14:40:19 +01006536 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006537 public String getSimLocaleForSubscriber(int subId) {
6538 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6539 final Phone phone = getPhone(subId);
6540 if (phone == null) {
6541 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006542 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544 final long identity = Binder.clearCallingIdentity();
6545 try {
chen xu5d3637b2019-01-21 23:31:38 -08006546 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006547 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006548 if (info == null) {
6549 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6550 return null;
6551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552 // Try and fetch the locale from the carrier properties or from the SIM language
6553 // preferences (EF-PL and EF-LI)...
6554 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006556 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6557 if (localeFromDefaultSim != null) {
6558 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6559 if (DBG) log("Using locale from subId: " + subId + " locale: "
6560 + localeFromDefaultSim);
6561 return localeFromDefaultSim.toLanguageTag();
6562 } else {
6563 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564 }
6565 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006566
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006567 // The SIM language preferences only store a language (e.g. fr = French), not an
6568 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6569 // the SIM and carrier preferences does not include a country we add the country
6570 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006571 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006573 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574 return mccLocale.toLanguageTag();
6575 }
6576
6577 if (DBG) log("No locale found - returning null");
6578 return null;
6579 } finally {
6580 Binder.restoreCallingIdentity(identity);
6581 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006582 }
6583
6584 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006585 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6586 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006587 }
6588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589 /**
6590 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6591 */
6592 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006593 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6594 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006595 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006596
Chenjie Yu1ba97252018-01-11 18:16:20 -08006597 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006598 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006599
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006600 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006601 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6602 * representing the state of the modem.
6603 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006604 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6605 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006606 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006607 */
6608 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006609 public void requestModemActivityInfo(ResultReceiver result) {
6610 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006611 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612
6613 final long identity = Binder.clearCallingIdentity();
6614 try {
sqian1a1be542020-03-05 11:37:28 -08006615 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616 } finally {
6617 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006618 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006619 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006620
Siddharth Rayb8114062018-06-17 15:02:38 -07006621 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6622 // less than total activity duration.
6623 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6624 if (info == null) {
6625 return false;
6626 }
6627 int activityDurationMs =
6628 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6629 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006630 int[] txTimeMs = info.getTransmitTimeMillis();
6631 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6632 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006633 }
6634 return (info.isValid()
6635 && (info.getSleepTimeMillis() <= activityDurationMs)
6636 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006637 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006638 && (totalTxTimeMs <= activityDurationMs));
6639 }
6640
Jack Yu85bd38a2015-11-09 11:34:32 -08006641 /**
6642 * {@hide}
6643 * Returns the service state information on specified subscription.
6644 */
6645 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006646 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6647 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006648 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006649 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006650 return null;
6651 }
6652
Hall Liuf19c44f2018-11-27 14:38:17 -08006653 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6654 LocationAccessPolicy.checkLocationPermission(mApp,
6655 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6656 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006657 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006658 .setCallingPid(Binder.getCallingPid())
6659 .setCallingUid(Binder.getCallingUid())
6660 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006661 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006662 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6663 .build());
6664
6665 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6666 LocationAccessPolicy.checkLocationPermission(mApp,
6667 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6668 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006669 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006670 .setCallingPid(Binder.getCallingPid())
6671 .setCallingUid(Binder.getCallingUid())
6672 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006673 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006674 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6675 .build());
6676 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6677 boolean hasFinePermission =
6678 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6679 boolean hasCoarsePermission =
6680 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6681
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006682 final long identity = Binder.clearCallingIdentity();
6683 try {
6684 final Phone phone = getPhone(subId);
6685 if (phone == null) {
6686 return null;
6687 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006688
Hall Liuf19c44f2018-11-27 14:38:17 -08006689 ServiceState ss = phone.getServiceState();
6690
6691 // Scrub out the location info in ServiceState depending on what level of access
6692 // the caller has.
6693 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006694 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6695 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006696 } finally {
6697 Binder.restoreCallingIdentity(identity);
6698 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006699 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006700
6701 /**
6702 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6703 *
6704 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6705 * voicemail ringtone.
6706 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6707 * PhoneAccount.
6708 */
6709 @Override
6710 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711 final long identity = Binder.clearCallingIdentity();
6712 try {
6713 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6714 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006715 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6719 } finally {
6720 Binder.restoreCallingIdentity(identity);
6721 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006722 }
6723
6724 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006725 * Sets the per-account voicemail ringtone.
6726 *
6727 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6728 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6729 *
6730 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6731 * voicemail ringtone.
6732 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6733 * PhoneAccount.
6734 */
6735 @Override
6736 public void setVoicemailRingtoneUri(String callingPackage,
6737 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006738 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006739 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006740 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6741 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6743 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6744 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746
6747 final long identity = Binder.clearCallingIdentity();
6748 try {
6749 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6750 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006751 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006752 }
6753 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6754 } finally {
6755 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006756 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006757 }
6758
6759 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006760 * Returns whether vibration is set for voicemail notification in Phone settings.
6761 *
6762 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6763 * voicemail vibration setting.
6764 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6765 */
6766 @Override
6767 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006768 final long identity = Binder.clearCallingIdentity();
6769 try {
6770 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6771 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006772 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006773 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6776 } finally {
6777 Binder.restoreCallingIdentity(identity);
6778 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006779 }
6780
Youhan Wange64578a2016-05-02 15:32:42 -07006781 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006782 * Sets the per-account voicemail vibration.
6783 *
6784 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6785 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6786 *
6787 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6788 * voicemail vibration setting.
6789 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6790 * specific PhoneAccount.
6791 */
6792 @Override
6793 public void setVoicemailVibrationEnabled(String callingPackage,
6794 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006795 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006796 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006797 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6798 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6800 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6801 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006802 }
6803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006804 final long identity = Binder.clearCallingIdentity();
6805 try {
6806 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6807 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006808 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006809 }
6810 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6811 } finally {
6812 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006813 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006814 }
6815
6816 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006817 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6818 *
6819 * @throws SecurityException if the caller does not have the required permission
6820 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006821 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006822 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006823 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006824 }
6825
6826 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006827 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6828 * permission.
6829 *
6830 * @throws SecurityException if the caller does not have the required permission
6831 */
6832 private void enforceSendSmsPermission() {
6833 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6834 }
6835
6836 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006837 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006838 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006839 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006840 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006841 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006842 final long identity = Binder.clearCallingIdentity();
6843 try {
6844 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006845 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006846 if (componentName == null) {
6847 throw new SecurityException(
6848 "Caller not current active visual voicemail package[null]");
6849 }
6850 String vvmPackage = componentName.getPackageName();
6851 if (!callingPackage.equals(vvmPackage)) {
6852 throw new SecurityException("Caller not current active visual voicemail package["
6853 + vvmPackage + "]");
6854 }
6855 } finally {
6856 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006857 }
6858 }
6859
6860 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006861 * Return the application ID for the app type.
6862 *
6863 * @param subId the subscription ID that this request applies to.
6864 * @param appType the uicc app type.
6865 * @return Application ID for specificied app type, or null if no uicc.
6866 */
6867 @Override
6868 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006869 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006870 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871
6872 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006873 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874 if (phone == null) {
6875 return null;
6876 }
6877 String aid = null;
6878 try {
6879 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6880 .getApplicationByType(appType).getAid();
6881 } catch (Exception e) {
6882 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6883 }
6884 return aid;
6885 } finally {
6886 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006887 }
Youhan Wange64578a2016-05-02 15:32:42 -07006888 }
6889
Youhan Wang4001d252016-05-11 10:29:41 -07006890 /**
6891 * Return the Electronic Serial Number.
6892 *
6893 * @param subId the subscription ID that this request applies to.
6894 * @return ESN or null if error.
6895 */
6896 @Override
6897 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006898 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006899 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006900
6901 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006902 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903 if (phone == null) {
6904 return null;
6905 }
6906 String esn = null;
6907 try {
6908 esn = phone.getEsn();
6909 } catch (Exception e) {
6910 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6911 }
6912 return esn;
6913 } finally {
6914 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006915 }
Youhan Wang4001d252016-05-11 10:29:41 -07006916 }
6917
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006918 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006919 * Return the Preferred Roaming List Version.
6920 *
6921 * @param subId the subscription ID that this request applies to.
6922 * @return PRLVersion or null if error.
6923 */
6924 @Override
6925 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006926 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006927 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928
6929 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006930 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006931 if (phone == null) {
6932 return null;
6933 }
6934 String cdmaPrlVersion = null;
6935 try {
6936 cdmaPrlVersion = phone.getCdmaPrlVersion();
6937 } catch (Exception e) {
6938 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6939 }
6940 return cdmaPrlVersion;
6941 } finally {
6942 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006943 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006944 }
6945
6946 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006947 * Get snapshot of Telephony histograms
6948 * @return List of Telephony histograms
6949 * @hide
6950 */
6951 @Override
6952 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6954 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006955
6956 final long identity = Binder.clearCallingIdentity();
6957 try {
6958 return RIL.getTelephonyRILTimingHistograms();
6959 } finally {
6960 Binder.restoreCallingIdentity(identity);
6961 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006962 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006963
6964 /**
6965 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006966 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6967 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006968 * Require system privileges. In the future we may add this to carrier APIs.
6969 *
Michele Berionne482f8202018-11-27 18:57:59 -08006970 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006971 */
6972 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006973 @TelephonyManager.SetCarrierRestrictionResult
6974 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006975 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006976 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006977
Michele Berionne482f8202018-11-27 18:57:59 -08006978 if (carrierRestrictionRules == null) {
6979 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006980 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 final long identity = Binder.clearCallingIdentity();
6983 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006984 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006985 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986 } finally {
6987 Binder.restoreCallingIdentity(identity);
6988 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006989 }
6990
6991 /**
6992 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006993 * Get the allowed carrier list and the excluded carrier list, including the priority between
6994 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006995 * Require system privileges. In the future we may add this to carrier APIs.
6996 *
Michele Berionne482f8202018-11-27 18:57:59 -08006997 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006998 */
6999 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007000 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007001 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007002 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003
7004 final long identity = Binder.clearCallingIdentity();
7005 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007006 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7007 if (response instanceof CarrierRestrictionRules) {
7008 return (CarrierRestrictionRules) response;
7009 }
7010 // Response is an Exception of some kind,
7011 // which is signalled to the user as a NULL retval
7012 return null;
7013 } catch (Exception e) {
7014 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7015 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007016 } finally {
7017 Binder.restoreCallingIdentity(identity);
7018 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007019 }
7020
fionaxu59545b42016-05-25 15:53:37 -07007021 /**
7022 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7023 * @param subId the subscription ID that this action applies to.
7024 * @param enabled control enable or disable metered apns.
7025 * {@hide}
7026 */
7027 @Override
7028 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7029 enforceModifyPermission();
7030 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031
7032 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007033 if (phone == null) {
7034 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7035 return;
7036 }
7037 try {
7038 phone.carrierActionSetMeteredApnsEnabled(enabled);
7039 } catch (Exception e) {
7040 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041 } finally {
7042 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007043 }
7044 }
7045
7046 /**
7047 * Action set from carrier signalling broadcast receivers to enable/disable radio
7048 * @param subId the subscription ID that this action applies to.
7049 * @param enabled control enable or disable radio.
7050 * {@hide}
7051 */
7052 @Override
7053 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7054 enforceModifyPermission();
7055 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007056
7057 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007058 if (phone == null) {
7059 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7060 return;
7061 }
7062 try {
7063 phone.carrierActionSetRadioEnabled(enabled);
7064 } catch (Exception e) {
7065 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007066 } finally {
7067 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007068 }
7069 }
7070
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007071 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007072 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7073 * network status based on which carrier apps could apply actions accordingly,
7074 * enable/disable default url handler for example.
7075 *
7076 * @param subId the subscription ID that this action applies to.
7077 * @param report control start/stop reporting the default network status.
7078 * {@hide}
7079 */
7080 @Override
7081 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7082 enforceModifyPermission();
7083 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084
7085 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007086 if (phone == null) {
7087 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7088 return;
7089 }
7090 try {
7091 phone.carrierActionReportDefaultNetworkStatus(report);
7092 } catch (Exception e) {
7093 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094 } finally {
7095 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007096 }
7097 }
7098
7099 /**
fionaxud9622282017-07-17 17:51:30 -07007100 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7101 * @param subId the subscription ID that this action applies to.
7102 * {@hide}
7103 */
7104 @Override
7105 public void carrierActionResetAll(int subId) {
7106 enforceModifyPermission();
7107 final Phone phone = getPhone(subId);
7108 if (phone == null) {
7109 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7110 return;
7111 }
7112 try {
7113 phone.carrierActionResetAll();
7114 } catch (Exception e) {
7115 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7116 }
7117 }
7118
7119 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007120 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7121 * bug report is being generated.
7122 */
7123 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007124 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007125 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7126 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007127 writer.println("Permission Denial: can't dump Phone from pid="
7128 + Binder.getCallingPid()
7129 + ", uid=" + Binder.getCallingUid()
7130 + "without permission "
7131 + android.Manifest.permission.DUMP);
7132 return;
7133 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007134 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007135 }
Jack Yueb89b242016-06-22 13:27:47 -07007136
Brad Ebingerdac2f002018-04-03 15:17:52 -07007137 @Override
7138 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7139 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7140 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007141 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7142 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007143 }
7144
Jack Yueb89b242016-06-22 13:27:47 -07007145 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007146 * Policy control of data connection. Usually used when data limit is passed.
7147 * @param enabled True if enabling the data, otherwise disabling.
7148 * @param subId Subscription index
7149 * {@hide}
7150 */
7151 @Override
7152 public void setPolicyDataEnabled(boolean enabled, int subId) {
7153 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154
7155 final long identity = Binder.clearCallingIdentity();
7156 try {
7157 Phone phone = getPhone(subId);
7158 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007159 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007160 }
7161 } finally {
7162 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007163 }
7164 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007165
7166 /**
7167 * Get Client request stats
7168 * @return List of Client Request Stats
7169 * @hide
7170 */
7171 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007172 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7173 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007175 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007176 return null;
7177 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007178 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007180 final long identity = Binder.clearCallingIdentity();
7181 try {
7182 if (phone != null) {
7183 return phone.getClientRequestStats();
7184 }
7185
7186 return null;
7187 } finally {
7188 Binder.restoreCallingIdentity(identity);
7189 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007190 }
7191
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007192 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007193 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007194 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007195 }
Jack Yueb4124c2017-02-16 15:32:43 -08007196
7197 /**
Grace Chen70990072017-03-24 17:21:30 -07007198 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007199 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007200 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007201 * @param state State of SIM (power down, power up, pass through)
7202 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7203 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7204 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007205 *
7206 **/
7207 @Override
Grace Chen70990072017-03-24 17:21:30 -07007208 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007209 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007210 Phone phone = PhoneFactory.getPhone(slotIndex);
7211
vagdeviaf9a5b92018-08-15 16:01:53 -07007212 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007214 final long identity = Binder.clearCallingIdentity();
7215 try {
7216 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007217 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007218 }
7219 } finally {
7220 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007221 }
7222 }
Shuo Qiandd210312017-04-12 22:11:33 +00007223
Tyler Gunn65d45c22017-06-05 11:22:26 -07007224 private boolean isUssdApiAllowed(int subId) {
7225 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007226 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007227 if (configManager == null) {
7228 return false;
7229 }
7230 PersistableBundle pb = configManager.getConfigForSubId(subId);
7231 if (pb == null) {
7232 return false;
7233 }
7234 return pb.getBoolean(
7235 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7236 }
7237
Shuo Qiandd210312017-04-12 22:11:33 +00007238 /**
7239 * Check if phone is in emergency callback mode
7240 * @return true if phone is in emergency callback mode
7241 * @param subId sub id
7242 */
goneil9c5f4872017-12-05 14:07:56 -08007243 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007244 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007245 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007246 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007247
7248 final long identity = Binder.clearCallingIdentity();
7249 try {
7250 if (phone != null) {
7251 return phone.isInEcm();
7252 } else {
7253 return false;
7254 }
7255 } finally {
7256 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007257 }
7258 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007259
7260 /**
7261 * Get the current signal strength information for the given subscription.
7262 * Because this information is not updated when the device is in a low power state
7263 * it should not be relied-upon to be current.
7264 * @param subId Subscription index
7265 * @return the most recent cached signal strength info from the modem
7266 */
7267 @Override
7268 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007269 final long identity = Binder.clearCallingIdentity();
7270 try {
7271 Phone p = getPhone(subId);
7272 if (p == null) {
7273 return null;
7274 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007276 return p.getSignalStrength();
7277 } finally {
7278 Binder.restoreCallingIdentity(identity);
7279 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007280 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007281
Pengquan Meng77b7f132018-08-22 14:49:57 -07007282 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007283 * Get the current modem radio state for the given slot.
7284 * @param slotIndex slot index.
7285 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007286 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007287 * @return the current radio power state from the modem
7288 */
7289 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007290 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007291 Phone phone = PhoneFactory.getPhone(slotIndex);
7292 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7294 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007295 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7296 }
7297
7298 final long identity = Binder.clearCallingIdentity();
7299 try {
7300 return phone.getRadioPowerState();
7301 } finally {
7302 Binder.restoreCallingIdentity(identity);
7303 }
7304 }
7305 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7306 }
7307
7308 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007309 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7310 *
7311 * <p>Requires one of the following permissions:
7312 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7313 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7314 * privileges.
7315 *
7316 * @param subId subscription id
7317 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7318 * {@code false}.
7319 */
7320 @Override
7321 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007322 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7323 null /* message */);
7324
Pengquan Menga1bb6272018-09-06 09:59:22 -07007325 boolean isEnabled = false;
7326 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007327 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007328 Phone phone = getPhone(subId);
7329 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007330 } catch (Exception e) {
7331 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7332 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007333 } finally {
7334 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007335 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007336 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007337 }
7338
7339
7340 /**
7341 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7342 *
7343 * <p> Requires permission:
7344 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7345 * privileges.
7346 *
7347 * @param subId subscription id
7348 * @param isEnabled {@code true} means enable, {@code false} means disable.
7349 */
7350 @Override
7351 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7353 mApp, subId, "setDataRoamingEnabled");
7354
Pengquan Menga1bb6272018-09-06 09:59:22 -07007355 final long identity = Binder.clearCallingIdentity();
7356 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007357 Phone phone = getPhone(subId);
7358 if (phone != null) {
7359 phone.setDataRoamingEnabled(isEnabled);
7360 }
7361 } finally {
7362 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007363 }
7364 }
7365
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007366 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007367 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007368 TelephonyPermissions
7369 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007370 mApp, subId, "isManualNetworkSelectionAllowed");
7371
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007372 boolean isAllowed = true;
7373 final long identity = Binder.clearCallingIdentity();
7374 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007375 Phone phone = getPhone(subId);
7376 if (phone != null) {
7377 isAllowed = phone.isCspPlmnEnabled();
7378 }
7379 } finally {
7380 Binder.restoreCallingIdentity(identity);
7381 }
7382 return isAllowed;
7383 }
7384
7385 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007386 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007387 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007388 try {
7389 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007390 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007391 } catch (SecurityException e) {
7392 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7393 // has carrier privileges on an active UICC
7394 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7395 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007396 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007397 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007398 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007399
7400 final long identity = Binder.clearCallingIdentity();
7401 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007402 UiccController uiccController = UiccController.getInstance();
7403 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007404 if (hasReadPermission) {
7405 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007406 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007407
7408 // Remove private info if the caller doesn't have access
7409 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7410 for (UiccCardInfo cardInfo : cardInfos) {
7411 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7412 // is available
7413 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7414 if (card == null || card.getUiccProfile() == null) {
7415 // assume no access if the card or profile is unavailable
7416 filteredInfos.add(cardInfo.getUnprivileged());
7417 continue;
7418 }
7419 UiccProfile profile = card.getUiccProfile();
7420 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7421 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7422 filteredInfos.add(cardInfo);
7423 } else {
7424 filteredInfos.add(cardInfo.getUnprivileged());
7425 }
7426 }
7427 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007428 } finally {
7429 Binder.restoreCallingIdentity(identity);
7430 }
7431 }
7432
7433 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007434 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007435 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 final long identity = Binder.clearCallingIdentity();
7438 try {
7439 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7440 if (slots == null) {
7441 Rlog.i(LOG_TAG, "slots is null.");
7442 return null;
7443 }
7444
7445 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7446 for (int i = 0; i < slots.length; i++) {
7447 UiccSlot slot = slots[i];
7448 if (slot == null) {
7449 continue;
7450 }
7451
Jordan Liu7be7e652019-05-06 18:55:02 +00007452 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007453 UiccCard card = slot.getUiccCard();
7454 if (card != null) {
7455 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007456 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007457 cardId = slot.getEid();
7458 if (TextUtils.isEmpty(cardId)) {
7459 cardId = slot.getIccId();
7460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 }
7462
Jordan Liu857451f2019-05-09 16:35:35 -07007463 if (cardId != null) {
7464 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7465 // if cardId is an EID, it's all digits so this is fine
7466 cardId = IccUtils.stripTrailingFs(cardId);
7467 }
7468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007469 int cardState = 0;
7470 switch (slot.getCardState()) {
7471 case CARDSTATE_ABSENT:
7472 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7473 break;
7474 case CARDSTATE_PRESENT:
7475 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7476 break;
7477 case CARDSTATE_ERROR:
7478 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7479 break;
7480 case CARDSTATE_RESTRICTED:
7481 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7482 break;
7483 default:
7484 break;
7485
7486 }
7487
7488 infos[i] = new UiccSlotInfo(
7489 slot.isActive(),
7490 slot.isEuicc(),
7491 cardId,
7492 cardState,
7493 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007494 slot.isExtendedApduSupported(),
7495 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007496 }
7497 return infos;
7498 } finally {
7499 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007500 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007501 }
7502
7503 @Override
7504 public boolean switchSlots(int[] physicalSlots) {
7505 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007506
7507 final long identity = Binder.clearCallingIdentity();
7508 try {
7509 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7510 } finally {
7511 Binder.restoreCallingIdentity(identity);
7512 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007513 }
Jack Yu4c988042018-02-27 15:30:01 -08007514
7515 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007516 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007517 final long identity = Binder.clearCallingIdentity();
7518 try {
7519 return UiccController.getInstance().getCardIdForDefaultEuicc();
7520 } finally {
7521 Binder.restoreCallingIdentity(identity);
7522 }
7523 }
7524
7525 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007526 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7527 enforceModifyPermission();
7528 final Phone phone = getPhone(subId);
7529 if (phone == null) {
7530 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7531 return;
7532 }
7533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 final long identity = Binder.clearCallingIdentity();
7535 try {
7536 phone.setRadioIndicationUpdateMode(filters, mode);
7537 } finally {
7538 Binder.restoreCallingIdentity(identity);
7539 }
Jack Yu4c988042018-02-27 15:30:01 -08007540 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007541
7542 /**
goneil47ffb6e2018-04-06 15:40:58 -07007543 * A test API to reload the UICC profile.
7544 *
7545 * <p>Requires that the calling app has permission
7546 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7547 * @hide
7548 */
7549 @Override
7550 public void refreshUiccProfile(int subId) {
7551 enforceModifyPermission();
7552
7553 final long identity = Binder.clearCallingIdentity();
7554 try {
7555 Phone phone = getPhone(subId);
7556 if (phone == null) {
7557 return;
7558 }
7559 UiccCard uiccCard = phone.getUiccCard();
7560 if (uiccCard == null) {
7561 return;
7562 }
7563 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7564 if (uiccProfile == null) {
7565 return;
7566 }
7567 uiccProfile.refresh();
7568 } finally {
7569 Binder.restoreCallingIdentity(identity);
7570 }
7571 }
7572
7573 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007574 * Returns false if the mobile data is disabled by default, otherwise return true.
7575 */
7576 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007577 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007578 }
7579
7580 /**
7581 * Returns true if the data roaming is enabled by default, i.e the system property
7582 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7583 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7584 */
7585 private boolean getDefaultDataRoamingEnabled(int subId) {
7586 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007587 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007588 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007589 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7590 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7591 return isDataRoamingEnabled;
7592 }
7593
7594 /**
7595 * Returns the default network type for the given {@code subId}, if the default network type is
7596 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7597 */
7598 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007599 List<Integer> list = TelephonyProperties.default_network();
7600 int phoneId = mSubscriptionController.getPhoneId(subId);
7601 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7602 return list.get(phoneId);
7603 }
7604 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007605 }
fionaxua13278b2018-03-21 00:08:13 -07007606
7607 @Override
7608 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007609 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007610 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007611
7612 final long identity = Binder.clearCallingIdentity();
7613 try {
7614 final Phone phone = getPhone(subId);
7615 if (phone == null) {
7616 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7617 return;
7618 }
chen xueaba88a2019-03-15 13:15:10 -07007619 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7620 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007621 } finally {
7622 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007623 }
fionaxua13278b2018-03-21 00:08:13 -07007624 }
7625
7626 @Override
7627 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007628 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007629
7630 final long identity = Binder.clearCallingIdentity();
7631 try {
7632 final Phone phone = getPhone(subId);
7633 if (phone == null) {
7634 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7635 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7636 }
7637 return phone.getCarrierIdListVersion();
7638 } finally {
7639 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007640 }
fionaxua13278b2018-03-21 00:08:13 -07007641 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007642
7643 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007644 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7645 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007646 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007647 mApp, subId, callingPackage, callingFeatureId,
7648 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007649 return -1;
7650 }
7651
7652 final long identity = Binder.clearCallingIdentity();
7653 try {
7654 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7655 } finally {
7656 Binder.restoreCallingIdentity(identity);
7657 }
7658 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007659
7660 @Override
7661 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007662 TelephonyPermissions
7663 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007664 mApp, subId, "getCdmaRoamingMode");
7665
7666 final long identity = Binder.clearCallingIdentity();
7667 try {
7668 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7669 } finally {
7670 Binder.restoreCallingIdentity(identity);
7671 }
7672 }
7673
7674 @Override
7675 public boolean setCdmaRoamingMode(int subId, int mode) {
7676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7677 mApp, subId, "setCdmaRoamingMode");
7678
7679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7682 } finally {
7683 Binder.restoreCallingIdentity(identity);
7684 }
7685 }
7686
7687 @Override
7688 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7690 mApp, subId, "setCdmaSubscriptionMode");
7691
7692 final long identity = Binder.clearCallingIdentity();
7693 try {
7694 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7695 } finally {
7696 Binder.restoreCallingIdentity(identity);
7697 }
7698 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007699
sqianc5eccab2018-10-19 18:46:41 -07007700 @Override
sqian8c685422019-02-22 15:55:18 -08007701 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007702 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007704 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7705 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007706 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7707 }
7708 final long identity = Binder.clearCallingIdentity();
7709 try {
sqian854d44b2018-12-12 16:48:18 -08007710 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7711 for (Phone phone: PhoneFactory.getPhones()) {
7712 if (phone.getEmergencyNumberTracker() != null
7713 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7714 emergencyNumberListInternal.put(
7715 phone.getSubId(),
7716 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7717 }
sqian11b7a0e2018-12-05 18:48:28 -08007718 }
sqian854d44b2018-12-12 16:48:18 -08007719 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007720 } finally {
7721 Binder.restoreCallingIdentity(identity);
7722 }
sqianc5eccab2018-10-19 18:46:41 -07007723 }
7724
7725 @Override
sqian8c685422019-02-22 15:55:18 -08007726 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007727 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007728 if (!exactMatch) {
7729 TelephonyPermissions
7730 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007731 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007732 }
7733 final long identity = Binder.clearCallingIdentity();
7734 try {
sqian854d44b2018-12-12 16:48:18 -08007735 for (Phone phone: PhoneFactory.getPhones()) {
7736 if (phone.getEmergencyNumberTracker() != null
7737 && phone.getEmergencyNumberTracker() != null) {
7738 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7739 number, exactMatch)) {
7740 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007741 }
7742 }
sqian11b7a0e2018-12-05 18:48:28 -08007743 }
7744 return false;
7745 } finally {
7746 Binder.restoreCallingIdentity(identity);
7747 }
7748 }
7749
sqianf4ca7ed2019-01-15 18:32:07 -08007750 /**
7751 * Update emergency number list for test mode.
7752 */
7753 @Override
7754 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7755 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7756 "updateEmergencyNumberListTestMode");
7757
7758 final long identity = Binder.clearCallingIdentity();
7759 try {
7760 for (Phone phone: PhoneFactory.getPhones()) {
7761 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7762 if (tracker != null) {
7763 tracker.executeEmergencyNumberTestModeCommand(action, num);
7764 }
7765 }
7766 } finally {
7767 Binder.restoreCallingIdentity(identity);
7768 }
7769 }
7770
7771 /**
7772 * Get the full emergency number list for test mode.
7773 */
7774 @Override
7775 public List<String> getEmergencyNumberListTestMode() {
7776 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7777 "getEmergencyNumberListTestMode");
7778
7779 final long identity = Binder.clearCallingIdentity();
7780 try {
7781 Set<String> emergencyNumbers = new HashSet<>();
7782 for (Phone phone: PhoneFactory.getPhones()) {
7783 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7784 if (tracker != null) {
7785 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7786 emergencyNumbers.add(num.getNumber());
7787 }
7788 }
7789 }
7790 return new ArrayList<>(emergencyNumbers);
7791 } finally {
7792 Binder.restoreCallingIdentity(identity);
7793 }
7794 }
7795
chen xud6b45bd2018-10-30 22:27:10 -07007796 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007797 public int getEmergencyNumberDbVersion(int subId) {
7798 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7799
7800 final long identity = Binder.clearCallingIdentity();
7801 try {
7802 final Phone phone = getPhone(subId);
7803 if (phone == null) {
7804 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7805 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7806 }
7807 return phone.getEmergencyNumberDbVersion();
7808 } finally {
7809 Binder.restoreCallingIdentity(identity);
7810 }
7811 }
7812
7813 @Override
7814 public void notifyOtaEmergencyNumberDbInstalled() {
7815 enforceModifyPermission();
7816
7817 final long identity = Binder.clearCallingIdentity();
7818 try {
7819 for (Phone phone: PhoneFactory.getPhones()) {
7820 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7821 if (tracker != null) {
7822 tracker.updateOtaEmergencyNumberDatabase();
7823 }
7824 }
7825 } finally {
7826 Binder.restoreCallingIdentity(identity);
7827 }
7828 }
7829
7830 @Override
7831 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7832 enforceActiveEmergencySessionPermission();
7833
7834 final long identity = Binder.clearCallingIdentity();
7835 try {
7836 for (Phone phone: PhoneFactory.getPhones()) {
7837 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7838 if (tracker != null) {
7839 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7840 }
7841 }
7842 } finally {
7843 Binder.restoreCallingIdentity(identity);
7844 }
7845 }
7846
7847 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007848 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7849 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7850 Phone phone = getPhone(subId);
7851 if (phone == null) {
7852 return null;
7853 }
7854 final long identity = Binder.clearCallingIdentity();
7855 try {
7856 UiccProfile profile = UiccController.getInstance()
7857 .getUiccProfileForPhone(phone.getPhoneId());
7858 if (profile != null) {
7859 return profile.getCertsFromCarrierPrivilegeAccessRules();
7860 }
7861 } finally {
7862 Binder.restoreCallingIdentity(identity);
7863 }
7864 return null;
7865 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007866
7867 /**
7868 * Enable or disable a modem stack.
7869 */
7870 @Override
7871 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7872 enforceModifyPermission();
7873
7874 final long identity = Binder.clearCallingIdentity();
7875 try {
7876 Phone phone = PhoneFactory.getPhone(slotIndex);
7877 if (phone == null) {
7878 return false;
7879 } else {
7880 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7881 }
7882 } finally {
7883 Binder.restoreCallingIdentity(identity);
7884 }
7885 }
Michelecea4cf22018-12-21 15:00:11 -08007886
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007887 /**
7888 * Whether a modem stack is enabled or not.
7889 */
7890 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007891 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7892 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007893 Phone phone = PhoneFactory.getPhone(slotIndex);
7894 if (phone == null) return false;
7895
7896 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007897 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7898 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007899 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7900 }
7901
7902 final long identity = Binder.clearCallingIdentity();
7903 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007904 try {
7905 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7906 } catch (NoSuchElementException ex) {
7907 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7908 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007909 } finally {
7910 Binder.restoreCallingIdentity(identity);
7911 }
7912 }
7913
Michelecea4cf22018-12-21 15:00:11 -08007914 @Override
Michele0ea7d782019-03-19 14:58:42 -07007915 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007916 enforceModifyPermission();
7917
7918 final long identity = Binder.clearCallingIdentity();
7919 try {
7920 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007921 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007922 .commit();
7923 } finally {
7924 Binder.restoreCallingIdentity(identity);
7925 }
7926 }
7927
7928 @Override
Michele0ea7d782019-03-19 14:58:42 -07007929 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007930 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007931 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007932 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7933 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007934 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007935 }
Michelecea4cf22018-12-21 15:00:11 -08007936
7937 final long identity = Binder.clearCallingIdentity();
7938 try {
Michele0ea7d782019-03-19 14:58:42 -07007939 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007940 } finally {
7941 Binder.restoreCallingIdentity(identity);
7942 }
7943 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007944
Michele0ea7d782019-03-19 14:58:42 -07007945 @TelephonyManager.IsMultiSimSupportedResult
7946 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007947 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7948 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7949 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007950 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7951 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007952 }
7953 // Check if the hardware supports multisim functionality. If usage of multisim is not
7954 // supported by the modem, indicate that it is restricted.
7955 PhoneCapability staticCapability =
7956 mPhoneConfigurationManager.getStaticPhoneCapability();
7957 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007958 loge("isMultiSimSupportedInternal: no static configuration available");
7959 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007960 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00007961 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007962 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7963 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007964 }
7965 // Check if support of multiple SIMs is restricted by carrier
7966 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007967 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007968 }
7969
Michele0ea7d782019-03-19 14:58:42 -07007970 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007971 }
7972
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007973 /**
7974 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007975 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7976 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7977 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007978 * @param numOfSims number of active sims we want to switch to
7979 */
7980 @Override
7981 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007982 if (numOfSims == 1) {
7983 enforceModifyPermission();
7984 } else {
7985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7986 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7987 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007988 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007989
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007990 try {
Michele30b57b22019-03-01 12:01:14 -08007991 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007992 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007993 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7994 return;
7995 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007996 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7997 } finally {
7998 Binder.restoreCallingIdentity(identity);
7999 }
8000 }
8001
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008002 @Override
8003 public boolean isApplicationOnUicc(int subId, int appType) {
8004 enforceReadPrivilegedPermission("isApplicationOnUicc");
8005 Phone phone = getPhone(subId);
8006 if (phone == null) {
8007 return false;
8008 }
8009 final long identity = Binder.clearCallingIdentity();
8010 try {
8011 UiccCard uiccCard = phone.getUiccCard();
8012 if (uiccCard == null) {
8013 return false;
8014 }
8015 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8016 if (uiccProfile == null) {
8017 return false;
8018 }
8019 if (TelephonyManager.APPTYPE_SIM <= appType
8020 && appType <= TelephonyManager.APPTYPE_ISIM) {
8021 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8022 }
8023 return false;
8024 } finally {
8025 Binder.restoreCallingIdentity(identity);
8026 }
8027 }
8028
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008029 /**
chen xub4baa772019-04-03 10:23:41 -07008030 * Get whether making changes to modem configurations will trigger reboot.
8031 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008032 */
8033 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008034 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8035 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008037 mApp, subId, callingPackage, callingFeatureId,
8038 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008039 return false;
8040 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008041 final long identity = Binder.clearCallingIdentity();
8042 try {
8043 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8044 } finally {
8045 Binder.restoreCallingIdentity(identity);
8046 }
8047 }
8048
Nathan Harold29f5f052019-02-15 13:41:57 -08008049 private void updateModemStateMetrics() {
8050 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8051 // TODO: check the state for each modem if the api is ready.
8052 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8053 }
8054
Pengquan Meng3889a572019-01-23 11:16:29 -08008055 @Override
8056 public int[] getSlotsMapping() {
8057 enforceReadPrivilegedPermission("getSlotsMapping");
8058
8059 final long identity = Binder.clearCallingIdentity();
8060 try {
8061 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8062 // All logical slots should have a mapping to a physical slot.
8063 int[] logicalSlotsMapping = new int[phoneCount];
8064 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8065 for (int i = 0; i < slotInfos.length; i++) {
8066 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8067 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8068 }
8069 }
8070 return logicalSlotsMapping;
8071 } finally {
8072 Binder.restoreCallingIdentity(identity);
8073 }
8074 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008075
8076 /**
8077 * Get the IRadio HAL Version
8078 */
8079 @Override
8080 public int getRadioHalVersion() {
8081 Phone phone = getDefaultPhone();
8082 if (phone == null) return -1;
8083 HalVersion hv = phone.getHalVersion();
8084 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8085 return hv.major * 100 + hv.minor;
8086 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008087
8088 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008089 * Get the current calling package name.
8090 * @return the current calling package name
8091 */
8092 @Override
8093 public String getCurrentPackageName() {
8094 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8095 }
8096
8097 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008098 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8099 * corresponding network requests on a subId.
8100 *
8101 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008102 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008103 * 2) APN is un-metered for this subscription, or
8104 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008105 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008106 *
8107 * @return whether data is allowed for a apn type.
8108 *
8109 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008110 */
8111 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008112 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008113 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8114 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008115
8116 // Now that all security checks passes, perform the operation as ourselves.
8117 final long identity = Binder.clearCallingIdentity();
8118 try {
8119 Phone phone = getPhone(subId);
8120 if (phone == null) return false;
8121
Jack Yu41407ee2019-05-13 16:54:09 -07008122 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008123 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8124 } finally {
8125 Binder.restoreCallingIdentity(identity);
8126 }
8127 }
8128
8129 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008130 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008131 enforceReadPrivilegedPermission("isApnMetered");
8132
8133 // Now that all security checks passes, perform the operation as ourselves.
8134 final long identity = Binder.clearCallingIdentity();
8135 try {
8136 Phone phone = getPhone(subId);
8137 if (phone == null) return true; // By default return true.
8138
Jack Yu41407ee2019-05-13 16:54:09 -07008139 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008140 } finally {
8141 Binder.restoreCallingIdentity(identity);
8142 }
8143 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008144
8145 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008146 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8147 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8148 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8149 if (iccRecords == null) {
8150 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8151 return false;
8152 }
8153 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8154 }
8155
8156 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008157 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008158 if (callingPackage == null) {
8159 callingPackage = getCurrentPackageName();
8160 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008161 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8162 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8163 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8164 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8165 }
8166 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8167 Intent intent = new Intent();
8168 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8169 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8170 // Bring up choose default SMS subscription dialog right now
8171 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8172 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8173 mApp.startActivity(intent);
8174 }
chen xud5ca2d52019-05-28 15:20:57 -07008175
8176 @Override
8177 public String getMmsUAProfUrl(int subId) {
8178 //TODO investigate if this API should require proper permission check in R b/133791609
8179 final long identity = Binder.clearCallingIdentity();
8180 try {
8181 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8182 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8183 } finally {
8184 Binder.restoreCallingIdentity(identity);
8185 }
8186 }
8187
8188 @Override
8189 public String getMmsUserAgent(int subId) {
8190 //TODO investigate if this API should require proper permission check in R b/133791609
8191 final long identity = Binder.clearCallingIdentity();
8192 try {
8193 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8194 .getString(com.android.internal.R.string.config_mms_user_agent);
8195 } finally {
8196 Binder.restoreCallingIdentity(identity);
8197 }
8198 }
Jack Yub07d4972019-05-28 16:12:25 -07008199
8200 @Override
8201 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8202 enforceModifyPermission();
8203
8204 // Now that all security checks passes, perform the operation as ourselves.
8205 final long identity = Binder.clearCallingIdentity();
8206 try {
8207 Phone phone = getPhone(subId);
8208 if (phone == null) return false;
8209
8210 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8211 } finally {
8212 Binder.restoreCallingIdentity(identity);
8213 }
8214 }
8215
8216 @Override
8217 public boolean isDataAllowedInVoiceCall(int subId) {
8218 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8219
8220 // Now that all security checks passes, perform the operation as ourselves.
8221 final long identity = Binder.clearCallingIdentity();
8222 try {
8223 Phone phone = getPhone(subId);
8224 if (phone == null) return false;
8225
8226 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8227 } finally {
8228 Binder.restoreCallingIdentity(identity);
8229 }
8230 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008231
changbetty97defcf2019-12-24 15:40:37 +08008232 @Override
8233 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8234 enforceModifyPermission();
8235
8236 // Now that all security checks passes, perform the operation as ourselves.
8237 final long identity = Binder.clearCallingIdentity();
8238 try {
8239 Phone phone = getPhone(subId);
8240 if (phone == null) return false;
8241
8242 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8243 } finally {
8244 Binder.restoreCallingIdentity(identity);
8245 }
8246 }
8247
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008248 /**
8249 * Updates whether conference event pacakge handling is enabled.
8250 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8251 * otherwise.
8252 */
8253 @Override
8254 public void setCepEnabled(boolean isCepEnabled) {
8255 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8256
8257 final long identity = Binder.clearCallingIdentity();
8258 try {
8259 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8260 for (Phone phone : PhoneFactory.getPhones()) {
8261 Phone defaultPhone = phone.getImsPhone();
8262 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8263 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8264 ImsPhoneCallTracker imsPhoneCallTracker =
8265 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8266 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8267 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8268 + imsPhone.getMsisdn());
8269 }
8270 }
8271 } finally {
8272 Binder.restoreCallingIdentity(identity);
8273 }
8274 }
allenwtsu46dcc572020-01-08 18:24:03 +08008275
8276 /**
8277 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8278 *
8279 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8280 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8281 * before being read.
8282 */
8283 @Override
8284 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8285 isCompressed) {
8286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8287 mApp, subId, "notifyRcsAutoConfigurationReceived");
8288 try {
8289 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8290 if (configBinder == null) {
8291 Rlog.e(LOG_TAG, "null result for getImsConfig");
8292 } else {
8293 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8294 }
8295 } catch (RemoteException e) {
8296 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8297 }
8298 }
zoey chenf95ca592019-12-30 16:11:23 +08008299
8300 @Override
8301 public boolean isIccLockEnabled(int subId) {
8302 enforceReadPrivilegedPermission("isIccLockEnabled");
8303
8304 // Now that all security checks passes, perform the operation as ourselves.
8305 final long identity = Binder.clearCallingIdentity();
8306 try {
8307 Phone phone = getPhone(subId);
8308 if (phone != null && phone.getIccCard() != null) {
8309 return phone.getIccCard().getIccLockEnabled();
8310 } else {
8311 return false;
8312 }
8313 } finally {
8314 Binder.restoreCallingIdentity(identity);
8315 }
8316 }
8317
8318 /**
8319 * Set the ICC pin lock enabled or disabled..
8320 *
8321 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8322 * 0 or a positive integer as the attempts remaining value.
8323 *
8324 */
8325 @Override
8326 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8327 enforceModifyPermission();
8328
8329 Phone phone = getPhone(subId);
8330 if (phone == null) {
8331 return 0;
8332 }
8333 // Now that all security checks passes, perform the operation as ourselves.
8334 final long identity = Binder.clearCallingIdentity();
8335 try {
8336 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8337 new Pair<Boolean, String>(enabled, password), phone, null);
8338 return attemptsRemaining;
8339
8340 } catch (Exception e) {
8341 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8342 } finally {
8343 Binder.restoreCallingIdentity(identity);
8344 }
8345 return 0;
8346 }
8347
8348 /**
8349 * Change the ICC password used in ICC pin lock.
8350 *
8351 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8352 * 0 or a positive integer as the attempts remaining value.
8353 *
8354 */
8355 @Override
8356 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8357 enforceModifyPermission();
8358
8359 Phone phone = getPhone(subId);
8360 if (phone == null) {
8361 return 0;
8362 }
8363 // Now that all security checks passes, perform the operation as ourselves.
8364 final long identity = Binder.clearCallingIdentity();
8365 try {
8366 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8367 new Pair<String, String>(oldPassword, newPassword), phone, null);
8368 return attemptsRemaining;
8369
8370 } catch (Exception e) {
8371 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8372 } finally {
8373 Binder.restoreCallingIdentity(identity);
8374 }
8375 return 0;
8376 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008377}