blob: 6ce15a8828ec174a252fc47559e7dd0d96906964 [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;
Shuo Qianb15c6be2020-03-05 17:55:34 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070055import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070056import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070058import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070059import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070060import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070061import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080062import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070063import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090064import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080065import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080066import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070067import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070068import android.telephony.Annotation.ApnType;
sqian80370722020-01-29 15:02:51 -080069import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070079import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070080import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080081import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070082import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080083import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070084import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080085import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080086import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070087import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080088import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080090import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080091import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080092import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070093import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070094import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080095import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080096import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000097import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070098import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070099import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800100import android.telephony.data.ApnSetting;
101import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700102import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800103import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700104import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700105import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700107import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800108import android.telephony.ims.aidl.IImsMmTelFeature;
109import android.telephony.ims.aidl.IImsRcsFeature;
110import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700111import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700112import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800114import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800115import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800116import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800120import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
sqian80370722020-01-29 15:02:51 -0800124import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700126import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700127import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800128import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700129import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700130import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800131import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800133import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800134import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700135import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800136import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800138import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700140import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700141import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700143import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800144import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700145import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700146import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700147import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700148import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700149import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700150import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700151import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800153import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800154import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700155import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800156import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700157import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800158import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700159import com.android.internal.telephony.imsphone.ImsPhone;
160import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800161import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900162import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800164import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700167import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800168import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800170import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000171import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800172import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700173import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800174import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700175import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700176import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800177import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700178import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700179import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800180import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800181
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700182import java.io.FileDescriptor;
183import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800185import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800186import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800188import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100189import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800190import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700191import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800192import java.util.Set;
Hall Liud0d1dc92020-01-20 13:42:00 -0800193import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194
195/**
196 * Implementation of the ITelephony interface.
197 */
Santos Cordon117fee72014-05-16 17:56:12 -0700198public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199 private static final String LOG_TAG = "PhoneInterfaceManager";
200 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
201 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800202 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700203
204 // Message codes used with mMainThreadHandler
205 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700206 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
207 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700208 private static final int CMD_OPEN_CHANNEL = 9;
209 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
210 private static final int CMD_CLOSE_CHANNEL = 11;
211 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800212 private static final int CMD_NV_READ_ITEM = 13;
213 private static final int EVENT_NV_READ_ITEM_DONE = 14;
214 private static final int CMD_NV_WRITE_ITEM = 15;
215 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
216 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
217 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700218 private static final int CMD_RESET_MODEM_CONFIG = 19;
219 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800220 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
221 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
222 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
223 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800224 private static final int CMD_SEND_ENVELOPE = 25;
225 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000226 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
227 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700228 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
229 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
230 private static final int CMD_EXCHANGE_SIM_IO = 31;
231 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800232 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
233 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700234 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
235 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700236 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
237 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700238 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
239 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
240 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
241 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700242 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
243 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
244 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
245 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700246 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800247 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
248 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000249 private static final int CMD_SWITCH_SLOTS = 50;
250 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700251 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
252 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
253 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
254 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
255 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
256 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
257 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
258 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700259 private static final int CMD_GET_ALL_CELL_INFO = 60;
260 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
261 private static final int CMD_GET_CELL_LOCATION = 62;
262 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700263 private static final int CMD_MODEM_REBOOT = 64;
264 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700265 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
266 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800267 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
268 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700269 private static final int CMD_GET_MODEM_STATUS = 70;
270 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700271 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
272 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700273 private static final int CMD_ERASE_MODEM_CONFIG = 74;
274 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800275 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
276 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
277 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
278 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800279 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
280 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
sqian80370722020-01-29 15:02:51 -0800281 private static final int CMD_GET_CALL_FORWARDING = 83;
282 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
283 private static final int CMD_SET_CALL_FORWARDING = 85;
284 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
285 private static final int CMD_GET_CALL_WAITING = 87;
286 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
287 private static final int CMD_SET_CALL_WAITING = 89;
288 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800290 // Parameters of select command.
291 private static final int SELECT_COMMAND = 0xA4;
292 private static final int SELECT_P1 = 0x04;
293 private static final int SELECT_P2 = 0;
294 private static final int SELECT_P3 = 0x10;
295
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296 /** The singleton instance. */
297 private static PhoneInterfaceManager sInstance;
298
Wink Saville3ab207e2014-11-20 13:07:20 -0800299 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800300 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800301 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700302 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800303 private AppOpsManager mAppOps;
304 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800305 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800306 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700307 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700308
Derek Tan97ebb422014-09-05 16:55:38 -0700309 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
310 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800311 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800312 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700313
Michelecea4cf22018-12-21 15:00:11 -0800314 // String to store multi SIM allowed
315 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
316
Derek Tan740e1672017-06-27 14:56:27 -0700317 // The AID of ISD-R.
318 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
319
yinxub1bed742017-04-17 11:45:04 -0700320 private NetworkScanRequestTracker mNetworkScanRequestTracker;
321
David Kelly5e06a7f2018-03-12 14:10:59 +0000322 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
323 private static final int MANUFACTURER_CODE_LENGTH = 8;
324
Derek Tan89e89d42014-07-08 17:00:10 -0700325 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700326 * Experiment flag to enable erase modem config on reset network, default value is false
327 */
328 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
329 "reset_network_erase_modem_config_enabled";
330
331 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700332 * A request object to use for transmitting data to an ICC.
333 */
334 private static final class IccAPDUArgument {
335 public int channel, cla, command, p1, p2, p3;
336 public String data;
337
338 public IccAPDUArgument(int channel, int cla, int command,
339 int p1, int p2, int p3, String data) {
340 this.channel = channel;
341 this.cla = cla;
342 this.command = command;
343 this.p1 = p1;
344 this.p2 = p2;
345 this.p3 = p3;
346 this.data = data;
347 }
348 }
349
350 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700351 * A request object to use for transmitting data to an ICC.
352 */
353 private static final class ManualNetworkSelectionArgument {
354 public OperatorInfo operatorInfo;
355 public boolean persistSelection;
356
357 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
358 this.operatorInfo = operatorInfo;
359 this.persistSelection = persistSelection;
360 }
361 }
362
363 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
365 * request after sending. The main thread will notify the request when it is complete.
366 */
367 private static final class MainThreadRequest {
368 /** The argument to use for the request */
369 public Object argument;
370 /** The result of the request that is run on the main thread */
371 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800372 // The subscriber id that this request applies to. Defaults to
373 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
374 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375
Nathan Harold92bed182018-10-12 18:16:49 -0700376 // In cases where subId is unavailable, the caller needs to specify the phone.
377 public Phone phone;
378
vagdeviaf9a5b92018-08-15 16:01:53 -0700379 public WorkSource workSource;
380
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 public MainThreadRequest(Object argument) {
382 this.argument = argument;
383 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800384
Nathan Harold92bed182018-10-12 18:16:49 -0700385 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
386 this.argument = argument;
387 if (phone != null) {
388 this.phone = phone;
389 }
390 this.workSource = workSource;
391 }
392
vagdeviaf9a5b92018-08-15 16:01:53 -0700393 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800394 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800395 if (subId != null) {
396 this.subId = subId;
397 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700398 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400 }
401
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800402 private static final class IncomingThirdPartyCallArgs {
403 public final ComponentName component;
404 public final String callId;
405 public final String callerDisplayName;
406
407 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
408 String callerDisplayName) {
409 this.component = component;
410 this.callId = callId;
411 this.callerDisplayName = callerDisplayName;
412 }
413 }
414
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 /**
416 * A handler that processes messages on the main thread in the phone process. Since many
417 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
418 * inbound binder threads to the main thread in the phone process. The Binder thread
419 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
420 * on, which will be notified when the operation completes and will contain the result of the
421 * request.
422 *
423 * <p>If a MainThreadRequest object is provided in the msg.obj field,
424 * note that request.result must be set to something non-null for the calling thread to
425 * unblock.
426 */
427 private final class MainThreadHandler extends Handler {
428 @Override
429 public void handleMessage(Message msg) {
430 MainThreadRequest request;
431 Message onCompleted;
432 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800433 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800435 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436
437 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700438 case CMD_HANDLE_USSD_REQUEST: {
439 request = (MainThreadRequest) msg.obj;
440 final Phone phone = getPhoneFromRequest(request);
441 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
442 String ussdRequest = ussdObject.first;
443 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700444
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 if (!isUssdApiAllowed(request.subId)) {
446 // Carrier does not support use of this API, return failure.
447 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
448 UssdResponse response = new UssdResponse(ussdRequest, null);
449 Bundle returnData = new Bundle();
450 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
451 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700452
Pengquan Menga1bb6272018-09-06 09:59:22 -0700453 request.result = true;
454 notifyRequester(request);
455 return;
456 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700457
Pengquan Menga1bb6272018-09-06 09:59:22 -0700458 try {
459 request.result = phone != null
460 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
461 } catch (CallStateException cse) {
462 request.result = false;
463 }
464 // Wake up the requesting thread
465 notifyRequester(request);
466 break;
pkanwar32d516d2016-10-14 19:37:38 -0700467 }
468
Yorke Lee716f67e2015-06-17 15:39:16 -0700469 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700471 final Phone phone = getPhoneFromRequest(request);
472 request.result = phone != null ?
473 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
474 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700476 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800483 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700484 if (uiccCard == null) {
485 loge("iccTransmitApduLogicalChannel: No UICC");
486 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700488 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
490 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700491 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700492 iccArgument.channel, iccArgument.cla, iccArgument.command,
493 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700495 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700496 break;
497
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700499 ar = (AsyncResult) msg.obj;
500 request = (MainThreadRequest) ar.userObj;
501 if (ar.exception == null && ar.result != null) {
502 request.result = ar.result;
503 } else {
504 request.result = new IccIoResult(0x6F, 0, (byte[])null);
505 if (ar.result == null) {
506 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800507 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800509 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700510 } else {
511 loge("iccTransmitApduLogicalChannel: Unknown exception");
512 }
513 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700514 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 break;
516
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700517 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
518 request = (MainThreadRequest) msg.obj;
519 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800520 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700521 if (uiccCard == null) {
522 loge("iccTransmitApduBasicChannel: No UICC");
523 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700524 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 } else {
526 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
527 request);
528 uiccCard.iccTransmitApduBasicChannel(
529 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
530 iccArgument.p3, iccArgument.data, onCompleted);
531 }
532 break;
533
534 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
535 ar = (AsyncResult) msg.obj;
536 request = (MainThreadRequest) ar.userObj;
537 if (ar.exception == null && ar.result != null) {
538 request.result = ar.result;
539 } else {
540 request.result = new IccIoResult(0x6F, 0, (byte[])null);
541 if (ar.result == null) {
542 loge("iccTransmitApduBasicChannel: Empty response");
543 } else if (ar.exception instanceof CommandException) {
544 loge("iccTransmitApduBasicChannel: CommandException: " +
545 ar.exception);
546 } else {
547 loge("iccTransmitApduBasicChannel: Unknown exception");
548 }
549 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700551 break;
552
553 case CMD_EXCHANGE_SIM_IO:
554 request = (MainThreadRequest) msg.obj;
555 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800556 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 if (uiccCard == null) {
558 loge("iccExchangeSimIO: No UICC");
559 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 } else {
562 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
563 request);
564 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
565 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
566 iccArgument.data, onCompleted);
567 }
568 break;
569
570 case EVENT_EXCHANGE_SIM_IO_DONE:
571 ar = (AsyncResult) msg.obj;
572 request = (MainThreadRequest) ar.userObj;
573 if (ar.exception == null && ar.result != null) {
574 request.result = ar.result;
575 } else {
576 request.result = new IccIoResult(0x6f, 0, (byte[])null);
577 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700578 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700579 break;
580
Derek Tan4d5e5c12014-02-04 11:54:58 -0800581 case CMD_SEND_ENVELOPE:
582 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800583 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700584 if (uiccCard == null) {
585 loge("sendEnvelopeWithStatus: No UICC");
586 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 } else {
589 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
590 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
591 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800592 break;
593
594 case EVENT_SEND_ENVELOPE_DONE:
595 ar = (AsyncResult) msg.obj;
596 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700597 if (ar.exception == null && ar.result != null) {
598 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800599 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700600 request.result = new IccIoResult(0x6F, 0, (byte[])null);
601 if (ar.result == null) {
602 loge("sendEnvelopeWithStatus: Empty response");
603 } else if (ar.exception instanceof CommandException) {
604 loge("sendEnvelopeWithStatus: CommandException: " +
605 ar.exception);
606 } else {
607 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
608 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800609 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700610 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800611 break;
612
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 case CMD_OPEN_CHANNEL:
614 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800615 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800616 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700617 if (uiccCard == null) {
618 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800619 request.result = new IccOpenLogicalChannelResponse(-1,
620 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700622 } else {
623 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800624 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
625 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 break;
628
629 case EVENT_OPEN_CHANNEL_DONE:
630 ar = (AsyncResult) msg.obj;
631 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 int[] result = (int[]) ar.result;
635 int channelId = result[0];
636 byte[] selectResponse = null;
637 if (result.length > 1) {
638 selectResponse = new byte[result.length - 1];
639 for (int i = 1; i < result.length; ++i) {
640 selectResponse[i - 1] = (byte) result[i];
641 }
642 }
643 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700644 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 if (ar.result == null) {
647 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700649 if (ar.exception != null) {
650 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
651 }
652
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700653 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700654 if (ar.exception instanceof CommandException) {
655 CommandException.Error error =
656 ((CommandException) (ar.exception)).getCommandError();
657 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700658 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700659 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700660 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700661 }
662 }
663 openChannelResp = new IccOpenLogicalChannelResponse(
664 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700666 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 break;
669
670 case CMD_CLOSE_CHANNEL:
671 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800672 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700673 if (uiccCard == null) {
674 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900675 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700677 } else {
678 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
679 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
680 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 break;
682
683 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800684 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
685 break;
686
687 case CMD_NV_READ_ITEM:
688 request = (MainThreadRequest) msg.obj;
689 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800690 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
691 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800692 break;
693
694 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 ar = (AsyncResult) msg.obj;
696 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800697 if (ar.exception == null && ar.result != null) {
698 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800700 request.result = "";
701 if (ar.result == null) {
702 loge("nvReadItem: Empty response");
703 } else if (ar.exception instanceof CommandException) {
704 loge("nvReadItem: CommandException: " +
705 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800707 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 }
709 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700710 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700711 break;
712
Jake Hambye994d462014-02-03 13:10:13 -0800713 case CMD_NV_WRITE_ITEM:
714 request = (MainThreadRequest) msg.obj;
715 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
716 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800717 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700718 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800719 break;
720
721 case EVENT_NV_WRITE_ITEM_DONE:
722 handleNullReturnEvent(msg, "nvWriteItem");
723 break;
724
725 case CMD_NV_WRITE_CDMA_PRL:
726 request = (MainThreadRequest) msg.obj;
727 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800728 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800729 break;
730
731 case EVENT_NV_WRITE_CDMA_PRL_DONE:
732 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
733 break;
734
chen xu6dac5ab2018-10-26 17:39:23 -0700735 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800736 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700737 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800738 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800739 break;
740
chen xu6dac5ab2018-10-26 17:39:23 -0700741 case EVENT_RESET_MODEM_CONFIG_DONE:
742 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800743 break;
744
Jake Hamby7c27be32014-03-03 13:25:59 -0800745 case CMD_GET_PREFERRED_NETWORK_TYPE:
746 request = (MainThreadRequest) msg.obj;
747 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700748 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800749 break;
750
751 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
752 ar = (AsyncResult) msg.obj;
753 request = (MainThreadRequest) ar.userObj;
754 if (ar.exception == null && ar.result != null) {
755 request.result = ar.result; // Integer
756 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800757 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800758 if (ar.result == null) {
759 loge("getPreferredNetworkType: Empty response");
760 } else if (ar.exception instanceof CommandException) {
761 loge("getPreferredNetworkType: CommandException: " +
762 ar.exception);
763 } else {
764 loge("getPreferredNetworkType: Unknown exception");
765 }
766 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700767 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800768 break;
769
770 case CMD_SET_PREFERRED_NETWORK_TYPE:
771 request = (MainThreadRequest) msg.obj;
772 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
773 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700774 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800775 break;
776
777 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
778 handleNullReturnEvent(msg, "setPreferredNetworkType");
779 break;
780
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000781 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
782 request = (MainThreadRequest)msg.obj;
783 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800784 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000785 break;
786
787 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
788 ar = (AsyncResult)msg.obj;
789 request = (MainThreadRequest)ar.userObj;
790 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700791 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000792 break;
793
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800794 case CMD_SET_VOICEMAIL_NUMBER:
795 request = (MainThreadRequest) msg.obj;
796 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
797 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800798 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
799 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800800 break;
801
802 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
803 handleNullReturnEvent(msg, "setVoicemailNumber");
804 break;
805
Stuart Scott54788802015-03-30 13:18:01 -0700806 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
807 request = (MainThreadRequest) msg.obj;
808 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
809 request);
810 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
811 break;
812
813 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
814 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
815 break;
816
Shishir Agrawal302c8692015-06-19 13:49:39 -0700817 case CMD_PERFORM_NETWORK_SCAN:
818 request = (MainThreadRequest) msg.obj;
819 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
820 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
821 break;
822
sqian80370722020-01-29 15:02:51 -0800823 case CMD_GET_CALL_FORWARDING:
824 request = (MainThreadRequest) msg.obj;
825 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
826 int callForwardingReason = (Integer) request.argument;
827 getPhoneFromRequest(request).getCallForwardingOption(
828 callForwardingReason, onCompleted);
829 break;
830
831 case EVENT_GET_CALL_FORWARDING_DONE:
832 ar = (AsyncResult) msg.obj;
833 request = (MainThreadRequest) ar.userObj;
834 CallForwardingInfo callForwardingInfo = null;
835 if (ar.exception == null && ar.result != null) {
836 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
837 for (CallForwardInfo callForwardInfo : callForwardInfos) {
838 // Service Class is a bit mask per 3gpp 27.007. Search for
839 // any service for voice call.
840 if ((callForwardInfo.serviceClass
841 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
842 callForwardingInfo = new CallForwardingInfo(
843 callForwardInfo.serviceClass, callForwardInfo.reason,
844 callForwardInfo.number,
845 callForwardInfo.timeSeconds);
846 break;
847 }
848 }
849 // Didn't find a call forward info for voice call.
850 if (callForwardingInfo == null) {
851 callForwardingInfo = new CallForwardingInfo(
852 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
853 0 /* reason */, null /* number */, 0 /* timeout */);
854 }
855 } else {
856 if (ar.result == null) {
857 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
858 }
859 if (ar.exception != null) {
860 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
861 }
862 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
863 if (ar.exception instanceof CommandException) {
864 CommandException.Error error =
865 ((CommandException) (ar.exception)).getCommandError();
866 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
867 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
868 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
869 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
870 }
871 }
872 callForwardingInfo = new CallForwardingInfo(
873 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
874 }
875 request.result = callForwardingInfo;
876 notifyRequester(request);
877 break;
878
879 case CMD_SET_CALL_FORWARDING:
880 request = (MainThreadRequest) msg.obj;
881 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
882 CallForwardingInfo callForwardingInfoToSet =
883 (CallForwardingInfo) request.argument;
884 getPhoneFromRequest(request).setCallForwardingOption(
885 callForwardingInfoToSet.getStatus(),
886 callForwardingInfoToSet.getReason(),
887 callForwardingInfoToSet.getNumber(),
888 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
889 break;
890
891 case EVENT_SET_CALL_FORWARDING_DONE:
892 ar = (AsyncResult) msg.obj;
893 request = (MainThreadRequest) ar.userObj;
894 if (ar.exception == null) {
895 request.result = true;
896 } else {
897 request.result = false;
898 loge("setCallForwarding exception: " + ar.exception);
899 }
900 notifyRequester(request);
901 break;
902
903 case CMD_GET_CALL_WAITING:
904 request = (MainThreadRequest) msg.obj;
905 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
906 getPhoneFromRequest(request).getCallWaiting(onCompleted);
907 break;
908
909 case EVENT_GET_CALL_WAITING_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
913 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800914 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -0800915 // Service Class is a bit mask per 3gpp 27.007.
916 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800917 if (callForwardResults.length > 1
918 && ((callForwardResults[1]
919 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
920 callForwardingStatus = callForwardResults[0] == 0
sqian80370722020-01-29 15:02:51 -0800921 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
922 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
923 } else {
924 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
925 }
926 } else {
927 if (ar.result == null) {
928 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
929 }
930 if (ar.exception != null) {
931 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
932 }
933 if (ar.exception instanceof CommandException) {
934 CommandException.Error error =
935 ((CommandException) (ar.exception)).getCommandError();
936 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
937 callForwardingStatus =
938 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
939 }
940 }
941 }
942 request.result = callForwardingStatus;
943 notifyRequester(request);
944 break;
945
946 case CMD_SET_CALL_WAITING:
947 request = (MainThreadRequest) msg.obj;
948 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
949 boolean isEnable = (Boolean) request.argument;
950 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
951 break;
952
953 case EVENT_SET_CALL_WAITING_DONE:
954 ar = (AsyncResult) msg.obj;
955 request = (MainThreadRequest) ar.userObj;
956 if (ar.exception == null) {
957 request.result = true;
958 } else {
959 request.result = false;
960 loge("setCallWaiting exception: " + ar.exception);
961 }
962 notifyRequester(request);
963 break;
964
Shishir Agrawal302c8692015-06-19 13:49:39 -0700965 case EVENT_PERFORM_NETWORK_SCAN_DONE:
966 ar = (AsyncResult) msg.obj;
967 request = (MainThreadRequest) ar.userObj;
968 CellNetworkScanResult cellScanResult;
969 if (ar.exception == null && ar.result != null) {
970 cellScanResult = new CellNetworkScanResult(
971 CellNetworkScanResult.STATUS_SUCCESS,
972 (List<OperatorInfo>) ar.result);
973 } else {
974 if (ar.result == null) {
975 loge("getCellNetworkScanResults: Empty response");
976 }
977 if (ar.exception != null) {
978 loge("getCellNetworkScanResults: Exception: " + ar.exception);
979 }
980 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
981 if (ar.exception instanceof CommandException) {
982 CommandException.Error error =
983 ((CommandException) (ar.exception)).getCommandError();
984 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
985 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
986 } else if (error == CommandException.Error.GENERIC_FAILURE) {
987 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
988 }
989 }
990 cellScanResult = new CellNetworkScanResult(errorCode, null);
991 }
992 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700993 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700994 break;
995
996 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
997 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700998 ManualNetworkSelectionArgument selArg =
999 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001000 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1001 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001002 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1003 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001004 break;
1005
1006 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001007 ar = (AsyncResult) msg.obj;
1008 request = (MainThreadRequest) ar.userObj;
1009 if (ar.exception == null) {
1010 request.result = true;
1011 } else {
1012 request.result = false;
1013 loge("setNetworkSelectionModeManual " + ar.exception);
1014 }
1015 notifyRequester(request);
1016 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001017 break;
1018
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001019 case CMD_GET_MODEM_ACTIVITY_INFO:
1020 request = (MainThreadRequest) msg.obj;
1021 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001022 if (defaultPhone != null) {
1023 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001024 } else {
1025 ResultReceiver result = (ResultReceiver) request.argument;
1026 Bundle bundle = new Bundle();
1027 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1028 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1029 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001030 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001031 break;
1032
1033 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1034 ar = (AsyncResult) msg.obj;
1035 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001036 ResultReceiver result = (ResultReceiver) request.argument;
1037
1038 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001039 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001040 // Update the last modem activity info and the result of the request.
1041 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1042 if (isModemActivityInfoValid(info)) {
1043 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1044 int[] txTimeMs = info.getTransmitTimeMillis();
1045 int[] lastModemTxTimeMs = mLastModemActivityInfo
1046 .getTransmitTimeMillis();
1047 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1048 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1049 }
1050 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1051 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1052 + mLastModemActivityInfo.getSleepTimeMillis());
1053 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1054 + mLastModemActivityInfo.getIdleTimeMillis());
1055 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1056 mLastModemActivityInfo.setReceiveTimeMillis(
1057 info.getReceiveTimeMillis()
1058 + mLastModemActivityInfo.getReceiveTimeMillis());
1059 }
1060 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1061 mLastModemActivityInfo.getSleepTimeMillis(),
1062 mLastModemActivityInfo.getIdleTimeMillis(),
1063 mLastModemActivityInfo.getTransmitTimeMillis(),
1064 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001065 } else {
1066 if (ar.result == null) {
1067 loge("queryModemActivityInfo: Empty response");
1068 } else if (ar.exception instanceof CommandException) {
1069 loge("queryModemActivityInfo: CommandException: " +
1070 ar.exception);
1071 } else {
1072 loge("queryModemActivityInfo: Unknown exception");
1073 }
1074 }
sqian1a1be542020-03-05 11:37:28 -08001075 Bundle bundle = new Bundle();
1076 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1077 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001078 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001079 break;
1080
Meng Wang1a7c35a2016-05-05 20:56:15 -07001081 case CMD_SET_ALLOWED_CARRIERS:
1082 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001083 CarrierRestrictionRules argument =
1084 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001085 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001086 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001087 break;
1088
1089 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1090 ar = (AsyncResult) msg.obj;
1091 request = (MainThreadRequest) ar.userObj;
1092 if (ar.exception == null && ar.result != null) {
1093 request.result = ar.result;
1094 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001095 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1096 if (ar.exception instanceof CommandException) {
1097 loge("setAllowedCarriers: CommandException: " + ar.exception);
1098 CommandException.Error error =
1099 ((CommandException) (ar.exception)).getCommandError();
1100 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1101 request.result =
1102 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1103 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001104 } else {
1105 loge("setAllowedCarriers: Unknown exception");
1106 }
1107 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001108 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001109 break;
1110
1111 case CMD_GET_ALLOWED_CARRIERS:
1112 request = (MainThreadRequest) msg.obj;
1113 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001114 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001115 break;
1116
1117 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1118 ar = (AsyncResult) msg.obj;
1119 request = (MainThreadRequest) ar.userObj;
1120 if (ar.exception == null && ar.result != null) {
1121 request.result = ar.result;
1122 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001123 request.result = new IllegalStateException(
1124 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001125 if (ar.result == null) {
1126 loge("getAllowedCarriers: Empty response");
1127 } else if (ar.exception instanceof CommandException) {
1128 loge("getAllowedCarriers: CommandException: " +
1129 ar.exception);
1130 } else {
1131 loge("getAllowedCarriers: Unknown exception");
1132 }
1133 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001134 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001135 break;
1136
Nathan Haroldb3014052017-01-25 15:57:32 -08001137 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1138 ar = (AsyncResult) msg.obj;
1139 request = (MainThreadRequest) ar.userObj;
1140 if (ar.exception == null && ar.result != null) {
1141 request.result = ar.result;
1142 } else {
1143 request.result = new IllegalArgumentException(
1144 "Failed to retrieve Forbidden Plmns");
1145 if (ar.result == null) {
1146 loge("getForbiddenPlmns: Empty response");
1147 } else {
1148 loge("getForbiddenPlmns: Unknown exception");
1149 }
1150 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001151 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001152 break;
1153
1154 case CMD_GET_FORBIDDEN_PLMNS:
1155 request = (MainThreadRequest) msg.obj;
1156 uiccCard = getUiccCardFromRequest(request);
1157 if (uiccCard == null) {
1158 loge("getForbiddenPlmns() UiccCard is null");
1159 request.result = new IllegalArgumentException(
1160 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001161 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001162 break;
1163 }
1164 Integer appType = (Integer) request.argument;
1165 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1166 if (uiccApp == null) {
1167 loge("getForbiddenPlmns() no app with specified type -- "
1168 + appType);
1169 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001170 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001171 break;
1172 } else {
1173 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1174 + " specified type -- " + appType);
1175 }
1176 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1177 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1178 onCompleted);
1179 break;
1180
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001181 case CMD_SWITCH_SLOTS:
1182 request = (MainThreadRequest) msg.obj;
1183 int[] physicalSlots = (int[]) request.argument;
1184 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1185 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1186 break;
1187
1188 case EVENT_SWITCH_SLOTS_DONE:
1189 ar = (AsyncResult) msg.obj;
1190 request = (MainThreadRequest) ar.userObj;
1191 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001192 notifyRequester(request);
1193 break;
1194 case CMD_GET_NETWORK_SELECTION_MODE:
1195 request = (MainThreadRequest) msg.obj;
1196 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1197 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1198 break;
1199
1200 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1201 ar = (AsyncResult) msg.obj;
1202 request = (MainThreadRequest) ar.userObj;
1203 if (ar.exception != null) {
1204 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1205 } else {
1206 int mode = ((int[]) ar.result)[0];
1207 if (mode == 0) {
1208 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1209 } else {
1210 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1211 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001212 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001213 notifyRequester(request);
1214 break;
1215 case CMD_GET_CDMA_ROAMING_MODE:
1216 request = (MainThreadRequest) msg.obj;
1217 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1218 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1219 break;
1220 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1221 ar = (AsyncResult) msg.obj;
1222 request = (MainThreadRequest) ar.userObj;
1223 if (ar.exception != null) {
1224 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1225 } else {
1226 request.result = ((int[]) ar.result)[0];
1227 }
1228 notifyRequester(request);
1229 break;
1230 case CMD_SET_CDMA_ROAMING_MODE:
1231 request = (MainThreadRequest) msg.obj;
1232 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1233 int mode = (int) request.argument;
1234 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1235 break;
1236 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1237 ar = (AsyncResult) msg.obj;
1238 request = (MainThreadRequest) ar.userObj;
1239 request.result = ar.exception == null;
1240 notifyRequester(request);
1241 break;
1242 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1243 request = (MainThreadRequest) msg.obj;
1244 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1245 int subscriptionMode = (int) request.argument;
1246 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1247 break;
1248 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1249 ar = (AsyncResult) msg.obj;
1250 request = (MainThreadRequest) ar.userObj;
1251 request.result = ar.exception == null;
1252 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001253 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001254 case CMD_GET_ALL_CELL_INFO:
1255 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001256 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001257 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001258 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001259 case EVENT_GET_ALL_CELL_INFO_DONE:
1260 ar = (AsyncResult) msg.obj;
1261 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001262 // If a timeout occurs, the response will be null
1263 request.result = (ar.exception == null && ar.result != null)
1264 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001265 synchronized (request) {
1266 request.notifyAll();
1267 }
1268 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001269 case CMD_REQUEST_CELL_INFO_UPDATE:
1270 request = (MainThreadRequest) msg.obj;
1271 request.phone.requestCellInfoUpdate(request.workSource,
1272 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1273 break;
1274 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1275 ar = (AsyncResult) msg.obj;
1276 request = (MainThreadRequest) ar.userObj;
1277 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1278 try {
1279 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001280 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001281 cb.onError(
1282 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1283 ar.exception.getClass().getName(),
1284 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001285 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001286 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001287 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001288 } else {
1289 // use the result as returned
1290 cb.onCellInfo((List<CellInfo>) ar.result);
1291 }
1292 } catch (RemoteException re) {
1293 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1294 }
1295 break;
1296 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001297 request = (MainThreadRequest) msg.obj;
1298 WorkSource ws = (WorkSource) request.argument;
1299 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001300 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001301 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001302 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001303 ar = (AsyncResult) msg.obj;
1304 request = (MainThreadRequest) ar.userObj;
1305 if (ar.exception == null) {
1306 request.result = ar.result;
1307 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001308 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001309 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001310 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001311 }
1312
1313 synchronized (request) {
1314 request.notifyAll();
1315 }
1316 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001317 case CMD_MODEM_REBOOT:
1318 request = (MainThreadRequest) msg.obj;
1319 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001320 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001321 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001322 case EVENT_CMD_MODEM_REBOOT_DONE:
1323 handleNullReturnEvent(msg, "rebootModem");
1324 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001325 case CMD_REQUEST_ENABLE_MODEM:
1326 request = (MainThreadRequest) msg.obj;
1327 boolean enable = (boolean) request.argument;
1328 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001329 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001330 PhoneConfigurationManager.getInstance()
1331 .enablePhone(request.phone, enable, onCompleted);
1332 break;
1333 case EVENT_ENABLE_MODEM_DONE:
1334 ar = (AsyncResult) msg.obj;
1335 request = (MainThreadRequest) ar.userObj;
1336 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001337 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001338 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001339 if ((boolean) request.result) {
1340 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1341 updateModemStateMetrics();
1342 } else {
1343 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1344 + ar.exception);
1345 }
1346 notifyRequester(request);
1347 break;
1348 case CMD_GET_MODEM_STATUS:
1349 request = (MainThreadRequest) msg.obj;
1350 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1351 PhoneConfigurationManager.getInstance()
1352 .getPhoneStatusFromModem(request.phone, onCompleted);
1353 break;
1354 case EVENT_GET_MODEM_STATUS_DONE:
1355 ar = (AsyncResult) msg.obj;
1356 request = (MainThreadRequest) ar.userObj;
1357 int id = request.phone.getPhoneId();
1358 if (ar.exception == null && ar.result != null) {
1359 request.result = ar.result;
1360 //update the cache as modem status has changed
1361 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1362 (boolean) request.result);
1363 } else {
1364 // Return true if modem status cannot be retrieved. For most cases,
1365 // modem status is on. And for older version modems, GET_MODEM_STATUS
1366 // and disable modem are not supported. Modem is always on.
1367 // TODO: this should be fixed in R to support a third
1368 // status UNKNOWN b/131631629
1369 request.result = true;
1370 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1371 + ar.exception);
1372 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001373 notifyRequester(request);
1374 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001375 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1376 request = (MainThreadRequest) msg.obj;
1377 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1378 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1379 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1380 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1381 break;
1382 }
1383 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1384 ar = (AsyncResult) msg.obj;
1385 request = (MainThreadRequest) ar.userObj;
1386 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1387 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1388 args.second.accept(ar.exception == null);
1389 notifyRequester(request);
1390 break;
1391 }
yincheng zhaod698b842019-09-06 17:06:54 -07001392 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1393 ar = (AsyncResult) msg.obj;
1394 request = (MainThreadRequest) ar.userObj;
1395 if (ar.exception == null && ar.result != null) {
1396 request.result = ar.result;
1397 } else {
1398 request.result = -1;
1399 loge("Failed to set Forbidden Plmns");
1400 if (ar.result == null) {
1401 loge("setForbidenPlmns: Empty response");
1402 } else if (ar.exception != null) {
1403 loge("setForbiddenPlmns: Exception: " + ar.exception);
1404 request.result = -1;
1405 } else {
1406 loge("setForbiddenPlmns: Unknown exception");
1407 }
1408 }
1409 notifyRequester(request);
1410 break;
1411 case CMD_SET_FORBIDDEN_PLMNS:
1412 request = (MainThreadRequest) msg.obj;
1413 uiccCard = getUiccCardFromRequest(request);
1414 if (uiccCard == null) {
1415 loge("setForbiddenPlmns: UiccCard is null");
1416 request.result = -1;
1417 notifyRequester(request);
1418 break;
1419 }
1420 Pair<Integer, List<String>> setFplmnsArgs =
1421 (Pair<Integer, List<String>>) request.argument;
1422 appType = setFplmnsArgs.first;
1423 List<String> fplmns = setFplmnsArgs.second;
1424 uiccApp = uiccCard.getApplicationByType(appType);
1425 if (uiccApp == null) {
1426 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1427 request.result = -1;
1428 loge("Failed to get UICC App");
1429 notifyRequester(request);
1430 } else {
1431 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1432 ((SIMRecords) uiccApp.getIccRecords())
1433 .setForbiddenPlmns(onCompleted, fplmns);
1434 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001435 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001436 case CMD_ERASE_MODEM_CONFIG:
1437 request = (MainThreadRequest) msg.obj;
1438 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1439 defaultPhone.eraseModemConfig(onCompleted);
1440 break;
1441 case EVENT_ERASE_MODEM_CONFIG_DONE:
1442 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001443 break;
zoey chenf95ca592019-12-30 16:11:23 +08001444
1445 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1446 request = (MainThreadRequest) msg.obj;
1447 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1448 Pair<String, String> changed = (Pair<String, String>) request.argument;
1449 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1450 changed.first, changed.second, onCompleted);
1451 break;
1452 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1453 ar = (AsyncResult) msg.obj;
1454 request = (MainThreadRequest) ar.userObj;
1455 if (ar.exception == null) {
1456 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1457 } else {
1458 request.result = msg.arg1;
1459 }
1460 notifyRequester(request);
1461 break;
1462
1463 case CMD_SET_ICC_LOCK_ENABLED:
1464 request = (MainThreadRequest) msg.obj;
1465 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1466 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1467 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1468 enabled.first, enabled.second, onCompleted);
1469 break;
1470 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1471 ar = (AsyncResult) msg.obj;
1472 request = (MainThreadRequest) ar.userObj;
1473 if (ar.exception == null) {
1474 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1475 } else {
1476 request.result = msg.arg1;
1477 }
1478 notifyRequester(request);
1479 break;
1480
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 default:
1482 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1483 break;
1484 }
1485 }
Jake Hambye994d462014-02-03 13:10:13 -08001486
Pengquan Menga1bb6272018-09-06 09:59:22 -07001487 private void notifyRequester(MainThreadRequest request) {
1488 synchronized (request) {
1489 request.notifyAll();
1490 }
1491 }
1492
Jake Hambye994d462014-02-03 13:10:13 -08001493 private void handleNullReturnEvent(Message msg, String command) {
1494 AsyncResult ar = (AsyncResult) msg.obj;
1495 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1496 if (ar.exception == null) {
1497 request.result = true;
1498 } else {
1499 request.result = false;
1500 if (ar.exception instanceof CommandException) {
1501 loge(command + ": CommandException: " + ar.exception);
1502 } else {
1503 loge(command + ": Unknown exception");
1504 }
1505 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001506 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508 }
1509
1510 /**
1511 * Posts the specified command to be executed on the main thread,
1512 * waits for the request to complete, and returns the result.
1513 * @see #sendRequestAsync
1514 */
1515 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001516 return sendRequest(
1517 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001518 }
1519
1520 /**
1521 * Posts the specified command to be executed on the main thread,
1522 * waits for the request to complete, and returns the result.
1523 * @see #sendRequestAsync
1524 */
1525 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1526 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001527 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001528 }
1529
1530 /**
1531 * Posts the specified command to be executed on the main thread,
1532 * waits for the request to complete, and returns the result.
1533 * @see #sendRequestAsync
1534 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001535 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001536 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001537 }
1538
1539 /**
1540 * Posts the specified command to be executed on the main thread,
1541 * waits for the request to complete, and returns the result.
1542 * @see #sendRequestAsync
1543 */
Nathan Harold92bed182018-10-12 18:16:49 -07001544 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1545 return sendRequest(command, argument, subId, null, workSource);
1546 }
1547
1548 /**
1549 * Posts the specified command to be executed on the main thread,
1550 * waits for the request to complete, and returns the result.
1551 * @see #sendRequestAsync
1552 */
1553 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1554 return sendRequest(
1555 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1556 }
1557
1558 /**
1559 * Posts the specified command to be executed on the main thread,
1560 * waits for the request to complete, and returns the result.
1561 * @see #sendRequestAsync
1562 */
1563 private Object sendRequest(
1564 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1566 throw new RuntimeException("This method will deadlock if called from the main thread.");
1567 }
1568
Nathan Harold92bed182018-10-12 18:16:49 -07001569 MainThreadRequest request = null;
1570 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1571 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1572 } else if (phone != null) {
1573 request = new MainThreadRequest(argument, phone, workSource);
1574 } else {
1575 request = new MainThreadRequest(argument, subId, workSource);
1576 }
1577
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001578 Message msg = mMainThreadHandler.obtainMessage(command, request);
1579 msg.sendToTarget();
1580
1581 // Wait for the request to complete
1582 synchronized (request) {
1583 while (request.result == null) {
1584 try {
1585 request.wait();
1586 } catch (InterruptedException e) {
1587 // Do nothing, go back and wait until the request is complete
1588 }
1589 }
1590 }
1591 return request.result;
1592 }
1593
1594 /**
1595 * Asynchronous ("fire and forget") version of sendRequest():
1596 * Posts the specified command to be executed on the main thread, and
1597 * returns immediately.
1598 * @see #sendRequest
1599 */
1600 private void sendRequestAsync(int command) {
1601 mMainThreadHandler.sendEmptyMessage(command);
1602 }
1603
1604 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001605 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001606 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001607 */
1608 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001609 sendRequestAsync(command, argument, null, null);
1610 }
1611
1612 /**
1613 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1614 * @see {@link #sendRequest(int,Object)}
1615 */
1616 private void sendRequestAsync(
1617 int command, Object argument, Phone phone, WorkSource workSource) {
1618 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001619 Message msg = mMainThreadHandler.obtainMessage(command, request);
1620 msg.sendToTarget();
1621 }
1622
1623 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 * Initialize the singleton PhoneInterfaceManager instance.
1625 * This is only done once, at startup, from PhoneApp.onCreate().
1626 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001627 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001628 synchronized (PhoneInterfaceManager.class) {
1629 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001630 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 } else {
1632 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1633 }
1634 return sInstance;
1635 }
1636 }
1637
1638 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001639 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001640 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001642 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001643 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1645 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001646 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001647 mTelephonySharedPreferences =
1648 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001649 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001650 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001651
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 publish();
1653 }
1654
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001655 private Phone getDefaultPhone() {
1656 Phone thePhone = getPhone(getDefaultSubscription());
1657 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1658 }
1659
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 private void publish() {
1661 if (DBG) log("publish: " + this);
1662
1663 ServiceManager.addService("phone", this);
1664 }
1665
Stuart Scott584921c2015-01-15 17:10:34 -08001666 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001667 if (request.phone != null) {
1668 return request.phone;
1669 } else {
1670 return getPhoneFromSubId(request.subId);
1671 }
1672 }
1673
1674 private Phone getPhoneFromSubId(int subId) {
1675 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1676 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001677 }
1678
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001679 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1680 Phone phone = getPhoneFromRequest(request);
1681 return phone == null ? null :
1682 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1683 }
1684
Wink Saville36469e72014-06-11 15:17:00 -07001685 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001686 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001687 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001690 private void sendEraseModemConfig(Phone phone) {
1691 if (phone != null) {
1692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1693 mApp, phone.getSubId(), "eraseModemConfig");
1694 final long identity = Binder.clearCallingIdentity();
1695 try {
1696 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1697 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1698 } finally {
1699 Binder.restoreCallingIdentity(identity);
1700 }
1701 }
1702 }
1703
Peter Wang050bb052020-01-13 23:33:09 -08001704 private boolean isImsAvailableOnDevice() {
1705 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1706 if (pm == null) {
1707 // For some reason package manger is not available.. This will fail internally anyway,
1708 // so do not throw error and allow.
1709 return true;
1710 }
1711 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1712 }
1713
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001715 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001716 }
1717
Wink Savilleb564aae2014-10-23 10:18:09 -07001718 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 if (DBG) log("dial: " + number);
1720 // No permission check needed here: This is just a wrapper around the
1721 // ACTION_DIAL intent, which is available to any app since it puts up
1722 // the UI before it does anything.
1723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001724 final long identity = Binder.clearCallingIdentity();
1725 try {
1726 String url = createTelUrl(number);
1727 if (url == null) {
1728 return;
1729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001731 // PENDING: should we just silently fail if phone is offhook or ringing?
1732 PhoneConstants.State state = mCM.getState(subId);
1733 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1734 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1735 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1736 mApp.startActivity(intent);
1737 }
1738 } finally {
1739 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 }
1741 }
1742
1743 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001744 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001745 }
1746
Wink Savilleb564aae2014-10-23 10:18:09 -07001747 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 if (DBG) log("call: " + number);
1749
1750 // This is just a wrapper around the ACTION_CALL intent, but we still
1751 // need to do a permission check since we're calling startActivity()
1752 // from the context of the phone app.
1753 enforceCallPermission();
1754
Jordan Liu1617b712019-07-10 15:06:26 -07001755 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 != AppOpsManager.MODE_ALLOWED) {
1757 return;
1758 }
1759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001760 final long identity = Binder.clearCallingIdentity();
1761 try {
1762 String url = createTelUrl(number);
1763 if (url == null) {
1764 return;
1765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001767 boolean isValid = false;
1768 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1769 if (slist != null) {
1770 for (SubscriptionInfo subInfoRecord : slist) {
1771 if (subInfoRecord.getSubscriptionId() == subId) {
1772 isValid = true;
1773 break;
1774 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001775 }
Wink Saville08874612014-08-31 19:19:58 -07001776 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001777 if (!isValid) {
1778 return;
1779 }
Wink Saville08874612014-08-31 19:19:58 -07001780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001781 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1782 intent.putExtra(SUBSCRIPTION_KEY, subId);
1783 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1784 mApp.startActivity(intent);
1785 } finally {
1786 Binder.restoreCallingIdentity(identity);
1787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
1789
Wink Savilleb564aae2014-10-23 10:18:09 -07001790 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001791 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001792 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1793 }
1794
Wink Savilleb564aae2014-10-23 10:18:09 -07001795 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001796 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001797 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1798 }
1799
Wink Savilleb564aae2014-10-23 10:18:09 -07001800 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001801 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001802
1803 final long identity = Binder.clearCallingIdentity();
1804 try {
1805 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1806 checkSimPin.start();
1807 return checkSimPin.unlockSim(null, pin);
1808 } finally {
1809 Binder.restoreCallingIdentity(identity);
1810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 }
1812
Wink Savilleb564aae2014-10-23 10:18:09 -07001813 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001815
1816 final long identity = Binder.clearCallingIdentity();
1817 try {
1818 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1819 checkSimPuk.start();
1820 return checkSimPuk.unlockSim(puk, pin);
1821 } finally {
1822 Binder.restoreCallingIdentity(identity);
1823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
1825
1826 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001827 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 * a synchronous one.
1829 */
1830 private static class UnlockSim extends Thread {
1831
1832 private final IccCard mSimCard;
1833
1834 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001835 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1836 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001837
1838 // For replies from SimCard interface
1839 private Handler mHandler;
1840
1841 // For async handler to identify request type
1842 private static final int SUPPLY_PIN_COMPLETE = 100;
1843
1844 public UnlockSim(IccCard simCard) {
1845 mSimCard = simCard;
1846 }
1847
1848 @Override
1849 public void run() {
1850 Looper.prepare();
1851 synchronized (UnlockSim.this) {
1852 mHandler = new Handler() {
1853 @Override
1854 public void handleMessage(Message msg) {
1855 AsyncResult ar = (AsyncResult) msg.obj;
1856 switch (msg.what) {
1857 case SUPPLY_PIN_COMPLETE:
1858 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1859 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001860 mRetryCount = msg.arg1;
1861 if (ar.exception != null) {
1862 if (ar.exception instanceof CommandException &&
1863 ((CommandException)(ar.exception)).getCommandError()
1864 == CommandException.Error.PASSWORD_INCORRECT) {
1865 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001866 } //When UiccCardApp dispose,handle message and return exception
1867 else if (ar.exception instanceof CommandException &&
1868 ((CommandException) (ar.exception)).getCommandError()
1869 == CommandException.Error.ABORTED) {
1870 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001871 } else {
1872 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1873 }
1874 } else {
1875 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 mDone = true;
1878 UnlockSim.this.notifyAll();
1879 }
1880 break;
1881 }
1882 }
1883 };
1884 UnlockSim.this.notifyAll();
1885 }
1886 Looper.loop();
1887 }
1888
1889 /*
1890 * Use PIN or PUK to unlock SIM card
1891 *
1892 * If PUK is null, unlock SIM card with PIN
1893 *
1894 * If PUK is not null, unlock SIM card with PUK and set PIN code
1895 */
Wink Saville9de0f752013-10-22 19:04:03 -07001896 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897
1898 while (mHandler == null) {
1899 try {
1900 wait();
1901 } catch (InterruptedException e) {
1902 Thread.currentThread().interrupt();
1903 }
1904 }
1905 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1906
1907 if (puk == null) {
1908 mSimCard.supplyPin(pin, callback);
1909 } else {
1910 mSimCard.supplyPuk(puk, pin, callback);
1911 }
1912
1913 while (!mDone) {
1914 try {
1915 Log.d(LOG_TAG, "wait for done");
1916 wait();
1917 } catch (InterruptedException e) {
1918 // Restore the interrupted status
1919 Thread.currentThread().interrupt();
1920 }
1921 }
1922 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001923 int[] resultArray = new int[2];
1924 resultArray[0] = mResult;
1925 resultArray[1] = mRetryCount;
1926 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001927 }
1928 }
1929
1930 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001931 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001932
1933 }
1934
Wink Savilleb564aae2014-10-23 10:18:09 -07001935 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 // No permission check needed here: this call is harmless, and it's
1937 // needed for the ServiceState.requestStateUpdate() call (which is
1938 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001939 final long identity = Binder.clearCallingIdentity();
1940 try {
1941 final Phone phone = getPhone(subId);
1942 if (phone != null) {
1943 phone.updateServiceLocation();
1944 }
1945 } finally {
1946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948 }
1949
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001950 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001951 @Override
1952 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001953 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001954 }
1955
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001956 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001957 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1958 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1959 callingFeatureId);
1960 }
1961
1962 @Deprecated
1963 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001964 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001965 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1966 }
1967
1968 @Override
1969 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1970 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001971 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001972 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001973 return false;
1974 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001975
1976 final long identity = Binder.clearCallingIdentity();
1977 try {
1978 return isRadioOnForSubscriber(subId);
1979 } finally {
1980 Binder.restoreCallingIdentity(identity);
1981 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001982 }
1983
1984 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985 final long identity = Binder.clearCallingIdentity();
1986 try {
1987 final Phone phone = getPhone(subId);
1988 if (phone != null) {
1989 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1990 } else {
1991 return false;
1992 }
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001995 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 }
1997
1998 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001999 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 }
Wink Saville36469e72014-06-11 15:17:00 -07002001
Wink Savilleb564aae2014-10-23 10:18:09 -07002002 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002004
2005 final long identity = Binder.clearCallingIdentity();
2006 try {
2007 final Phone phone = getPhone(subId);
2008 if (phone != null) {
2009 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2010 }
2011 } finally {
2012 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002013 }
Wink Saville36469e72014-06-11 15:17:00 -07002014 }
2015
2016 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002017 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002018 }
2019
Wink Savilleb564aae2014-10-23 10:18:09 -07002020 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002021 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002022
2023 final long identity = Binder.clearCallingIdentity();
2024 try {
2025 final Phone phone = getPhone(subId);
2026 if (phone == null) {
2027 return false;
2028 }
2029 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2030 toggleRadioOnOffForSubscriber(subId);
2031 }
2032 return true;
2033 } finally {
2034 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002035 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002036 }
Wink Saville36469e72014-06-11 15:17:00 -07002037
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002038 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002039 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002040 /*
2041 * If any of the Radios are available, it will need to be
2042 * shutdown. So return true if any Radio is available.
2043 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002044 final long identity = Binder.clearCallingIdentity();
2045 try {
2046 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2047 Phone phone = PhoneFactory.getPhone(i);
2048 if (phone != null && phone.isRadioAvailable()) return true;
2049 }
2050 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2051 return false;
2052 } finally {
2053 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002054 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002055 }
2056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002058 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002059 enforceModifyPermission();
2060
2061 final long identity = Binder.clearCallingIdentity();
2062 try {
2063 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2064 logv("Shutting down Phone " + i);
2065 shutdownRadioUsingPhoneId(i);
2066 }
2067 } finally {
2068 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002069 }
2070 }
2071
2072 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002073 Phone phone = PhoneFactory.getPhone(phoneId);
2074 if (phone != null && phone.isRadioAvailable()) {
2075 phone.shutdownRadio();
2076 }
2077 }
2078
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002080 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002081
2082 final long identity = Binder.clearCallingIdentity();
2083 try {
2084 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2085 if (defaultPhone != null) {
2086 defaultPhone.setRadioPower(turnOn);
2087 return true;
2088 } else {
2089 loge("There's no default phone.");
2090 return false;
2091 }
2092 } finally {
2093 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002094 }
Wink Saville36469e72014-06-11 15:17:00 -07002095 }
2096
Wink Savilleb564aae2014-10-23 10:18:09 -07002097 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099
2100 final long identity = Binder.clearCallingIdentity();
2101 try {
2102 final Phone phone = getPhone(subId);
2103 if (phone != null) {
2104 phone.setRadioPower(turnOn);
2105 return true;
2106 } else {
2107 return false;
2108 }
2109 } finally {
2110 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
2113
Wink Saville36469e72014-06-11 15:17:00 -07002114 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002115 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 public boolean enableDataConnectivity() {
2117 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002118
2119 final long identity = Binder.clearCallingIdentity();
2120 try {
2121 int subId = mSubscriptionController.getDefaultDataSubId();
2122 final Phone phone = getPhone(subId);
2123 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002124 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002125 return true;
2126 } else {
2127 return false;
2128 }
2129 } finally {
2130 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 }
2133
Wink Saville36469e72014-06-11 15:17:00 -07002134 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002135 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136 public boolean disableDataConnectivity() {
2137 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002138
2139 final long identity = Binder.clearCallingIdentity();
2140 try {
2141 int subId = mSubscriptionController.getDefaultDataSubId();
2142 final Phone phone = getPhone(subId);
2143 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002144 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002145 return true;
2146 } else {
2147 return false;
2148 }
2149 } finally {
2150 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002151 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 }
2153
Sanket Padawe356d7632015-06-22 14:03:32 -07002154 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002155 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002156 final long identity = Binder.clearCallingIdentity();
2157 try {
2158 final Phone phone = getPhone(subId);
2159 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002160 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002161 } else {
2162 return false;
2163 }
2164 } finally {
2165 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 }
2168
2169 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002170 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002171 }
2172
pkanwarae03a6b2016-11-06 20:37:09 -08002173 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002174 enforceCallPermission();
2175
2176 final long identity = Binder.clearCallingIdentity();
2177 try {
2178 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2179 return;
2180 }
2181 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2182 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2183 } finally {
2184 Binder.restoreCallingIdentity(identity);
2185 }
pkanwar32d516d2016-10-14 19:37:38 -07002186 };
2187
Wink Savilleb564aae2014-10-23 10:18:09 -07002188 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002190
2191 final long identity = Binder.clearCallingIdentity();
2192 try {
2193 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2194 return false;
2195 }
2196 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2197 } finally {
2198 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
2201
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002203 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002204 }
2205
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002206 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002207 final long identity = Binder.clearCallingIdentity();
2208 try {
2209 Phone phone = PhoneFactory.getPhone(slotIndex);
2210 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2211 PhoneConstantConversions.convertCallState(phone.getState());
2212 } finally {
2213 Binder.restoreCallingIdentity(identity);
2214 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 }
2216
Sanket Padawe356d7632015-06-22 14:03:32 -07002217 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002218 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002219 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2220 }
2221
2222 @Override
2223 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002224 final long identity = Binder.clearCallingIdentity();
2225 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002226 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002227 if (phone != null) {
2228 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2229 } else {
2230 return PhoneConstantConversions.convertDataState(
2231 PhoneConstants.DataState.DISCONNECTED);
2232 }
2233 } finally {
2234 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 }
2237
Sanket Padawe356d7632015-06-22 14:03:32 -07002238 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002239 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002240 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2241 }
2242
2243 @Override
2244 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002245 final long identity = Binder.clearCallingIdentity();
2246 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002247 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002248 if (phone != null) {
2249 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2250 } else {
2251 return TelephonyManager.DATA_ACTIVITY_NONE;
2252 }
2253 } finally {
2254 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 }
2257
2258 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002259 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002260 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002261 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002262
2263 LocationAccessPolicy.LocationPermissionResult locationResult =
2264 LocationAccessPolicy.checkLocationPermission(mApp,
2265 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2266 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002267 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002268 .setCallingPid(Binder.getCallingPid())
2269 .setCallingUid(Binder.getCallingUid())
2270 .setMethod("getCellLocation")
2271 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2272 .build());
2273 switch (locationResult) {
2274 case DENIED_HARD:
2275 throw new SecurityException("Not allowed to access cell location");
2276 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002277 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2278 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 }
2280
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002281 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002282 final long identity = Binder.clearCallingIdentity();
2283 try {
2284 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002285 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002286 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002287 } finally {
2288 Binder.restoreCallingIdentity(identity);
2289 }
Svetoslav64fad262015-04-14 14:35:21 -07002290 }
2291
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 @Override
Jack Yu01425032020-02-22 19:38:58 -08002293 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002294 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2295 // registered cell info, so return a NULL country instead.
2296 final long identity = Binder.clearCallingIdentity();
2297 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002298 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2299 // Get default phone in this case.
2300 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2301 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002302 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002303 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002304 if (phone == null) return "";
2305 ServiceStateTracker sst = phone.getServiceStateTracker();
2306 if (sst == null) return "";
2307 LocaleTracker lt = sst.getLocaleTracker();
2308 if (lt == null) return "";
2309 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2310 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2311 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002312 } finally {
2313 Binder.restoreCallingIdentity(identity);
2314 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002315 }
2316
2317 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002319 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002320 }
2321
Sanket Padawe356d7632015-06-22 14:03:32 -07002322 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002323 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 mApp.enforceCallingOrSelfPermission(
2325 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326
2327 final long identity = Binder.clearCallingIdentity();
2328 try {
2329 final Phone phone = getPhone(subId);
2330 if (phone != null) {
2331 phone.enableLocationUpdates();
2332 }
2333 } finally {
2334 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 }
2337
2338 @Override
2339 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002340 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002341 }
2342
Sanket Padawe356d7632015-06-22 14:03:32 -07002343 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002344 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 mApp.enforceCallingOrSelfPermission(
2346 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 final Phone phone = getPhone(subId);
2351 if (phone != null) {
2352 phone.disableLocationUpdates();
2353 }
2354 } finally {
2355 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002356 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 }
2358
Nathan Harold31d7ff32018-10-15 20:20:30 -07002359 /**
2360 * Returns the target SDK version number for a given package name.
2361 *
Nathan Haroldec184742019-07-10 17:04:16 -07002362 * This call MUST be invoked before clearing the calling UID.
2363 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002364 * @return target SDK if the package is found or INT_MAX.
2365 */
2366 private int getTargetSdk(String packageName) {
2367 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002368 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002369 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002370 if (ai != null) return ai.targetSdkVersion;
2371 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002372 loge("Failed to get package info for pkg="
2373 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002374 }
2375 return Integer.MAX_VALUE;
2376 }
2377
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 @Override
2379 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002380 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2381 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002382 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002383 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2384 throw new SecurityException(
2385 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2386 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002387
Jordan Liu1617b712019-07-10 15:06:26 -07002388 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2390 return null;
2391 }
Svetoslav64fad262015-04-14 14:35:21 -07002392
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002393 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002395 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002396 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397
Nathan Haroldf180aac2018-06-01 18:43:55 -07002398 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2399 for (CellInfo ci : info) {
2400 if (ci instanceof CellInfoGsm) {
2401 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2402 } else if (ci instanceof CellInfoWcdma) {
2403 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002406 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 }
2408
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002409 private List<CellInfo> getCachedCellInfo() {
2410 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2411 for (Phone phone : PhoneFactory.getPhones()) {
2412 List<CellInfo> info = phone.getAllCellInfo();
2413 if (info != null) cellInfos.addAll(info);
2414 }
2415 return cellInfos;
2416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417
2418 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002419 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002420 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002421 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002422
2423 LocationAccessPolicy.LocationPermissionResult locationResult =
2424 LocationAccessPolicy.checkLocationPermission(mApp,
2425 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2426 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002427 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002428 .setCallingPid(Binder.getCallingPid())
2429 .setCallingUid(Binder.getCallingUid())
2430 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002431 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002432 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2433 .build());
2434 switch (locationResult) {
2435 case DENIED_HARD:
2436 throw new SecurityException("Not allowed to access cell info");
2437 case DENIED_SOFT:
2438 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 }
2440
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002441 final int targetSdk = getTargetSdk(callingPackage);
2442 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2443 return getCachedCellInfo();
2444 }
2445
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002446 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002447 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448 final long identity = Binder.clearCallingIdentity();
2449 try {
2450 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2451 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002452 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002453 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002454 if (info != null) cellInfos.addAll(info);
2455 }
2456 return cellInfos;
2457 } finally {
2458 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 }
2460 }
2461
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002462 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002463 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2464 String callingFeatureId) {
2465 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2466 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002467 }
2468
2469 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002470 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2471 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002472 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002473 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002474 }
2475
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002476 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2477 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002478 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002479 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002480
2481 LocationAccessPolicy.LocationPermissionResult locationResult =
2482 LocationAccessPolicy.checkLocationPermission(mApp,
2483 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2484 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002485 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002486 .setCallingPid(Binder.getCallingPid())
2487 .setCallingUid(Binder.getCallingUid())
2488 .setMethod("requestCellInfoUpdate")
2489 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2490 .build());
2491 switch (locationResult) {
2492 case DENIED_HARD:
2493 throw new SecurityException("Not allowed to access cell info");
2494 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002495 try {
2496 cb.onCellInfo(new ArrayList<CellInfo>());
2497 } catch (RemoteException re) {
2498 // Drop without consequences
2499 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002500 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002501 }
2502
Nathan Harolda939a962019-05-09 10:13:47 -07002503
2504 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002505 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2506
2507 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2508 }
2509
2510 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002512 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002513 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002514
2515 final long identity = Binder.clearCallingIdentity();
2516 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002517 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002518 } finally {
2519 Binder.restoreCallingIdentity(identity);
2520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521 }
2522
Shishir Agrawala9f32182016-04-12 12:00:16 -07002523 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002524 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002525 Phone phone = PhoneFactory.getPhone(slotIndex);
2526 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002527 return null;
2528 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002529 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002530 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002531 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002532 return null;
2533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002534
2535 final long identity = Binder.clearCallingIdentity();
2536 try {
2537 return phone.getImei();
2538 } finally {
2539 Binder.restoreCallingIdentity(identity);
2540 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002541 }
2542
2543 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002544 public String getTypeAllocationCodeForSlot(int slotIndex) {
2545 Phone phone = PhoneFactory.getPhone(slotIndex);
2546 String tac = null;
2547 if (phone != null) {
2548 String imei = phone.getImei();
2549 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2550 }
2551 return tac;
2552 }
2553
2554 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002555 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002556 Phone phone = PhoneFactory.getPhone(slotIndex);
2557 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002558 return null;
2559 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002560
Jeff Davidson913390f2018-02-23 17:11:49 -08002561 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002562 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002563 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002564 return null;
2565 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566
2567 final long identity = Binder.clearCallingIdentity();
2568 try {
2569 return phone.getMeid();
2570 } finally {
2571 Binder.restoreCallingIdentity(identity);
2572 }
Jack Yu2af8d712017-03-15 17:14:14 -07002573 }
2574
2575 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002576 public String getManufacturerCodeForSlot(int slotIndex) {
2577 Phone phone = PhoneFactory.getPhone(slotIndex);
2578 String manufacturerCode = null;
2579 if (phone != null) {
2580 String meid = phone.getMeid();
2581 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2582 }
2583 return manufacturerCode;
2584 }
2585
2586 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002587 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2588 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002589 Phone phone = PhoneFactory.getPhone(slotIndex);
2590 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002591 return null;
2592 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002593 int subId = phone.getSubId();
2594 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002595 mApp, subId, callingPackage, callingFeatureId,
2596 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002597 return null;
2598 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599
2600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 return phone.getDeviceSvn();
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
2605 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002606 }
2607
fionaxu43304da2017-11-27 22:51:16 -08002608 @Override
2609 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002610 final long identity = Binder.clearCallingIdentity();
2611 try {
2612 final Phone phone = getPhone(subId);
2613 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2614 } finally {
2615 Binder.restoreCallingIdentity(identity);
2616 }
fionaxu43304da2017-11-27 22:51:16 -08002617 }
2618
2619 @Override
2620 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 final long identity = Binder.clearCallingIdentity();
2622 try {
2623 final Phone phone = getPhone(subId);
2624 return phone == null ? null : phone.getCarrierName();
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
2627 }
fionaxu43304da2017-11-27 22:51:16 -08002628 }
2629
calvinpanffe225e2018-11-01 19:43:06 +08002630 @Override
chen xu0026ca62019-03-06 15:28:50 -08002631 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002632 final long identity = Binder.clearCallingIdentity();
2633 try {
2634 final Phone phone = getPhone(subId);
2635 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002636 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002637 } finally {
2638 Binder.restoreCallingIdentity(identity);
2639 }
2640 }
2641
2642 @Override
chen xu0026ca62019-03-06 15:28:50 -08002643 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002647 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002648 } finally {
2649 Binder.restoreCallingIdentity(identity);
2650 }
2651 }
2652
chen xu651eec72018-11-11 19:03:44 -08002653 @Override
chen xu864e11c2018-12-06 22:10:03 -08002654 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2655 if (!isSubscriptionMccMnc) {
2656 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2657 }
chen xu651eec72018-11-11 19:03:44 -08002658 final Phone phone = PhoneFactory.getPhone(slotIndex);
2659 if (phone == null) {
2660 return TelephonyManager.UNKNOWN_CARRIER_ID;
2661 }
2662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2665 } finally {
2666 Binder.restoreCallingIdentity(identity);
2667 }
2668 }
2669
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 //
2671 // Internal helper methods.
2672 //
2673
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002674 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2676 *
2677 * @throws SecurityException if the caller does not have the required permission
2678 */
2679 private void enforceModifyPermission() {
2680 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2681 }
2682
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002683 /**
2684 * Make sure the caller is system.
2685 *
2686 * @throws SecurityException if the caller is not system.
2687 */
2688 private void enforceSystemCaller() {
2689 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2690 throw new SecurityException("Caller must be system");
2691 }
2692 }
2693
Shuo Qianf2b2df42019-11-13 17:43:31 -08002694 private void enforceActiveEmergencySessionPermission() {
2695 mApp.enforceCallingOrSelfPermission(
2696 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2697 }
2698
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 /**
2700 * Make sure the caller has the CALL_PHONE permission.
2701 *
2702 * @throws SecurityException if the caller does not have the required permission
2703 */
2704 private void enforceCallPermission() {
2705 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2706 }
2707
paulhu423b5f22019-08-23 19:17:33 +08002708 private void enforceSettingsPermission() {
2709 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002710 }
2711
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002712 private String createTelUrl(String number) {
2713 if (TextUtils.isEmpty(number)) {
2714 return null;
2715 }
2716
Jake Hambye994d462014-02-03 13:10:13 -08002717 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 }
2719
Ihab Awadf9e92732013-12-05 18:02:52 -08002720 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2722 }
2723
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002724 private static void logv(String msg) {
2725 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2726 }
2727
Ihab Awadf9e92732013-12-05 18:02:52 -08002728 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2730 }
2731
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002732 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002733 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002734 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002735 }
2736
Sanket Padawe356d7632015-06-22 14:03:32 -07002737 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002738 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 final Phone phone = PhoneFactory.getPhone(slotIndex);
2742 if (phone == null) {
2743 return PhoneConstants.PHONE_TYPE_NONE;
2744 } else {
2745 return phone.getPhoneType();
2746 }
2747 } finally {
2748 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002750 }
2751
2752 /**
2753 * Returns the CDMA ERI icon index to display
2754 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002755 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002756 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2757 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2758 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002759 }
2760
Sanket Padawe356d7632015-06-22 14:03:32 -07002761 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002762 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2763 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002765 mApp, subId, callingPackage, callingFeatureId,
2766 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002767 return -1;
2768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769
2770 final long identity = Binder.clearCallingIdentity();
2771 try {
2772 final Phone phone = getPhone(subId);
2773 if (phone != null) {
2774 return phone.getCdmaEriIconIndex();
2775 } else {
2776 return -1;
2777 }
2778 } finally {
2779 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002780 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002781 }
2782
2783 /**
2784 * Returns the CDMA ERI icon mode,
2785 * 0 - ON
2786 * 1 - FLASHING
2787 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002788 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002789 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2790 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2791 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002792 }
2793
Sanket Padawe356d7632015-06-22 14:03:32 -07002794 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002795 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2796 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002797 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002798 mApp, subId, callingPackage, callingFeatureId,
2799 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002800 return -1;
2801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 final Phone phone = getPhone(subId);
2806 if (phone != null) {
2807 return phone.getCdmaEriIconMode();
2808 } else {
2809 return -1;
2810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 }
2815
2816 /**
2817 * Returns the CDMA ERI text,
2818 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002819 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002820 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2821 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2822 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002823 }
2824
Sanket Padawe356d7632015-06-22 14:03:32 -07002825 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002826 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2827 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002828 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002829 mApp, subId, callingPackage, callingFeatureId,
2830 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002831 return null;
2832 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833
2834 final long identity = Binder.clearCallingIdentity();
2835 try {
2836 final Phone phone = getPhone(subId);
2837 if (phone != null) {
2838 return phone.getCdmaEriText();
2839 } else {
2840 return null;
2841 }
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002844 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002845 }
2846
2847 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002848 * Returns the CDMA MDN.
2849 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002850 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002851 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2853 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854
2855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002858 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859 return phone.getLine1Number();
2860 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002861 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 return null;
2863 }
2864 } finally {
2865 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002866 }
2867 }
2868
2869 /**
2870 * Returns the CDMA MIN.
2871 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002872 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002873 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2875 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876
2877 final long identity = Binder.clearCallingIdentity();
2878 try {
2879 final Phone phone = getPhone(subId);
2880 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2881 return phone.getCdmaMin();
2882 } else {
2883 return null;
2884 }
2885 } finally {
2886 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002887 }
2888 }
2889
Hall Liud892bec2018-11-30 14:51:45 -08002890 @Override
2891 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2892 INumberVerificationCallback callback, String callingPackage) {
2893 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2894 != PERMISSION_GRANTED) {
2895 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2896 }
2897 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2898
2899 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2900 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2901 throw new SecurityException("Calling package must be configured in the device config");
2902 }
2903
2904 if (range == null) {
2905 throw new NullPointerException("Range must be non-null");
2906 }
2907
2908 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002909 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002910
2911 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2912 }
2913
Junda Liuca05d5d2014-08-14 22:36:34 -07002914 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002915 * Returns true if CDMA provisioning needs to run.
2916 */
2917 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002918 final long identity = Binder.clearCallingIdentity();
2919 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002920 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 } finally {
2922 Binder.restoreCallingIdentity(identity);
2923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002924 }
2925
2926 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002927 * Sets the voice mail number of a given subId.
2928 */
2929 @Override
2930 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002931 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2932 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002933
2934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2937 new Pair<String, String>(alphaTag, number), new Integer(subId));
2938 return success;
2939 } finally {
2940 Binder.restoreCallingIdentity(identity);
2941 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002942 }
2943
Ta-wei Yen87c49842016-05-13 21:19:52 -07002944 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002945 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2946 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002947 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2948 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002949 if (!TextUtils.equals(callingPackage, systemDialer)) {
2950 throw new SecurityException("caller must be system dialer");
2951 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002952
2953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2956 if (phoneAccountHandle == null) {
2957 return null;
2958 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002959 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960 } finally {
2961 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002962 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002963 }
2964
2965 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002966 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2967 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002968 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002970 mApp, subId, callingPackage, callingFeatureId,
2971 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002972 return null;
2973 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002974
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002975 final long identity = Binder.clearCallingIdentity();
2976 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002977 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002981 }
2982
2983 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002984 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2985 VisualVoicemailSmsFilterSettings settings) {
2986 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987
2988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002991 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002995 }
2996
2997 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002998 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2999 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000
3001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003004 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003008 }
3009
3010 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003011 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3012 String callingPackage, int subId) {
3013 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003014
3015 final long identity = Binder.clearCallingIdentity();
3016 try {
3017 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003018 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003022 }
3023
3024 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003025 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003026 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003027
3028 final long identity = Binder.clearCallingIdentity();
3029 try {
3030 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003031 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003035 }
3036
3037 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003038 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3039 String callingAttributionTag, int subId, String number, int port, String text,
3040 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003041 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003042 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003043 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003044 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003045 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3046 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003047 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003048
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003049 /**
fionaxu0152e512016-11-14 13:36:14 -08003050 * Sets the voice activation state of a given subId.
3051 */
3052 @Override
3053 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3055 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003056
3057 final long identity = Binder.clearCallingIdentity();
3058 try {
3059 final Phone phone = getPhone(subId);
3060 if (phone != null) {
3061 phone.setVoiceActivationState(activationState);
3062 } else {
3063 loge("setVoiceActivationState fails with invalid subId: " + subId);
3064 }
3065 } finally {
3066 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003067 }
3068 }
3069
3070 /**
3071 * Sets the data activation state of a given subId.
3072 */
3073 @Override
3074 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3076 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003077
3078 final long identity = Binder.clearCallingIdentity();
3079 try {
3080 final Phone phone = getPhone(subId);
3081 if (phone != null) {
3082 phone.setDataActivationState(activationState);
3083 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003084 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003085 }
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003088 }
3089 }
3090
3091 /**
3092 * Returns the voice activation state of a given subId.
3093 */
3094 @Override
3095 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003096 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003097
fionaxu0152e512016-11-14 13:36:14 -08003098 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003099 final long identity = Binder.clearCallingIdentity();
3100 try {
3101 if (phone != null) {
3102 return phone.getVoiceActivationState();
3103 } else {
3104 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3105 }
3106 } finally {
3107 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003108 }
3109 }
3110
3111 /**
3112 * Returns the data activation state of a given subId.
3113 */
3114 @Override
3115 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003116 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117
fionaxu0152e512016-11-14 13:36:14 -08003118 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003119 final long identity = Binder.clearCallingIdentity();
3120 try {
3121 if (phone != null) {
3122 return phone.getDataActivationState();
3123 } else {
3124 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3125 }
3126 } finally {
3127 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003128 }
3129 }
3130
3131 /**
Wink Saville36469e72014-06-11 15:17:00 -07003132 * Returns the unread count of voicemails for a subId
3133 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003134 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003135 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3136 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003137 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003138 mApp, subId, callingPackage, callingFeatureId,
3139 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003140 return 0;
3141 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003142 final long identity = Binder.clearCallingIdentity();
3143 try {
3144 final Phone phone = getPhone(subId);
3145 if (phone != null) {
3146 return phone.getVoiceMessageCount();
3147 } else {
3148 return 0;
3149 }
3150 } finally {
3151 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 }
3154
3155 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003156 * returns true, if the device is in a state where both voice and data
3157 * are supported simultaneously. This can change based on location or network condition.
3158 */
3159 @Override
3160 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003161 final long identity = Binder.clearCallingIdentity();
3162 try {
3163 final Phone phone = getPhone(subId);
3164 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3165 } finally {
3166 Binder.restoreCallingIdentity(identity);
3167 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003168 }
3169
3170 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003171 * Send the dialer code if called from the current default dialer or the caller has
3172 * carrier privilege.
3173 * @param inputCode The dialer code to send
3174 */
3175 @Override
3176 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003177 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003178 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003179 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3180 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003181 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003182 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003183 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003184 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185
3186 final long identity = Binder.clearCallingIdentity();
3187 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003188 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189 } finally {
3190 Binder.restoreCallingIdentity(identity);
3191 }
fionaxu235cc5e2017-03-06 22:25:57 -08003192 }
3193
Pengquan Menga1bb6272018-09-06 09:59:22 -07003194 @Override
3195 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003196 TelephonyPermissions
3197 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3198 mApp, subId, "getNetworkSelectionMode");
3199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 if (!isActiveSubscription(subId)) {
3202 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3203 }
3204 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3205 } finally {
3206 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003207 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003208 }
3209
Brad Ebinger35c841c2018-10-01 10:40:55 -07003210 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003211 public boolean isInEmergencySmsMode() {
3212 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3213 final long identity = Binder.clearCallingIdentity();
3214 try {
3215 for (Phone phone : PhoneFactory.getPhones()) {
3216 if (phone.isInEmergencySmsMode()) {
3217 return true;
3218 }
3219 }
3220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
3223 return false;
3224 }
3225
shilu366312e2019-12-17 09:28:10 -08003226 /**
3227 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3228 * @param subId The subscription to use to check the configuration.
3229 * @param c The callback that will be used to send the result.
3230 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003231 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003232 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3233 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003234 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3235 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003236
Brad Ebinger77b832e2019-10-17 17:03:22 -07003237 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3238 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3239 "IMS not available on device.");
3240 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 final long token = Binder.clearCallingIdentity();
3242 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003243 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003244 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003245 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003246 } catch (ImsException e) {
3247 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 } finally {
3249 Binder.restoreCallingIdentity(token);
3250 }
3251 }
3252
shilu366312e2019-12-17 09:28:10 -08003253 /**
3254 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3255 * @param subId The subscription to use to check the configuration.
3256 * @param c The callback that will be used to send the result.
3257 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003258 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003259 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003260 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3261 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003262 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3263 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3264 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003265 final long token = Binder.clearCallingIdentity();
3266 try {
3267 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3268 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3269 .removeRegistrationCallbackForSubscription(c, subId);
3270 } catch (ImsException e) {
3271 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3272 + "is inactive, ignoring unregister.");
3273 // If the subscription is no longer active, just return, since the callback
3274 // will already have been removed internally.
3275 } finally {
3276 Binder.restoreCallingIdentity(token);
3277 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 }
3279
Brad Ebinger774ba362019-10-22 17:36:18 -07003280 /**
3281 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3282 */
3283 @Override
3284 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3285 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3286 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3287 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3288 "IMS not available on device.");
3289 }
3290 final long token = Binder.clearCallingIdentity();
3291 try {
3292 Phone phone = getPhone(subId);
3293 if (phone == null) {
3294 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3295 + subId + "'");
3296 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3297 }
3298 phone.getImsRegistrationState(regState -> {
3299 try {
3300 consumer.accept((regState == null)
3301 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3302 } catch (RemoteException e) {
3303 // Ignore if the remote process is no longer available to call back.
3304 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3305 }
3306 });
3307 } finally {
3308 Binder.restoreCallingIdentity(token);
3309 }
3310 }
3311
3312 /**
3313 * Get the transport type for the IMS service registration state.
3314 */
3315 @Override
3316 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003317 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3318 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003319 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3320 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3321 "IMS not available on device.");
3322 }
3323 final long token = Binder.clearCallingIdentity();
3324 try {
3325 Phone phone = getPhone(subId);
3326 if (phone == null) {
3327 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3328 + subId + "'");
3329 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3330 }
3331 phone.getImsRegistrationTech(regTech -> {
3332 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3333 int regTechConverted = (regTech == null)
3334 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3335 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3336 regTechConverted);
3337 try {
3338 consumer.accept(regTechConverted);
3339 } catch (RemoteException e) {
3340 // Ignore if the remote process is no longer available to call back.
3341 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3342 }
3343 });
3344 } finally {
3345 Binder.restoreCallingIdentity(token);
3346 }
3347 }
3348
shilu366312e2019-12-17 09:28:10 -08003349 /**
3350 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3351 * @param subId The subscription to use to check the configuration.
3352 * @param c The callback that will be used to send the result.
3353 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003354 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003355 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3356 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003357 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3358 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003359 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3360 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3361 "IMS not available on device.");
3362 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3364 final long token = Binder.clearCallingIdentity();
3365 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003366 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003367 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003368 } catch (ImsException e) {
3369 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003370 } finally {
3371 Binder.restoreCallingIdentity(token);
3372 }
3373 }
3374
shilu366312e2019-12-17 09:28:10 -08003375 /**
3376 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3377 * @param subId The subscription to use to check the configuration.
3378 * @param c The callback that will be used to send the result.
3379 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003380 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003381 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003382 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3383 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003384 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3385 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3386 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003387
3388 final long token = Binder.clearCallingIdentity();
3389 try {
3390 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3391 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003392 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003393 } catch (ImsException e) {
3394 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3395 + "is inactive, ignoring unregister.");
3396 // If the subscription is no longer active, just return, since the callback
3397 // will already have been removed internally.
3398 } finally {
3399 Binder.restoreCallingIdentity(token);
3400 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003401 }
3402
3403 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003404 public boolean isCapable(int subId, int capability, int regTech) {
3405 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003406 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3407 final long token = Binder.clearCallingIdentity();
3408 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003409 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003410 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003411 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003412 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3413 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003414 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003415 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3416 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003417 } finally {
3418 Binder.restoreCallingIdentity(token);
3419 }
3420 }
3421
3422 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003423 public boolean isAvailable(int subId, int capability, int regTech) {
3424 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003425 final long token = Binder.clearCallingIdentity();
3426 try {
3427 Phone phone = getPhone(subId);
3428 if (phone == null) return false;
3429 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003430 } catch (com.android.ims.ImsException e) {
3431 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3432 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003433 } finally {
3434 Binder.restoreCallingIdentity(token);
3435 }
3436 }
3437
Brad Ebinger77b832e2019-10-17 17:03:22 -07003438 /**
3439 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3440 * subscription.
3441 * @param subId The subscription to use to check the configuration.
3442 * @param callback The callback that will be used to send the result.
3443 * @param capability The MmTelFeature capability that will be used to send the result.
3444 * @param transportType The transport type of the MmTelFeature capability.
3445 */
3446 @Override
3447 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3448 int transportType) {
3449 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3450 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3451 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3452 "IMS not available on device.");
3453 }
3454 final long token = Binder.clearCallingIdentity();
3455 try {
3456 int slotId = getSlotIndex(subId);
3457 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3458 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3459 + subId + "'");
3460 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3461 }
3462 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3463 transportType, aBoolean -> {
3464 try {
3465 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3466 } catch (RemoteException e) {
3467 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3468 + "running. Ignore");
3469 }
3470 });
3471 } finally {
3472 Binder.restoreCallingIdentity(token);
3473 }
3474 }
3475
shilu366312e2019-12-17 09:28:10 -08003476 /**
3477 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3478 * @param subId The subscription to use to check the configuration.
3479 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003480 @Override
3481 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003482 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3483 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003484
Brad Ebinger35c841c2018-10-01 10:40:55 -07003485 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3486 final long token = Binder.clearCallingIdentity();
3487 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003488 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003489 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003490 } catch (ImsException e) {
3491 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003492 } finally {
3493 Binder.restoreCallingIdentity(token);
3494 }
3495 }
3496
3497 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003498 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003499 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003500 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003501 final long identity = Binder.clearCallingIdentity();
3502 try {
3503 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003504 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003505 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003506 } catch (ImsException e) {
3507 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003508 } finally {
3509 Binder.restoreCallingIdentity(identity);
3510 }
3511 }
3512
shilu366312e2019-12-17 09:28:10 -08003513 /**
3514 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3515 * @param subId The subscription to use to check the configuration.
3516 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003517 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003518 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003519 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3520 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003521 final long identity = Binder.clearCallingIdentity();
3522 try {
3523 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003524 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3525 } catch (ImsException e) {
3526 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
3530 }
3531
3532 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003533 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003535 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003536 final long identity = Binder.clearCallingIdentity();
3537 try {
3538 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003539 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003540 } catch (ImsException e) {
3541 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003542 } finally {
3543 Binder.restoreCallingIdentity(identity);
3544 }
3545 }
3546
shilu366312e2019-12-17 09:28:10 -08003547 /**
3548 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3549 * @param subId The subscription to use to check the configuration.
3550 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003551 @Override
3552 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003553 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3554 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003558 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003559 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003560 } catch (ImsException e) {
3561 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003562 } finally {
3563 Binder.restoreCallingIdentity(identity);
3564 }
3565 }
3566
3567 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003568 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003570 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003571 final long identity = Binder.clearCallingIdentity();
3572 try {
3573 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003574 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003575 } catch (ImsException e) {
3576 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003577 } finally {
3578 Binder.restoreCallingIdentity(identity);
3579 }
3580 }
3581
shilu366312e2019-12-17 09:28:10 -08003582 /**
3583 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3584 * @param subId The subscription to use to check the configuration.
3585 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003586 @Override
3587 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003588 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3589 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003590 final long identity = Binder.clearCallingIdentity();
3591 try {
3592 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003593 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003594 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003595 } catch (ImsException e) {
3596 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003597 } finally {
3598 Binder.restoreCallingIdentity(identity);
3599 }
3600 }
3601
3602 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003603 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003605 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003609 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003610 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003611 } catch (ImsException e) {
3612 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003613 } finally {
3614 Binder.restoreCallingIdentity(identity);
3615 }
3616 }
3617
3618 @Override
3619 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3621 "setVoWiFiNonPersistent");
3622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003625 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003626 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003627 } catch (ImsException e) {
3628 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003629 } finally {
3630 Binder.restoreCallingIdentity(identity);
3631 }
3632 }
3633
shilu366312e2019-12-17 09:28:10 -08003634 /**
3635 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3636 * @param subId The subscription to use to check the configuration.
3637 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003638 @Override
3639 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003640 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3641 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003642 final long identity = Binder.clearCallingIdentity();
3643 try {
3644 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003645 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003646 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003647 } catch (ImsException e) {
3648 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003649 } finally {
3650 Binder.restoreCallingIdentity(identity);
3651 }
3652 }
3653
3654 @Override
3655 public void setVoWiFiModeSetting(int subId, int mode) {
3656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3657 "setVoWiFiModeSetting");
3658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003661 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003662 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003663 } catch (ImsException e) {
3664 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003665 } finally {
3666 Binder.restoreCallingIdentity(identity);
3667 }
3668 }
3669
3670 @Override
3671 public int getVoWiFiRoamingModeSetting(int subId) {
3672 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003676 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003677 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003678 } catch (ImsException e) {
3679 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
3683 }
3684
3685 @Override
3686 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3687 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3688 "setVoWiFiRoamingModeSetting");
3689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003692 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003693 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003694 } catch (ImsException e) {
3695 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003696 } finally {
3697 Binder.restoreCallingIdentity(identity);
3698 }
3699 }
3700
3701 @Override
3702 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3704 "setRttCapabilityEnabled");
3705 final long identity = Binder.clearCallingIdentity();
3706 try {
3707 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003708 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3709 } catch (ImsException e) {
3710 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
3714 }
3715
shilu366312e2019-12-17 09:28:10 -08003716 /**
3717 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3718 * @param subId The subscription to use to check the configuration.
3719 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 @Override
3721 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003722 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3723 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003727 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003728 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003729 } catch (ImsException e) {
3730 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003731 } finally {
3732 Binder.restoreCallingIdentity(identity);
3733 }
3734 }
3735
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003736 @Override
3737 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3738 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3739 final long identity = Binder.clearCallingIdentity();
3740 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003741 if (!isImsAvailableOnDevice()) {
3742 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3743 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003744 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003745 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003746 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003747 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003748 } catch (ImsException e) {
3749 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003750 } finally {
3751 Binder.restoreCallingIdentity(identity);
3752 }
3753 }
3754
3755 @Override
3756 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3757 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3758 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3760 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3761 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003762 try {
3763 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003764 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003765 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003766 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003767 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3768 + "is inactive, ignoring unregister.");
3769 // If the subscription is no longer active, just return, since the callback will already
3770 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003771 } finally {
3772 Binder.restoreCallingIdentity(identity);
3773 }
3774 }
3775
allenwtsu99c623b2020-01-03 18:24:23 +08003776
3777 private void checkModifyPhoneStatePermission(int subId, String message) {
3778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3779 message);
3780 }
3781
3782 private boolean isImsProvisioningRequired(int subId, int capability,
3783 boolean isMmtelCapability) {
3784 Phone phone = getPhone(subId);
3785 if (phone == null) {
3786 loge("phone instance null for subid " + subId);
3787 return false;
3788 }
3789 if (isMmtelCapability) {
3790 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3791 return false;
3792 }
3793 } else {
3794 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3795 return false;
3796 }
3797 }
3798 return true;
3799 }
3800
3801 @Override
3802 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3803 boolean isProvisioned) {
3804 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3805
3806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3809 if (!isImsProvisioningRequired(subId, capability, false)) {
3810 return;
3811 }
3812
3813 // this capability requires provisioning, route to the correct API.
3814 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3815 switch (capability) {
3816 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3817 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3818 ims.setEabProvisioned(isProvisioned);
3819 break;
3820 default: {
3821 throw new IllegalArgumentException("Tried to set provisioning for "
3822 + "rcs capability '" + capability + "', which does not require "
3823 + "provisioning.");
3824 }
3825 }
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
3828 }
3829
3830 }
3831
3832
3833 @Override
3834 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3835 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3836 final long identity = Binder.clearCallingIdentity();
3837 try {
3838 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3839 if (!isImsProvisioningRequired(subId, capability, false)) {
3840 return true;
3841 }
3842
3843 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3844 switch (capability) {
3845 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3846 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3847 return ims.isEabProvisionedOnDevice();
3848
3849 default: {
3850 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3851 + "capability '" + capability + "', which does not require "
3852 + "provisioning.");
3853 }
3854 }
3855
3856 } finally {
3857 Binder.restoreCallingIdentity(identity);
3858 }
3859 }
3860
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003861 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003862 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3863 boolean isProvisioned) {
3864 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3865 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3866 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3867 }
allenwtsu99c623b2020-01-03 18:24:23 +08003868 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003872 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003873 return;
3874 }
3875
3876 // this capability requires provisioning, route to the correct API.
3877 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3878 switch (capability) {
3879 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3880 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3881 ims.setVolteProvisioned(isProvisioned);
3882 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3883 ims.setWfcProvisioned(isProvisioned);
3884 }
3885 break;
3886 }
3887 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3888 // There is currently no difference in VT provisioning type.
3889 ims.setVtProvisioned(isProvisioned);
3890 break;
3891 }
3892 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3893 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3894 // change the capability of the feature instead if needed.
3895 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3896 == isProvisioned) {
3897 // No change in provisioning.
3898 return;
3899 }
3900 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3901 try {
3902 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003903 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003904 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3905 + ", Exception" + e.getMessage());
3906 }
3907 break;
3908 }
3909 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003910 throw new IllegalArgumentException("Tried to set provisioning for "
3911 + "MmTel capability '" + capability + "', which does not require "
3912 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003913 }
3914 }
3915
3916 } finally {
3917 Binder.restoreCallingIdentity(identity);
3918 }
3919 }
3920
3921 @Override
3922 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3923 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3924 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3925 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3926 }
3927 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003931 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003932 return true;
3933 }
3934
3935 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3936 switch (capability) {
3937 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3938 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3939 return ims.isVolteProvisionedOnDevice();
3940 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3941 return ims.isWfcProvisionedOnDevice();
3942 }
3943 // This should never happen, since we are checking tech above to make sure it
3944 // is either LTE or IWLAN.
3945 throw new IllegalArgumentException("Invalid radio technology for voice "
3946 + "capability.");
3947 }
3948 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3949 // There is currently no difference in VT provisioning type.
3950 return ims.isVtProvisionedOnDevice();
3951 }
3952 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3953 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3954 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3955 }
3956 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003957 throw new IllegalArgumentException(
3958 "Tried to get provisioning for MmTel capability '" + capability
3959 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003960 }
3961 }
3962
3963 } finally {
3964 Binder.restoreCallingIdentity(identity);
3965 }
3966 }
3967
3968 @Override
3969 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3970 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3971 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3972 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3973 }
3974 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3975 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3976 return (provisionedBits & capability) > 0;
3977 }
3978
3979 @Override
3980 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3981 boolean isProvisioned) {
3982 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3983 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3984 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3985 }
3986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3987 "setProvisioningStatusForCapability");
3988 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3989 // If the current provisioning status for capability already matches isProvisioned,
3990 // do nothing.
3991 if (((provisionedBits & capability) > 0) == isProvisioned) {
3992 return;
3993 }
3994 if (isProvisioned) {
3995 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3996 } else {
3997 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3998 }
3999 }
4000
4001 /**
4002 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4003 * technology. The bitfield should mirror the bitfield defined by
4004 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4005 */
4006 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4007 String key = getMmTelProvisioningKey(subId, tech);
4008 // Default is no capabilities are provisioned.
4009 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4010 }
4011
4012 /**
4013 * Sets the MmTel capability provisioning bitfield (defined by
4014 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4015 * technology specified.
4016 *
4017 * Note: This is a synchronous command and should not be called on UI thread.
4018 */
4019 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4020 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4021 String key = getMmTelProvisioningKey(subId, tech);
4022 editor.putInt(key, newField);
4023 editor.commit();
4024 }
4025
4026 private static String getMmTelProvisioningKey(int subId, int tech) {
4027 // resulting key is provision_ims_mmtel_{subId}_{tech}
4028 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4029 }
4030
4031 /**
4032 * Query CarrierConfig to see if the specified capability requires provisioning for the
4033 * carrier associated with the subscription id.
4034 */
4035 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4036 int capability) {
4037 CarrierConfigManager configManager = new CarrierConfigManager(context);
4038 PersistableBundle c = configManager.getConfigForSubId(subId);
4039 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004040 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004041 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4042 false);
4043 boolean requireVoiceVtProvisioning = c.getBoolean(
4044 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4045
4046 // First check to make sure that the capability requires provisioning.
4047 switch (capability) {
4048 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4049 // intentional fallthrough
4050 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4051 if (requireVoiceVtProvisioning) {
4052 // Voice and Video requires provisioning
4053 return true;
4054 }
4055 break;
4056 }
4057 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4058 if (requireUtProvisioning) {
4059 // UT requires provisioning
4060 return true;
4061 }
4062 break;
4063 }
4064 }
4065 return false;
4066 }
4067
allenwtsu99c623b2020-01-03 18:24:23 +08004068 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4069 int capability) {
4070 CarrierConfigManager configManager = new CarrierConfigManager(context);
4071 PersistableBundle c = configManager.getConfigForSubId(subId);
4072
4073 boolean requireRcsProvisioning = c.getBoolean(
4074 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4075
4076 // First check to make sure that the capability requires provisioning.
4077 switch (capability) {
4078 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4079 // intentional fallthrough
4080 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4081 if (requireRcsProvisioning) {
4082 // OPTION or PRESENCE requires provisioning
4083 return true;
4084 }
4085 break;
4086 }
4087 }
4088 return false;
4089 }
4090
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004091 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004092 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004093 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4094 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4095 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004096 enforceReadPrivilegedPermission("getImsProvisioningInt");
4097 final long identity = Binder.clearCallingIdentity();
4098 try {
4099 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004100 int slotId = getSlotIndex(subId);
4101 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4102 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4103 + subId + "' for key:" + key);
4104 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4105 }
4106 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004107 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004108 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4109 + subId + "' for key:" + key);
4110 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004111 } finally {
4112 Binder.restoreCallingIdentity(identity);
4113 }
4114 }
4115
4116 @Override
4117 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004118 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4119 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4120 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004121 enforceReadPrivilegedPermission("getImsProvisioningString");
4122 final long identity = Binder.clearCallingIdentity();
4123 try {
4124 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004125 int slotId = getSlotIndex(subId);
4126 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4127 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4128 + subId + "' for key:" + key);
4129 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4130 }
4131 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004132 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004133 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4134 + subId + "' for key:" + key);
4135 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004136 } finally {
4137 Binder.restoreCallingIdentity(identity);
4138 }
4139 }
4140
4141 @Override
4142 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004143 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4144 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4145 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4147 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004148 final long identity = Binder.clearCallingIdentity();
4149 try {
4150 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004151 int slotId = getSlotIndex(subId);
4152 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4153 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4154 + subId + "' for key:" + key);
4155 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4156 }
4157 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004158 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004159 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4160 + "' for key:" + key);
4161 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004162 } finally {
4163 Binder.restoreCallingIdentity(identity);
4164 }
4165 }
4166
4167 @Override
4168 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004169 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4170 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4171 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4173 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004174 final long identity = Binder.clearCallingIdentity();
4175 try {
4176 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004177 int slotId = getSlotIndex(subId);
4178 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4179 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4180 + subId + "' for key:" + key);
4181 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4182 }
4183 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004184 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004185 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4186 + "' for key:" + key);
4187 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
4191 }
4192
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004193 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 int slotId = SubscriptionManager.getSlotIndex(subId);
4195 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004196 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4197 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004198 }
4199 return slotId;
4200 }
4201
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004202 private int getSlotIndex(int subId) {
4203 int slotId = SubscriptionManager.getSlotIndex(subId);
4204 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4205 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4206 }
4207 return slotId;
4208 }
4209
Wink Saville36469e72014-06-11 15:17:00 -07004210 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004211 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004212 */
4213 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004214 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4215 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004216 final int targetSdk = getTargetSdk(callingPackage);
4217 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004218 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004219 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004220 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004221 mApp, subId, callingPackage, callingFeatureId,
4222 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004223 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4224 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226 final long identity = Binder.clearCallingIdentity();
4227 try {
4228 final Phone phone = getPhone(subId);
4229 if (phone != null) {
4230 return phone.getServiceState().getDataNetworkType();
4231 } else {
4232 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4233 }
4234 } finally {
4235 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004237 }
4238
4239 /**
4240 * Returns the data network type
4241 */
4242 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004243 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4244 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4245 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004246 }
4247
4248 /**
4249 * Returns the data network type for a subId
4250 */
4251 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004252 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4253 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004254 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004255 mApp, subId, callingPackage, callingFeatureId,
4256 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004257 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4258 }
4259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 final long identity = Binder.clearCallingIdentity();
4261 try {
4262 final Phone phone = getPhone(subId);
4263 if (phone != null) {
4264 return phone.getServiceState().getDataNetworkType();
4265 } else {
4266 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4267 }
4268 } finally {
4269 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004271 }
4272
4273 /**
Wink Saville36469e72014-06-11 15:17:00 -07004274 * Returns the Voice network type for a subId
4275 */
4276 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004277 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4278 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004280 mApp, subId, callingPackage, callingFeatureId,
4281 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004282 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4283 }
4284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004285 final long identity = Binder.clearCallingIdentity();
4286 try {
4287 final Phone phone = getPhone(subId);
4288 if (phone != null) {
4289 return phone.getServiceState().getVoiceNetworkType();
4290 } else {
4291 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4292 }
4293 } finally {
4294 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004296 }
4297
4298 /**
4299 * @return true if a ICC card is present
4300 */
4301 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004302 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004303 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4304 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004305 }
4306
4307 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004308 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004309 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004310 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004311 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004312 final long identity = Binder.clearCallingIdentity();
4313 try {
4314 final Phone phone = PhoneFactory.getPhone(slotIndex);
4315 if (phone != null) {
4316 return phone.getIccCard().hasIccCard();
4317 } else {
4318 return false;
4319 }
4320 } finally {
4321 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004322 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004323 }
4324
4325 /**
4326 * Return if the current radio is LTE on CDMA. This
4327 * is a tri-state return value as for a period of time
4328 * the mode may be unknown.
4329 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004330 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004331 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004332 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004333 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004334 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004335 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4336 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4337 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004338 }
4339
Sanket Padawe356d7632015-06-22 14:03:32 -07004340 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004341 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4342 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004343 try {
4344 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4345 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004346 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4347 }
4348
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004349 final long identity = Binder.clearCallingIdentity();
4350 try {
4351 final Phone phone = getPhone(subId);
4352 if (phone == null) {
4353 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4354 } else {
4355 return phone.getLteOnCdmaMode();
4356 }
4357 } finally {
4358 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004359 }
Wink Saville36469e72014-06-11 15:17:00 -07004360 }
4361
Wink Saville36469e72014-06-11 15:17:00 -07004362 /**
4363 * {@hide}
4364 * Returns Default subId, 0 in the case of single standby.
4365 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004366 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004367 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004368 }
4369
Shishir Agrawala9f32182016-04-12 12:00:16 -07004370 private int getSlotForDefaultSubscription() {
4371 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4372 }
4373
Wink Savilleb564aae2014-10-23 10:18:09 -07004374 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004375 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004376 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004377
Pengquan Menge92a50d2018-09-21 15:54:48 -07004378 private boolean isActiveSubscription(int subId) {
4379 return mSubscriptionController.isActiveSubId(subId);
4380 }
4381
Ihab Awadf2177b72013-11-25 13:33:23 -08004382 /**
4383 * @see android.telephony.TelephonyManager.WifiCallingChoices
4384 */
4385 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004386 final long identity = Binder.clearCallingIdentity();
4387 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004388 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004389 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4390 getWhenToMakeWifiCallsDefaultPreference());
4391 } finally {
4392 Binder.restoreCallingIdentity(identity);
4393 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004394 }
4395
4396 /**
4397 * @see android.telephony.TelephonyManager.WifiCallingChoices
4398 */
4399 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004400 final long identity = Binder.clearCallingIdentity();
4401 try {
4402 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004403 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4405 } finally {
4406 Binder.restoreCallingIdentity(identity);
4407 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004408 }
4409
Sailesh Nepald1e68152013-12-12 19:08:02 -08004410 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004411 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004412 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004413 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004414
Jordan Liu4c733742019-02-28 12:03:40 -08004415 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4416 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4417 if (phoneId == -1) {
4418 throw new IllegalArgumentException("Given slot index: " + slotIndex
4419 + " does not correspond to an active phone");
4420 }
4421 return PhoneFactory.getPhone(phoneId);
4422 }
4423
Shishir Agrawal566b7612013-10-28 14:41:00 -07004424 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004425 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4426 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4428 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004429 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004430 if (DBG) {
4431 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4432 }
4433 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4434 p2);
4435 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004436
Jordan Liu4c733742019-02-28 12:03:40 -08004437
4438 @Override
4439 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4440 int slotIndex, String callingPackage, String aid, int p2) {
4441 enforceModifyPermission();
4442 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4443 if (DBG) {
4444 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4445 }
4446 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4447 callingPackage, aid, p2);
4448 }
4449
4450 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4451 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004452 final long identity = Binder.clearCallingIdentity();
4453 try {
4454 if (TextUtils.equals(ISDR_AID, aid)) {
4455 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004456 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4457 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458 if (bestComponent == null
4459 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4460 loge("The calling package is not allowed to access ISD-R.");
4461 throw new SecurityException(
4462 "The calling package is not allowed to access ISD-R.");
4463 }
Derek Tan740e1672017-06-27 14:56:27 -07004464 }
Derek Tan740e1672017-06-27 14:56:27 -07004465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004466 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004467 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4468 null /* workSource */);
4469 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004470 return response;
4471 } finally {
4472 Binder.restoreCallingIdentity(identity);
4473 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004474 }
4475
4476 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004477 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4479 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004480 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4481 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4482 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004483
Jordan Liu4c733742019-02-28 12:03:40 -08004484 @Override
4485 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4486 enforceModifyPermission();
4487 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4488 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4489 channel);
4490 }
4491
4492 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004493 final long identity = Binder.clearCallingIdentity();
4494 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 if (channel < 0) {
4496 return false;
4497 }
Jordan Liu4c733742019-02-28 12:03:40 -08004498 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4499 null /* workSource */);
4500 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004501 return success;
4502 } finally {
4503 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004504 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004505 }
4506
4507 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004508 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004509 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4511 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004512 if (DBG) {
4513 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4514 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4515 + p3 + " data=" + data);
4516 }
4517 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4518 command, p1, p2, p3, data);
4519 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004520
Jordan Liu4c733742019-02-28 12:03:40 -08004521 @Override
4522 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4523 int command, int p1, int p2, int p3, String data) {
4524 enforceModifyPermission();
4525 if (DBG) {
4526 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4527 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4528 + p3 + " data=" + data);
4529 }
4530 return iccTransmitApduLogicalChannelWithPermission(
4531 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4532 data);
4533 }
4534
4535 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4536 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004537 final long identity = Binder.clearCallingIdentity();
4538 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004539 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 return "";
4541 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004542
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004543 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004544 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4545 null /* workSource */);
4546 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004548 // Append the returned status code to the end of the response payload.
4549 String s = Integer.toHexString(
4550 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4551 if (response.payload != null) {
4552 s = IccUtils.bytesToHexString(response.payload) + s;
4553 }
4554 return s;
4555 } finally {
4556 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004557 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004558 }
Jake Hambye994d462014-02-03 13:10:13 -08004559
Evan Charltonc66da362014-05-16 14:06:40 -07004560 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004561 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4562 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4564 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004565 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004566 if (DBG) {
4567 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4568 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4569 }
4570 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4571 cla, command, p1, p2, p3, data);
4572 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004573
Jordan Liu4c733742019-02-28 12:03:40 -08004574 @Override
4575 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4576 int command, int p1, int p2, int p3, String data) {
4577 enforceModifyPermission();
4578 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4579 if (DBG) {
4580 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4581 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4582 + " data=" + data);
4583 }
4584
4585 return iccTransmitApduBasicChannelWithPermission(
4586 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4587 p2, p3, data);
4588 }
4589
4590 // open APDU basic channel assuming the caller has sufficient permissions
4591 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4592 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004593 final long identity = Binder.clearCallingIdentity();
4594 try {
4595 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4596 && TextUtils.equals(ISDR_AID, data)) {
4597 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004598 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4599 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004600 if (bestComponent == null
4601 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4602 loge("The calling package is not allowed to select ISD-R.");
4603 throw new SecurityException(
4604 "The calling package is not allowed to select ISD-R.");
4605 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004606 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004608 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004609 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4610 null /* workSource */);
4611 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004612
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004613 // Append the returned status code to the end of the response payload.
4614 String s = Integer.toHexString(
4615 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4616 if (response.payload != null) {
4617 s = IccUtils.bytesToHexString(response.payload) + s;
4618 }
4619 return s;
4620 } finally {
4621 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004622 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004623 }
4624
4625 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004626 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004627 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4629 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004630
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004631 final long identity = Binder.clearCallingIdentity();
4632 try {
4633 if (DBG) {
4634 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4635 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4636 }
4637
4638 IccIoResult response =
4639 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4640 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4641 subId);
4642
4643 if (DBG) {
4644 log("Exchange SIM_IO [R]" + response);
4645 }
4646
4647 byte[] result = null;
4648 int length = 2;
4649 if (response.payload != null) {
4650 length = 2 + response.payload.length;
4651 result = new byte[length];
4652 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4653 } else {
4654 result = new byte[length];
4655 }
4656
4657 result[length - 1] = (byte) response.sw2;
4658 result[length - 2] = (byte) response.sw1;
4659 return result;
4660 } finally {
4661 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004662 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004663 }
4664
Nathan Haroldb3014052017-01-25 15:57:32 -08004665 /**
4666 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4667 * on a particular subscription
4668 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004669 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4670 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004671 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004672 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004673 return null;
4674 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004675
4676 final long identity = Binder.clearCallingIdentity();
4677 try {
4678 if (appType != TelephonyManager.APPTYPE_USIM
4679 && appType != TelephonyManager.APPTYPE_SIM) {
4680 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4681 return null;
4682 }
4683 Object response = sendRequest(
4684 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4685 if (response instanceof String[]) {
4686 return (String[]) response;
4687 }
yincheng zhaod698b842019-09-06 17:06:54 -07004688 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004690 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691 } finally {
4692 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004693 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004694 }
4695
yincheng zhaod698b842019-09-06 17:06:54 -07004696 /**
4697 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4698 * subscription.
4699 *
4700 * @param subId the id of the subscription.
4701 * @param appType the uicc app type, must be USIM or SIM.
4702 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4703 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004704 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004705 * @return number of fplmns that is successfully written to the SIM.
4706 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004707 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4708 String callingFeatureId) {
4709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4710 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004711 if (DBG) logv("no permissions for setForbiddenplmns");
4712 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4713 }
4714 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4715 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4716 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4717 }
4718 if (fplmns == null) {
4719 throw new IllegalArgumentException("Fplmn List provided is null");
4720 }
4721 for (String fplmn : fplmns) {
4722 if (!CellIdentity.isValidPlmn(fplmn)) {
4723 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4724 }
4725 }
4726 final long identity = Binder.clearCallingIdentity();
4727 try {
4728 Object response = sendRequest(
4729 CMD_SET_FORBIDDEN_PLMNS,
4730 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4731 subId);
4732 return (int) response;
4733 } finally {
4734 Binder.restoreCallingIdentity(identity);
4735 }
4736 }
4737
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004738 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004739 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004740 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4741 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004743 final long identity = Binder.clearCallingIdentity();
4744 try {
4745 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4746 if (response.payload == null) {
4747 return "";
4748 }
Evan Charltonc66da362014-05-16 14:06:40 -07004749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004750 // Append the returned status code to the end of the response payload.
4751 String s = Integer.toHexString(
4752 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4753 s = IccUtils.bytesToHexString(response.payload) + s;
4754 return s;
4755 } finally {
4756 Binder.restoreCallingIdentity(identity);
4757 }
Evan Charltonc66da362014-05-16 14:06:40 -07004758 }
4759
Jake Hambye994d462014-02-03 13:10:13 -08004760 /**
4761 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4762 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4763 *
4764 * @param itemID the ID of the item to read
4765 * @return the NV item as a String, or null on error.
4766 */
4767 @Override
4768 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004769 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4771 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004772
4773 final long identity = Binder.clearCallingIdentity();
4774 try {
4775 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004776 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004777 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4778 return value;
4779 } finally {
4780 Binder.restoreCallingIdentity(identity);
4781 }
Jake Hambye994d462014-02-03 13:10:13 -08004782 }
4783
4784 /**
4785 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4786 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4787 *
4788 * @param itemID the ID of the item to read
4789 * @param itemValue the value to write, as a String
4790 * @return true on success; false on any failure
4791 */
4792 @Override
4793 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004794 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4796 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004797
4798 final long identity = Binder.clearCallingIdentity();
4799 try {
4800 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4801 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004802 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004803 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4804 return success;
4805 } finally {
4806 Binder.restoreCallingIdentity(identity);
4807 }
Jake Hambye994d462014-02-03 13:10:13 -08004808 }
4809
4810 /**
4811 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4812 * Used for device configuration by some CDMA operators.
4813 *
4814 * @param preferredRoamingList byte array containing the new PRL
4815 * @return true on success; false on any failure
4816 */
4817 @Override
4818 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4820 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004821
4822 final long identity = Binder.clearCallingIdentity();
4823 try {
4824 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4825 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4826 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4827 return success;
4828 } finally {
4829 Binder.restoreCallingIdentity(identity);
4830 }
Jake Hambye994d462014-02-03 13:10:13 -08004831 }
4832
4833 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004834 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004835 * Used for device configuration by some CDMA operators.
4836 *
chen xu6dac5ab2018-10-26 17:39:23 -07004837 * @param slotIndex - device slot.
4838 *
Jake Hambye994d462014-02-03 13:10:13 -08004839 * @return true on success; false on any failure
4840 */
4841 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004842 public boolean resetModemConfig(int slotIndex) {
4843 Phone phone = PhoneFactory.getPhone(slotIndex);
4844 if (phone != null) {
4845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4846 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004847
chen xu6dac5ab2018-10-26 17:39:23 -07004848 final long identity = Binder.clearCallingIdentity();
4849 try {
4850 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4851 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4852 return success;
4853 } finally {
4854 Binder.restoreCallingIdentity(identity);
4855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004856 }
chen xu6dac5ab2018-10-26 17:39:23 -07004857 return false;
4858 }
4859
4860 /**
4861 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4862 *
4863 * @param slotIndex - device slot.
4864 *
4865 * @return true on success; false on any failure
4866 */
4867 @Override
4868 public boolean rebootModem(int slotIndex) {
4869 Phone phone = PhoneFactory.getPhone(slotIndex);
4870 if (phone != null) {
4871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4872 mApp, phone.getSubId(), "rebootModem");
4873
4874 final long identity = Binder.clearCallingIdentity();
4875 try {
4876 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4877 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4878 return success;
4879 } finally {
4880 Binder.restoreCallingIdentity(identity);
4881 }
4882 }
4883 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004884 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004885
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004886 public String[] getPcscfAddress(String apnType, String callingPackage,
4887 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004888 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004889 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4890 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004891 return new String[0];
4892 }
4893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004894 final long identity = Binder.clearCallingIdentity();
4895 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004896 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004897 } finally {
4898 Binder.restoreCallingIdentity(identity);
4899 }
Wink Saville36469e72014-06-11 15:17:00 -07004900 }
4901
Brad Ebinger51f743a2017-01-23 13:50:20 -08004902 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004903 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4904 * {@link #disableIms(int)}.
4905 * @param slotIndex device slot.
4906 */
4907 public void resetIms(int slotIndex) {
4908 enforceModifyPermission();
4909
4910 final long identity = Binder.clearCallingIdentity();
4911 try {
4912 if (mImsResolver == null) {
4913 // may happen if the does not support IMS.
4914 return;
4915 }
4916 mImsResolver.disableIms(slotIndex);
4917 mImsResolver.enableIms(slotIndex);
4918 } finally {
4919 Binder.restoreCallingIdentity(identity);
4920 }
4921 }
4922
4923 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004924 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4925 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004926 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004927 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004928 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004929
4930 final long identity = Binder.clearCallingIdentity();
4931 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004932 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004933 // may happen if the device does not support IMS.
4934 return;
4935 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004936 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004937 } finally {
4938 Binder.restoreCallingIdentity(identity);
4939 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004940 }
4941
4942 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004943 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4944 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004945 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004946 public void disableIms(int slotId) {
4947 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948
4949 final long identity = Binder.clearCallingIdentity();
4950 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004951 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004952 // may happen if the device does not support IMS.
4953 return;
4954 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004955 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004956 } finally {
4957 Binder.restoreCallingIdentity(identity);
4958 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004959 }
4960
4961 /**
4962 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4963 * feature or {@link null} if the service is not available. If the feature is available, the
4964 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4965 */
4966 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004967 IImsServiceFeatureCallback callback) {
4968 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969
4970 final long identity = Binder.clearCallingIdentity();
4971 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004972 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004973 // may happen if the device does not support IMS.
4974 return null;
4975 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004976 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977 } finally {
4978 Binder.restoreCallingIdentity(identity);
4979 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004980 }
4981
4982 /**
4983 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4984 * feature during emergency calling or {@link null} if the service is not available. If the
4985 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4986 * listener for feature updates.
4987 */
4988 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4989 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004990
4991 final long identity = Binder.clearCallingIdentity();
4992 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004993 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004994 // may happen if the device does not support IMS.
4995 return null;
4996 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004997 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 } finally {
4999 Binder.restoreCallingIdentity(identity);
5000 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005001 }
5002
Brad Ebinger5f64b052017-12-14 14:26:15 -08005003 /**
5004 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005005 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005006 */
5007 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5008 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009
5010 final long identity = Binder.clearCallingIdentity();
5011 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005012 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005013 // may happen if the device does not support IMS.
5014 return null;
5015 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005016 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017 } finally {
5018 Binder.restoreCallingIdentity(identity);
5019 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005020 }
5021
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005022 /**
5023 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005024 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005025 */
5026 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5027 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028
5029 final long identity = Binder.clearCallingIdentity();
5030 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005031 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005032 // may happen if the device does not support IMS.
5033 return null;
5034 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005035 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036 } finally {
5037 Binder.restoreCallingIdentity(identity);
5038 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005039 }
5040
Brad Ebinger884c07b2018-02-15 16:17:40 -08005041 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005042 * Sets the ImsService Package Name that Telephony will bind to.
5043 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005044 * @param slotIndex the slot ID that the ImsService should bind for.
5045 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005046 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005047 * @param featureTypes An integer array of feature types associated with a packageName.
5048 * @param packageName The name of the package that the current configuration will be replaced
5049 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005050 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005051 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005052 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5053 int[] featureTypes, String packageName) {
5054 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5055 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5057 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005058 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005060 final long identity = Binder.clearCallingIdentity();
5061 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005062 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005063 // may happen if the device does not support IMS.
5064 return false;
5065 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005066 Map<Integer, String> featureConfig = new HashMap<>();
5067 for (int featureType : featureTypes) {
5068 featureConfig.put(featureType, packageName);
5069 }
5070 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5071 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005072 } finally {
5073 Binder.restoreCallingIdentity(identity);
5074 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005075 }
5076
5077 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005078 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005079 *
5080 * @param slotId The slot that the ImsService is associated with.
5081 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5082 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005083 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005084 * @return the package name of the ImsService configuration.
5085 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005086 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5087 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005088 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005089 TelephonyPermissions
5090 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5091 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5092 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 final long identity = Binder.clearCallingIdentity();
5095 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005096 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005097 // may happen if the device does not support IMS.
5098 return "";
5099 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005100 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005101 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5102 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005103 } finally {
5104 Binder.restoreCallingIdentity(identity);
5105 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005106 }
5107
Brad Ebinger77b832e2019-10-17 17:03:22 -07005108 /**
5109 * Get the MmTelFeature state associated with the requested subscription id.
5110 * @param subId The subscription that the MmTelFeature is associated with.
5111 * @param callback A callback with an integer containing the
5112 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5113 */
5114 @Override
5115 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5116 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5117 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5118 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5119 "IMS not available on device.");
5120 }
5121 final long token = Binder.clearCallingIdentity();
5122 try {
5123 int slotId = getSlotIndex(subId);
5124 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5125 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5126 + subId + "'");
5127 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5128 }
5129 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5130 try {
5131 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5132 } catch (RemoteException e) {
5133 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5134 + "Ignore");
5135 }
5136 });
5137 } finally {
5138 Binder.restoreCallingIdentity(token);
5139 }
5140 }
5141
Wink Saville36469e72014-06-11 15:17:00 -07005142 public void setImsRegistrationState(boolean registered) {
5143 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005144
5145 final long identity = Binder.clearCallingIdentity();
5146 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005147 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005148 } finally {
5149 Binder.restoreCallingIdentity(identity);
5150 }
Wink Saville36469e72014-06-11 15:17:00 -07005151 }
5152
5153 /**
Stuart Scott54788802015-03-30 13:18:01 -07005154 * Set the network selection mode to automatic.
5155 *
5156 */
5157 @Override
5158 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5160 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161
5162 final long identity = Binder.clearCallingIdentity();
5163 try {
shilufc958392020-01-20 11:36:01 -08005164 if (!isActiveSubscription(subId)) {
5165 return;
5166 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5168 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5169 } finally {
5170 Binder.restoreCallingIdentity(identity);
5171 }
Stuart Scott54788802015-03-30 13:18:01 -07005172 }
5173
Pengquan Mengea84e042018-09-20 14:57:26 -07005174 /**
5175 * Ask the radio to connect to the input network and change selection mode to manual.
5176 *
5177 * @param subId the id of the subscription.
5178 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5179 * the operator to attach to.
5180 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5181 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5182 * normal network selection next time.
5183 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005184 */
5185 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005186 public boolean setNetworkSelectionModeManual(
5187 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5189 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005190
5191 if (!isActiveSubscription(subId)) {
5192 return false;
5193 }
5194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 final long identity = Binder.clearCallingIdentity();
5196 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005197 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005199 if (DBG) {
5200 log("setNetworkSelectionModeManual: subId: " + subId
5201 + " operator: " + operatorInfo);
5202 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005203 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5204 } finally {
5205 Binder.restoreCallingIdentity(identity);
5206 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005207 }
5208
5209 /**
5210 * Scans for available networks.
5211 */
5212 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005213 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5214 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5216 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005217 LocationAccessPolicy.LocationPermissionResult locationResult =
5218 LocationAccessPolicy.checkLocationPermission(mApp,
5219 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5220 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005221 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005222 .setCallingPid(Binder.getCallingPid())
5223 .setCallingUid(Binder.getCallingUid())
5224 .setMethod("getCellNetworkScanResults")
5225 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5226 .build());
5227 switch (locationResult) {
5228 case DENIED_HARD:
5229 throw new SecurityException("Not allowed to access scan results -- location");
5230 case DENIED_SOFT:
5231 return null;
5232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005233
Pengquan Menga1bb6272018-09-06 09:59:22 -07005234 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 try {
5236 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005237 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 } finally {
5240 Binder.restoreCallingIdentity(identity);
5241 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005242 }
5243
5244 /**
sqian80370722020-01-29 15:02:51 -08005245 * Get the call forwarding info, given the call forwarding reason.
5246 */
5247 @Override
5248 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5249 enforceReadPrivilegedPermission("getCallForwarding");
5250 long identity = Binder.clearCallingIdentity();
5251 try {
5252 if (DBG) {
5253 log("getCallForwarding: subId " + subId
5254 + " callForwardingReason" + callForwardingReason);
5255 }
5256 return (CallForwardingInfo) sendRequest(
5257 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
5261 }
5262
5263 /**
5264 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5265 * reason, the number to forward, and the timeout before the forwarding is attempted.
5266 */
5267 @Override
5268 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5269 enforceModifyPermission();
5270 long identity = Binder.clearCallingIdentity();
5271 try {
5272 if (DBG) {
5273 log("setCallForwarding: subId " + subId
5274 + " callForwardingInfo" + callForwardingInfo);
5275 }
5276 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5277 } finally {
5278 Binder.restoreCallingIdentity(identity);
5279 }
5280 }
5281
5282 /**
5283 * Get the call forwarding info, given the call forwarding reason.
5284 */
5285 @Override
5286 public int getCallWaitingStatus(int subId) {
5287 enforceReadPrivilegedPermission("getCallForwarding");
5288 long identity = Binder.clearCallingIdentity();
5289 try {
5290 if (DBG) log("getCallWaitingStatus: subId " + subId);
5291 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5292 } finally {
5293 Binder.restoreCallingIdentity(identity);
5294 }
5295 }
5296
5297 /**
5298 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5299 * reason, the number to forward, and the timeout before the forwarding is attempted.
5300 */
5301 @Override
5302 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5303 enforceModifyPermission();
5304 long identity = Binder.clearCallingIdentity();
5305 try {
5306 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5307 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5308 } finally {
5309 Binder.restoreCallingIdentity(identity);
5310 }
5311 }
5312
5313 /**
yinxub1bed742017-04-17 11:45:04 -07005314 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005315 *
yinxub1bed742017-04-17 11:45:04 -07005316 * @param subId id of the subscription
5317 * @param request contains the radio access networks with bands/channels to scan
5318 * @param messenger callback messenger for scan results or errors
5319 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005320 * @return the id of the requested scan which can be used to stop the scan.
5321 */
5322 @Override
5323 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005324 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5326 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005327 LocationAccessPolicy.LocationPermissionResult locationResult =
5328 LocationAccessPolicy.checkLocationPermission(mApp,
5329 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5330 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005331 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005332 .setCallingPid(Binder.getCallingPid())
5333 .setCallingUid(Binder.getCallingUid())
5334 .setMethod("requestNetworkScan")
5335 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5336 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005337 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005338 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005339 if (e != null) {
5340 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5341 throw e;
5342 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005343 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005344 return TelephonyScanManager.INVALID_SCAN_ID;
5345 }
5346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005347 }
Hall Liu912dfd32019-04-25 14:02:26 -07005348 int callingUid = Binder.getCallingUid();
5349 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005350 final long identity = Binder.clearCallingIdentity();
5351 try {
5352 return mNetworkScanRequestTracker.startNetworkScan(
5353 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005354 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005355 } finally {
5356 Binder.restoreCallingIdentity(identity);
5357 }
yinxu504e1392017-04-12 16:03:22 -07005358 }
5359
Hall Liub2ac8ef2019-02-28 15:56:23 -08005360 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005361 NetworkScanRequest request, int subId) {
5362 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5363 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5364 boolean hasNetworkScanPermission =
5365 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5366 == PERMISSION_GRANTED;
5367
5368 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5369 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5370 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005371 }
5372
5373 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5374 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005375 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5376 return new SecurityException("Specific channels must not be"
5377 + " scanned without location access.");
5378 }
5379 }
5380 }
5381
Hall Liub2ac8ef2019-02-28 15:56:23 -08005382 return null;
5383 }
5384
yinxu504e1392017-04-12 16:03:22 -07005385 /**
5386 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005387 *
5388 * @param subId id of the subscription
5389 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005390 */
5391 @Override
5392 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5394 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395
Hall Liu912dfd32019-04-25 14:02:26 -07005396 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 final long identity = Binder.clearCallingIdentity();
5398 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005399 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 } finally {
5401 Binder.restoreCallingIdentity(identity);
5402 }
yinxu504e1392017-04-12 16:03:22 -07005403 }
5404
5405 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005406 * Get the calculated preferred network type.
5407 * Used for debugging incorrect network type.
5408 *
5409 * @return the preferred network type, defined in RILConstants.java.
5410 */
5411 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005412 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005413 final Phone defaultPhone = getDefaultPhone();
5414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005415 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005416 return RILConstants.PREFERRED_NETWORK_MODE;
5417 }
5418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 final long identity = Binder.clearCallingIdentity();
5420 try {
5421 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005422 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005423 } finally {
5424 Binder.restoreCallingIdentity(identity);
5425 }
Junda Liu84d15a22014-07-02 11:21:04 -07005426 }
5427
5428 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005429 * Get the preferred network type.
5430 * Used for device configuration by some CDMA operators.
5431 *
5432 * @return the preferred network type, defined in RILConstants.java.
5433 */
5434 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005435 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005436 TelephonyPermissions
5437 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5438 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439
5440 final long identity = Binder.clearCallingIdentity();
5441 try {
5442 if (DBG) log("getPreferredNetworkType");
5443 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5444 int networkType = (result != null ? result[0] : -1);
5445 if (DBG) log("getPreferredNetworkType: " + networkType);
5446 return networkType;
5447 } finally {
5448 Binder.restoreCallingIdentity(identity);
5449 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005450 }
5451
5452 /**
5453 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005454 *
5455 * @param networkType the preferred network type, defined in RILConstants.java.
5456 * @return true on success; false on any failure.
5457 */
5458 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005459 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5461 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462
5463 final long identity = Binder.clearCallingIdentity();
5464 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005465 Settings.Global.putInt(mApp.getContentResolver(),
5466 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005467
5468 Boolean success = (Boolean) sendRequest(
5469 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5470 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5471 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005472 } finally {
5473 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005474 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005475 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005476
5477 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005478 * Get the allowed network types that store in the telephony provider.
5479 *
5480 * @param subId the id of the subscription.
5481 * @return allowedNetworkTypes the allowed network types.
5482 */
5483 @Override
5484 public long getAllowedNetworkTypes(int subId) {
5485 TelephonyPermissions
5486 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5487 mApp, subId, "getAllowedNetworkTypes");
5488
5489 final long identity = Binder.clearCallingIdentity();
5490 try {
5491 return SubscriptionManager.getLongSubscriptionProperty(
5492 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5493 } finally {
5494 Binder.restoreCallingIdentity(identity);
5495 }
5496 }
5497
5498 /**
5499 * Set the allowed network types.
5500 *
5501 * @param subId the id of the subscription.
5502 * @param allowedNetworkTypes the allowed network types.
5503 * @return true on success; false on any failure.
5504 */
5505 @Override
5506 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5508 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005509
calvinpan089c2a62020-03-12 14:17:55 +08005510 SubscriptionManager.setSubscriptionProperty(subId,
5511 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5512 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005513
calvinpan089c2a62020-03-12 14:17:55 +08005514 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5515 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5516 RILConstants.PREFERRED_NETWORK_MODE);
5517 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005518 }
5519
5520 /**
Miaoa84611c2019-03-15 09:21:10 +08005521 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005522 *
Miaoa84611c2019-03-15 09:21:10 +08005523 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005524 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005525 * @hide
5526 */
5527 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005528 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005529 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005531 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532 try {
Miaoa84611c2019-03-15 09:21:10 +08005533 if (phone != null) {
5534 return phone.hasMatchedTetherApnSetting();
5535 } else {
5536 return false;
5537 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005538 } finally {
5539 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005540 }
Junda Liu475951f2014-11-07 16:45:03 -08005541 }
5542
5543 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005544 * Set mobile data enabled
5545 * Used by the user through settings etc to turn on/off mobile data
5546 *
5547 * @param enable {@code true} turn turn data on, else {@code false}
5548 */
5549 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005550 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5552 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553
5554 final long identity = Binder.clearCallingIdentity();
5555 try {
5556 int phoneId = mSubscriptionController.getPhoneId(subId);
5557 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5558 Phone phone = PhoneFactory.getPhone(phoneId);
5559 if (phone != null) {
5560 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005561 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005563 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564 }
5565 } finally {
5566 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005567 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005568 }
5569
5570 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005571 * Enable or disable always reporting signal strength changes from radio.
5572 *
5573 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5574 */
5575 @Override
5576 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5577 enforceModifyPermission();
5578 enforceSystemCaller();
5579
5580 final long identity = Binder.clearCallingIdentity();
5581 final Phone phone = getPhone(subId);
5582 try {
5583 if (phone != null) {
5584 if (DBG) {
5585 log("setAlwaysReportSignalStrength: subId=" + subId
5586 + " isEnable=" + isEnable);
5587 }
5588 phone.setAlwaysReportSignalStrength(isEnable);
5589 } else {
5590 loge("setAlwaysReportSignalStrength: no phone found for subId="
5591 + subId);
5592 }
5593 } finally {
5594 Binder.restoreCallingIdentity(identity);
5595 }
5596 }
5597
5598 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005599 * Get the user enabled state of Mobile Data.
5600 *
5601 * TODO: remove and use isUserDataEnabled.
5602 * This can't be removed now because some vendor codes
5603 * calls through ITelephony directly while they should
5604 * use TelephonyManager.
5605 *
5606 * @return true on enabled
5607 */
5608 @Override
5609 public boolean getDataEnabled(int subId) {
5610 return isUserDataEnabled(subId);
5611 }
5612
5613 /**
5614 * Get whether mobile data is enabled per user setting.
5615 *
5616 * There are other factors deciding whether mobile data is actually enabled, but they are
5617 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005618 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005619 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005620 *
5621 * @return {@code true} if data is enabled else {@code false}
5622 */
5623 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005624 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005625 try {
5626 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5627 null);
5628 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5630 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005632
5633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 int phoneId = mSubscriptionController.getPhoneId(subId);
5636 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5637 Phone phone = PhoneFactory.getPhone(phoneId);
5638 if (phone != null) {
5639 boolean retVal = phone.isUserDataEnabled();
5640 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5641 return retVal;
5642 } else {
5643 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5644 return false;
5645 }
5646 } finally {
5647 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005648 }
5649 }
5650
5651 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005652 * Checks if the device is capable of mobile data by considering whether whether the
5653 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5654 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005655 *
Shuo Qian985d1232020-01-08 14:30:06 -08005656 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005657 */
5658 @Override
5659 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005660 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661
5662 final long identity = Binder.clearCallingIdentity();
5663 try {
5664 int phoneId = mSubscriptionController.getPhoneId(subId);
5665 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5666 Phone phone = PhoneFactory.getPhone(phoneId);
5667 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005668 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005669 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5670 return retVal;
5671 } else {
5672 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5673 return false;
5674 }
5675 } finally {
5676 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005677 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005678 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005679
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005680 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005681 Phone phone) {
5682 //load access rules from carrier configs, and check those as well: b/139133814
5683 SubscriptionController subController = SubscriptionController.getInstance();
5684 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5685 || subController == null) return privilegeFromSim;
5686
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005687 PackageManager pkgMgr = phone.getContext().getPackageManager();
5688 String[] packages = pkgMgr.getPackagesForUid(uid);
5689
5690 final long identity = Binder.clearCallingIdentity();
5691 try {
5692 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5693 SubscriptionManager subManager = (SubscriptionManager)
5694 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5695 for (String pkg : packages) {
5696 if (subManager.canManageSubscription(subInfo, pkg)) {
5697 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5698 }
5699 }
5700 return privilegeFromSim;
5701 } finally {
5702 Binder.restoreCallingIdentity(identity);
5703 }
5704 }
5705
5706 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5707 String pkgName) {
5708 //load access rules from carrier configs, and check those as well: b/139133814
5709 SubscriptionController subController = SubscriptionController.getInstance();
5710 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5711 || subController == null) return privilegeFromSim;
5712
5713 final long identity = Binder.clearCallingIdentity();
5714 try {
5715 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5716 SubscriptionManager subManager = (SubscriptionManager)
5717 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5718 return subManager.canManageSubscription(subInfo, pkgName)
5719 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5720 } finally {
5721 Binder.restoreCallingIdentity(identity);
5722 }
5723 }
5724
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005725 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005726 public int getCarrierPrivilegeStatus(int subId) {
5727 final Phone phone = getPhone(subId);
5728 if (phone == null) {
5729 loge("getCarrierPrivilegeStatus: Invalid subId");
5730 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5731 }
5732 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005733 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005734 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005735 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5736 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005737
5738 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5739 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005740 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005741 }
Junda Liu29340342014-07-10 15:23:27 -07005742
5743 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005744 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005745 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005746 final Phone phone = getPhone(subId);
5747 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005748 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005749 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5750 }
5751 UiccProfile profile =
5752 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5753 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005754 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005755 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5756 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005757 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005758 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005759 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005760 }
5761
5762 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005763 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5764 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005765 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005766 }
5767
5768 int phoneId = SubscriptionManager.getPhoneId(subId);
5769 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005770 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005771 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005772 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5773 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005774 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5775 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5776 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005777 }
5778
5779 @Override
5780 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005781 if (TextUtils.isEmpty(pkgName))
5782 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005783 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5784 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5785 UiccCard card = UiccController.getInstance().getUiccCard(i);
5786 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005787 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005788 continue;
5789 }
5790
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005791 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5792 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5793 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005794 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5795 break;
5796 }
5797 }
5798
5799 return result;
Junda Liu29340342014-07-10 15:23:27 -07005800 }
Derek Tan89e89d42014-07-08 17:00:10 -07005801
5802 @Override
Junda Liue64de782015-04-16 17:19:16 -07005803 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5804 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5805 loge("phoneId " + phoneId + " is not valid.");
5806 return null;
5807 }
5808 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005809 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005810 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005811 return null ;
5812 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005813 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005814 }
5815
Amith Yamasani6e118872016-02-19 12:53:51 -08005816 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005817 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005818 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005819 List<String> privilegedPackages = new ArrayList<>();
5820 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005821 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5822 // has UICC in that slot.
5823 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005824 if (card.hasCarrierPrivilegeRules()) {
5825 if (packages == null) {
5826 // Only check packages in user 0 for now
5827 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005828 PackageManager.MATCH_DISABLED_COMPONENTS
5829 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005830 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005831 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005832 }
5833 for (int p = packages.size() - 1; p >= 0; p--) {
5834 PackageInfo pkgInfo = packages.get(p);
5835 if (pkgInfo != null && pkgInfo.packageName != null
5836 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005837 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005838 privilegedPackages.add(pkgInfo.packageName);
5839 }
5840 }
5841 }
5842 }
5843 return privilegedPackages;
5844 }
5845
chen xuf7e9fe82019-05-09 19:31:02 -07005846 @Override
5847 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005848 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5849
5850 final long identity = Binder.clearCallingIdentity();
5851
chen xuf7e9fe82019-05-09 19:31:02 -07005852 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005853 try {
5854 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5855 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5856 }
5857 } finally {
5858 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005859 }
5860 return privilegedPackages;
5861 }
5862
Wink Savilleb564aae2014-10-23 10:18:09 -07005863 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005864 final Phone phone = getPhone(subId);
5865 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005866 if (card == null) {
5867 loge("getIccId: No UICC");
5868 return null;
5869 }
5870 String iccId = card.getIccId();
5871 if (TextUtils.isEmpty(iccId)) {
5872 loge("getIccId: ICC ID is null or empty.");
5873 return null;
5874 }
5875 return iccId;
5876 }
5877
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005878 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005879 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5880 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005881 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005882 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005884 final long identity = Binder.clearCallingIdentity();
5885 try {
5886 final String iccId = getIccId(subId);
5887 final Phone phone = getPhone(subId);
5888 if (phone == null) {
5889 return false;
5890 }
5891 final String subscriberId = phone.getSubscriberId();
5892
5893 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005894 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895 + subscriberId + " to " + number);
5896 }
5897
5898 if (TextUtils.isEmpty(iccId)) {
5899 return false;
5900 }
5901
5902 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5903
5904 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5905 if (alphaTag == null) {
5906 editor.remove(alphaTagPrefKey);
5907 } else {
5908 editor.putString(alphaTagPrefKey, alphaTag);
5909 }
5910
5911 // Record both the line number and IMSI for this ICCID, since we need to
5912 // track all merged IMSIs based on line number
5913 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5914 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5915 if (number == null) {
5916 editor.remove(numberPrefKey);
5917 editor.remove(subscriberPrefKey);
5918 } else {
5919 editor.putString(numberPrefKey, number);
5920 editor.putString(subscriberPrefKey, subscriberId);
5921 }
5922
5923 editor.commit();
5924 return true;
5925 } finally {
5926 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005927 }
Derek Tan7226c842014-07-02 17:42:23 -07005928 }
5929
5930 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005931 public String getLine1NumberForDisplay(int subId, String callingPackage,
5932 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005933 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005934 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005935 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005936 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005937 return null;
5938 }
Derek Tan97ebb422014-09-05 16:55:38 -07005939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940 final long identity = Binder.clearCallingIdentity();
5941 try {
5942 String iccId = getIccId(subId);
5943 if (iccId != null) {
5944 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5945 if (DBG_MERGE) {
5946 log("getLine1NumberForDisplay returning "
5947 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5948 }
5949 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5952 return null;
5953 } finally {
5954 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005955 }
Derek Tan7226c842014-07-02 17:42:23 -07005956 }
5957
5958 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005959 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5960 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005961 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005962 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005963 return null;
5964 }
Derek Tan97ebb422014-09-05 16:55:38 -07005965
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966 final long identity = Binder.clearCallingIdentity();
5967 try {
5968 String iccId = getIccId(subId);
5969 if (iccId != null) {
5970 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5971 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5972 }
5973 return null;
5974 } finally {
5975 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005976 }
Derek Tan7226c842014-07-02 17:42:23 -07005977 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005978
5979 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005980 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5981 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005982 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5983 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005984 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005985 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005986 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005987 return null;
5988 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005989
Jordan Liub49b04b2019-05-06 14:45:15 -07005990 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5991 // the process, where TelephonyManager was instantiated.
5992 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005993 final long identity = Binder.clearCallingIdentity();
5994 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005995 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 final TelephonyManager tele = TelephonyManager.from(context);
5997 final SubscriptionManager sub = SubscriptionManager.from(context);
5998
5999 // Figure out what subscribers are currently active
6000 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001
Jordan Liub49b04b2019-05-06 14:45:15 -07006002 // Only consider subs which match the current subId
6003 // This logic can be simplified. See b/131189269 for progress.
6004 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006005 activeSubscriberIds.add(tele.getSubscriberId(subId));
6006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007
6008 // First pass, find a number override for an active subscriber
6009 String mergeNumber = null;
6010 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6011 for (String key : prefs.keySet()) {
6012 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6013 final String subscriberId = (String) prefs.get(key);
6014 if (activeSubscriberIds.contains(subscriberId)) {
6015 final String iccId = key.substring(
6016 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6017 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6018 mergeNumber = (String) prefs.get(numberKey);
6019 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006020 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 + " for active subscriber " + subscriberId);
6022 }
6023 if (!TextUtils.isEmpty(mergeNumber)) {
6024 break;
6025 }
6026 }
6027 }
6028 }
6029
6030 // Shortcut when no active merged subscribers
6031 if (TextUtils.isEmpty(mergeNumber)) {
6032 return null;
6033 }
6034
6035 // Second pass, find all subscribers under that line override
6036 final ArraySet<String> result = new ArraySet<>();
6037 for (String key : prefs.keySet()) {
6038 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6039 final String number = (String) prefs.get(key);
6040 if (mergeNumber.equals(number)) {
6041 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6042 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6043 final String subscriberId = (String) prefs.get(subscriberKey);
6044 if (!TextUtils.isEmpty(subscriberId)) {
6045 result.add(subscriberId);
6046 }
6047 }
6048 }
6049 }
6050
6051 final String[] resultArray = result.toArray(new String[result.size()]);
6052 Arrays.sort(resultArray);
6053 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006054 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6056 }
6057 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006058 } finally {
6059 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006060 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006061 }
6062
6063 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006064 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6065 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6066
6067 final long identity = Binder.clearCallingIdentity();
6068 try {
6069 final TelephonyManager telephonyManager = mApp.getSystemService(
6070 TelephonyManager.class);
6071 String subscriberId = telephonyManager.getSubscriberId(subId);
6072 if (subscriberId == null) {
6073 if (DBG) {
6074 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6075 + subId);
6076 }
6077 return null;
6078 }
6079
6080 final SubscriptionInfo info = SubscriptionController.getInstance()
6081 .getSubscriptionInfo(subId);
6082 final ParcelUuid groupUuid = info.getGroupUuid();
6083 // If it doesn't belong to any group, return just subscriberId of itself.
6084 if (groupUuid == null) {
6085 return new String[]{subscriberId};
6086 }
6087
6088 // Get all subscriberIds from the group.
6089 final List<String> mergedSubscriberIds = new ArrayList<>();
6090 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006091 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6092 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006093 for (SubscriptionInfo subInfo : groupInfos) {
6094 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6095 if (subscriberId != null) {
6096 mergedSubscriberIds.add(subscriberId);
6097 }
6098 }
6099
6100 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6101 } finally {
6102 Binder.restoreCallingIdentity(identity);
6103
6104 }
6105 }
6106
6107 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006108 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006109 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006110 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111
6112 final long identity = Binder.clearCallingIdentity();
6113 try {
6114 final Phone phone = getPhone(subId);
6115 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6116 } finally {
6117 Binder.restoreCallingIdentity(identity);
6118 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006119 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006120
6121 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006122 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006123 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6124 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006125 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6126 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006127
6128 final long identity = Binder.clearCallingIdentity();
6129 try {
6130 final Phone phone = getPhone(subId);
6131 if (phone == null) {
6132 return false;
6133 }
6134 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6135 cdmaNonRoamingList);
6136 } finally {
6137 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006138 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006139 }
6140
6141 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006142 @Deprecated
6143 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6144 enforceModifyPermission();
6145
6146 int returnValue = 0;
6147 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006148 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006149 if(result.exception == null) {
6150 if (result.result != null) {
6151 byte[] responseData = (byte[])(result.result);
6152 if(responseData.length > oemResp.length) {
6153 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6154 responseData.length + "bytes. Buffer Size is " +
6155 oemResp.length + "bytes.");
6156 }
6157 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6158 returnValue = responseData.length;
6159 }
6160 } else {
6161 CommandException ex = (CommandException) result.exception;
6162 returnValue = ex.getCommandError().ordinal();
6163 if(returnValue > 0) returnValue *= -1;
6164 }
6165 } catch (RuntimeException e) {
6166 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6167 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6168 if(returnValue > 0) returnValue *= -1;
6169 }
6170
6171 return returnValue;
6172 }
6173
6174 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006175 public void setRadioCapability(RadioAccessFamily[] rafs) {
6176 try {
6177 ProxyController.getInstance().setRadioCapability(rafs);
6178 } catch (RuntimeException e) {
6179 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6180 }
6181 }
6182
6183 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006184 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006185 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006186 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006187 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006188 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006189 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190 final long identity = Binder.clearCallingIdentity();
6191 try {
chen xub97461a2018-10-26 14:17:57 -07006192 TelephonyPermissions
6193 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6194 mApp, phone.getSubId(), "getRadioAccessFamily");
6195 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006196 } finally {
6197 Binder.restoreCallingIdentity(identity);
6198 }
chen xub97461a2018-10-26 14:17:57 -07006199 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006200 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006201
6202 @Override
6203 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006204 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006205 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006206
6207 final long identity = Binder.clearCallingIdentity();
6208 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006209 ImsManager.getInstance(defaultPhone.getContext(),
6210 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006211 } finally {
6212 Binder.restoreCallingIdentity(identity);
6213 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006214 }
6215
6216 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006217 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006218 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6220 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006221 return false;
6222 }
Svet Ganovb320e182015-04-16 12:30:10 -07006223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 final long identity = Binder.clearCallingIdentity();
6225 try {
6226 // Check the user preference and the system-level IMS setting. Even if the user has
6227 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6228 // In the long run, we may instead need to check if there exists a connection service
6229 // which can support video calling.
6230 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006231 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232 return imsManager.isVtEnabledByPlatform()
6233 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6234 && imsManager.isVtEnabledByUser();
6235 } finally {
6236 Binder.restoreCallingIdentity(identity);
6237 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006238 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006239
Andrew Leea1239f22015-03-02 17:44:07 -08006240 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006241 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6242 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006244 mApp, subId, callingPackage, callingFeatureId,
6245 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006246 return false;
6247 }
6248
6249 final long identity = Binder.clearCallingIdentity();
6250 try {
6251 CarrierConfigManager configManager =
6252 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006253 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006254 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6255 } finally {
6256 Binder.restoreCallingIdentity(identity);
6257 }
Andrew Leea1239f22015-03-02 17:44:07 -08006258 }
6259
6260 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006261 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006263 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006264 return false;
6265 }
6266
6267 final long identity = Binder.clearCallingIdentity();
6268 try {
6269 CarrierConfigManager configManager =
6270 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006271 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6273 } finally {
6274 Binder.restoreCallingIdentity(identity);
6275 }
Andrew Leea1239f22015-03-02 17:44:07 -08006276 }
6277
Andrew Lee9431b832015-03-09 18:46:45 -07006278 @Override
6279 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006280 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006281 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006282 }
6283
6284 @Override
6285 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286 final long identity = Binder.clearCallingIdentity();
6287 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006288 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 } finally {
6290 Binder.restoreCallingIdentity(identity);
6291 }
Andrew Lee9431b832015-03-09 18:46:45 -07006292 }
6293
Hall Liuf6668912018-10-31 17:05:23 -07006294 /**
6295 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6296 * support for the feature and device firmware support.
6297 *
6298 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6299 */
6300 @Override
6301 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006302 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006303 final Phone phone = getPhone(subscriptionId);
6304 if (phone == null) {
6305 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6306 return false;
6307 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006309 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6311 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006312 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006313 return isCarrierSupported && isDeviceSupported;
6314 } finally {
6315 Binder.restoreCallingIdentity(identity);
6316 }
Hall Liu98187582018-01-22 19:15:32 -08006317 }
6318
Hall Liuf6668912018-10-31 17:05:23 -07006319 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006320 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6321 * RTT setting, will return true if the device and carrier both support RTT.
6322 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006323 */
6324 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006325 final long identity = Binder.clearCallingIdentity();
6326 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006327 boolean isRttSupported = isRttSupported(subscriptionId);
6328 boolean isUserRttSettingOn = Settings.Secure.getInt(
6329 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6330 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6331 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6332 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333 } finally {
6334 Binder.restoreCallingIdentity(identity);
6335 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006336 }
6337
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006338 @Deprecated
6339 @Override
6340 public String getDeviceId(String callingPackage) {
6341 return getDeviceIdWithFeature(callingPackage, null);
6342 }
6343
Sanket Padawe7310cc72015-01-14 09:53:20 -08006344 /**
6345 * Returns the unique device ID of phone, for example, the IMEI for
6346 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6347 *
6348 * <p>Requires Permission:
6349 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6350 */
6351 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006352 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006353 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006354 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006355 return null;
6356 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006357 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006358 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006359 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006360 return null;
6361 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006362
6363 final long identity = Binder.clearCallingIdentity();
6364 try {
6365 return phone.getDeviceId();
6366 } finally {
6367 Binder.restoreCallingIdentity(identity);
6368 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006369 }
6370
Ping Sunc67b7c22016-03-02 19:16:45 +08006371 /**
6372 * {@hide}
6373 * Returns the IMS Registration Status on a particular subid
6374 *
6375 * @param subId
6376 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006377 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006378 Phone phone = getPhone(subId);
6379 if (phone != null) {
6380 return phone.isImsRegistered();
6381 } else {
6382 return false;
6383 }
6384 }
6385
Santos Cordon7a1885b2015-02-03 11:15:19 -08006386 @Override
6387 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388 final long identity = Binder.clearCallingIdentity();
6389 try {
6390 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6391 } finally {
6392 Binder.restoreCallingIdentity(identity);
6393 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006394 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006395
Tyler Gunnf70ed162019-04-03 15:28:53 -07006396 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006397 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006398 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006399 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006400 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006401 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6402 }
6403 final long identity = Binder.clearCallingIdentity();
6404 try {
6405 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6406 } finally {
6407 Binder.restoreCallingIdentity(identity);
6408 }
6409 }
6410
6411 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006412 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6413 final long identity = Binder.clearCallingIdentity();
6414 try {
6415 Phone phone = getPhone(subscriptionId);
6416 if (phone == null) {
6417 return null;
6418 }
6419 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6420 } finally {
6421 Binder.restoreCallingIdentity(identity);
6422 }
6423 }
6424
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006425 /**
6426 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006427 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006428 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429 final long identity = Binder.clearCallingIdentity();
6430 try {
6431 Phone phone = getPhone(subId);
6432 if (phone != null) {
6433 return phone.isWifiCallingEnabled();
6434 } else {
6435 return false;
6436 }
6437 } finally {
6438 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006439 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006440 }
6441
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006442 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006443 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006444 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006445 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006446 final long identity = Binder.clearCallingIdentity();
6447 try {
6448 Phone phone = getPhone(subId);
6449 if (phone != null) {
6450 return phone.isVideoEnabled();
6451 } else {
6452 return false;
6453 }
6454 } finally {
6455 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006456 }
6457 }
6458
6459 /**
6460 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6461 * defined in {@link ImsRegistrationImplBase}.
6462 */
6463 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006464 final long identity = Binder.clearCallingIdentity();
6465 try {
6466 Phone phone = getPhone(subId);
6467 if (phone != null) {
6468 return phone.getImsRegistrationTech();
6469 } else {
6470 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6471 }
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006474 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006475 }
6476
Stuart Scott8eef64f2015-04-08 15:13:54 -07006477 @Override
6478 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006479 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006480 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6481 return;
6482 }
6483
Svet Ganovcc087f82015-05-12 20:35:54 -07006484 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006485
Svet Ganovcc087f82015-05-12 20:35:54 -07006486 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006487 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6488 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006489 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006490 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006491 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006492 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6493 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006494 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006495 // There has been issues when Sms raw table somehow stores orphan
6496 // fragments. They lead to garbled message when new fragments come
6497 // in and combined with those stale ones. In case this happens again,
6498 // user can reset all network settings which will clean up this table.
6499 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006500 // Clean up IMS settings as well here.
6501 int slotId = getSlotIndex(subId);
6502 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6503 ImsManager.getInstance(mApp, slotId).factoryReset();
6504 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006505
6506 // Erase modem config if erase modem on network setting is enabled.
6507 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6508 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6509 if (configValue != null && Boolean.parseBoolean(configValue)) {
6510 sendEraseModemConfig(getDefaultPhone());
6511 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006512 } finally {
6513 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006514 }
6515 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006516
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006517 private void cleanUpSmsRawTable(Context context) {
6518 ContentResolver resolver = context.getContentResolver();
6519 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6520 resolver.delete(uri, null, null);
6521 }
6522
Narayan Kamath1c496c22015-04-16 14:40:19 +01006523 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006524 public String getSimLocaleForSubscriber(int subId) {
6525 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6526 final Phone phone = getPhone(subId);
6527 if (phone == null) {
6528 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006529 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006531 final long identity = Binder.clearCallingIdentity();
6532 try {
chen xu5d3637b2019-01-21 23:31:38 -08006533 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006534 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006535 if (info == null) {
6536 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6537 return null;
6538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006539 // Try and fetch the locale from the carrier properties or from the SIM language
6540 // preferences (EF-PL and EF-LI)...
6541 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006543 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6544 if (localeFromDefaultSim != null) {
6545 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6546 if (DBG) log("Using locale from subId: " + subId + " locale: "
6547 + localeFromDefaultSim);
6548 return localeFromDefaultSim.toLanguageTag();
6549 } else {
6550 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551 }
6552 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554 // The SIM language preferences only store a language (e.g. fr = French), not an
6555 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6556 // the SIM and carrier preferences does not include a country we add the country
6557 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006558 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006560 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006561 return mccLocale.toLanguageTag();
6562 }
6563
6564 if (DBG) log("No locale found - returning null");
6565 return null;
6566 } finally {
6567 Binder.restoreCallingIdentity(identity);
6568 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006569 }
6570
6571 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006572 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6573 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006574 }
6575
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006576 /**
6577 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6578 */
6579 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006580 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6581 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006582 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006583
Chenjie Yu1ba97252018-01-11 18:16:20 -08006584 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006585 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006586
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006587 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006588 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6589 * representing the state of the modem.
6590 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006591 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6592 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006593 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006594 */
6595 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006596 public void requestModemActivityInfo(ResultReceiver result) {
6597 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006598 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006599
6600 final long identity = Binder.clearCallingIdentity();
6601 try {
sqian1a1be542020-03-05 11:37:28 -08006602 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006603 } finally {
6604 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006605 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006606 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006607
Siddharth Rayb8114062018-06-17 15:02:38 -07006608 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6609 // less than total activity duration.
6610 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6611 if (info == null) {
6612 return false;
6613 }
6614 int activityDurationMs =
6615 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6616 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006617 int[] txTimeMs = info.getTransmitTimeMillis();
6618 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6619 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006620 }
6621 return (info.isValid()
6622 && (info.getSleepTimeMillis() <= activityDurationMs)
6623 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006624 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006625 && (totalTxTimeMs <= activityDurationMs));
6626 }
6627
Jack Yu85bd38a2015-11-09 11:34:32 -08006628 /**
6629 * {@hide}
6630 * Returns the service state information on specified subscription.
6631 */
6632 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006633 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6634 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006636 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006637 return null;
6638 }
6639
Hall Liuf19c44f2018-11-27 14:38:17 -08006640 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6641 LocationAccessPolicy.checkLocationPermission(mApp,
6642 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6643 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006644 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006645 .setCallingPid(Binder.getCallingPid())
6646 .setCallingUid(Binder.getCallingUid())
6647 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006648 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006649 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6650 .build());
6651
6652 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6653 LocationAccessPolicy.checkLocationPermission(mApp,
6654 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6655 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006656 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006657 .setCallingPid(Binder.getCallingPid())
6658 .setCallingUid(Binder.getCallingUid())
6659 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006660 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006661 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6662 .build());
6663 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6664 boolean hasFinePermission =
6665 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6666 boolean hasCoarsePermission =
6667 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669 final long identity = Binder.clearCallingIdentity();
6670 try {
6671 final Phone phone = getPhone(subId);
6672 if (phone == null) {
6673 return null;
6674 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006675
Hall Liuf19c44f2018-11-27 14:38:17 -08006676 ServiceState ss = phone.getServiceState();
6677
6678 // Scrub out the location info in ServiceState depending on what level of access
6679 // the caller has.
6680 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006681 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6682 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006683 } finally {
6684 Binder.restoreCallingIdentity(identity);
6685 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006686 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006687
6688 /**
6689 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6690 *
6691 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6692 * voicemail ringtone.
6693 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6694 * PhoneAccount.
6695 */
6696 @Override
6697 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006698 final long identity = Binder.clearCallingIdentity();
6699 try {
6700 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6701 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006702 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6706 } finally {
6707 Binder.restoreCallingIdentity(identity);
6708 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006709 }
6710
6711 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006712 * Sets the per-account voicemail ringtone.
6713 *
6714 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6715 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6716 *
6717 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6718 * voicemail ringtone.
6719 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6720 * PhoneAccount.
6721 */
6722 @Override
6723 public void setVoicemailRingtoneUri(String callingPackage,
6724 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006725 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006726 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006727 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6728 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6730 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6731 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006732 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733
6734 final long identity = Binder.clearCallingIdentity();
6735 try {
6736 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6737 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006738 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006739 }
6740 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6741 } finally {
6742 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006743 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006744 }
6745
6746 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006747 * Returns whether vibration is set for voicemail notification in Phone settings.
6748 *
6749 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6750 * voicemail vibration setting.
6751 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6752 */
6753 @Override
6754 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006755 final long identity = Binder.clearCallingIdentity();
6756 try {
6757 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6758 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006759 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6763 } finally {
6764 Binder.restoreCallingIdentity(identity);
6765 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006766 }
6767
Youhan Wange64578a2016-05-02 15:32:42 -07006768 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006769 * Sets the per-account voicemail vibration.
6770 *
6771 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6772 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6773 *
6774 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6775 * voicemail vibration setting.
6776 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6777 * specific PhoneAccount.
6778 */
6779 @Override
6780 public void setVoicemailVibrationEnabled(String callingPackage,
6781 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006782 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006783 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006784 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6785 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6787 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6788 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006789 }
6790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006791 final long identity = Binder.clearCallingIdentity();
6792 try {
6793 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6794 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006795 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796 }
6797 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6798 } finally {
6799 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006800 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006801 }
6802
6803 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006804 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6805 *
6806 * @throws SecurityException if the caller does not have the required permission
6807 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006808 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006809 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006810 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006811 }
6812
6813 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006814 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6815 * permission.
6816 *
6817 * @throws SecurityException if the caller does not have the required permission
6818 */
6819 private void enforceSendSmsPermission() {
6820 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6821 }
6822
6823 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006824 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006825 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006826 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006827 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006828 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829 final long identity = Binder.clearCallingIdentity();
6830 try {
6831 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006832 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006833 if (componentName == null) {
6834 throw new SecurityException(
6835 "Caller not current active visual voicemail package[null]");
6836 }
6837 String vvmPackage = componentName.getPackageName();
6838 if (!callingPackage.equals(vvmPackage)) {
6839 throw new SecurityException("Caller not current active visual voicemail package["
6840 + vvmPackage + "]");
6841 }
6842 } finally {
6843 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006844 }
6845 }
6846
6847 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006848 * Return the application ID for the app type.
6849 *
6850 * @param subId the subscription ID that this request applies to.
6851 * @param appType the uicc app type.
6852 * @return Application ID for specificied app type, or null if no uicc.
6853 */
6854 @Override
6855 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006856 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006857 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006858
6859 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006860 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861 if (phone == null) {
6862 return null;
6863 }
6864 String aid = null;
6865 try {
6866 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6867 .getApplicationByType(appType).getAid();
6868 } catch (Exception e) {
6869 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6870 }
6871 return aid;
6872 } finally {
6873 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006874 }
Youhan Wange64578a2016-05-02 15:32:42 -07006875 }
6876
Youhan Wang4001d252016-05-11 10:29:41 -07006877 /**
6878 * Return the Electronic Serial Number.
6879 *
6880 * @param subId the subscription ID that this request applies to.
6881 * @return ESN or null if error.
6882 */
6883 @Override
6884 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006885 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006886 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006887
6888 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006889 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006890 if (phone == null) {
6891 return null;
6892 }
6893 String esn = null;
6894 try {
6895 esn = phone.getEsn();
6896 } catch (Exception e) {
6897 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6898 }
6899 return esn;
6900 } finally {
6901 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006902 }
Youhan Wang4001d252016-05-11 10:29:41 -07006903 }
6904
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006905 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006906 * Return the Preferred Roaming List Version.
6907 *
6908 * @param subId the subscription ID that this request applies to.
6909 * @return PRLVersion or null if error.
6910 */
6911 @Override
6912 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006913 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006914 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006915
6916 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006917 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006918 if (phone == null) {
6919 return null;
6920 }
6921 String cdmaPrlVersion = null;
6922 try {
6923 cdmaPrlVersion = phone.getCdmaPrlVersion();
6924 } catch (Exception e) {
6925 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6926 }
6927 return cdmaPrlVersion;
6928 } finally {
6929 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006930 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006931 }
6932
6933 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006934 * Get snapshot of Telephony histograms
6935 * @return List of Telephony histograms
6936 * @hide
6937 */
6938 @Override
6939 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6941 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006942
6943 final long identity = Binder.clearCallingIdentity();
6944 try {
6945 return RIL.getTelephonyRILTimingHistograms();
6946 } finally {
6947 Binder.restoreCallingIdentity(identity);
6948 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006949 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006950
6951 /**
6952 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006953 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6954 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006955 * Require system privileges. In the future we may add this to carrier APIs.
6956 *
Michele Berionne482f8202018-11-27 18:57:59 -08006957 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006958 */
6959 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006960 @TelephonyManager.SetCarrierRestrictionResult
6961 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006962 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006963 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006964
Michele Berionne482f8202018-11-27 18:57:59 -08006965 if (carrierRestrictionRules == null) {
6966 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006967 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006969 final long identity = Binder.clearCallingIdentity();
6970 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006971 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006972 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006973 } finally {
6974 Binder.restoreCallingIdentity(identity);
6975 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006976 }
6977
6978 /**
6979 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006980 * Get the allowed carrier list and the excluded carrier list, including the priority between
6981 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006982 * Require system privileges. In the future we may add this to carrier APIs.
6983 *
Michele Berionne482f8202018-11-27 18:57:59 -08006984 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006985 */
6986 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006987 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006988 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006989 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006990
6991 final long identity = Binder.clearCallingIdentity();
6992 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006993 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6994 if (response instanceof CarrierRestrictionRules) {
6995 return (CarrierRestrictionRules) response;
6996 }
6997 // Response is an Exception of some kind,
6998 // which is signalled to the user as a NULL retval
6999 return null;
7000 } catch (Exception e) {
7001 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7002 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 } finally {
7004 Binder.restoreCallingIdentity(identity);
7005 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007006 }
7007
fionaxu59545b42016-05-25 15:53:37 -07007008 /**
7009 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7010 * @param subId the subscription ID that this action applies to.
7011 * @param enabled control enable or disable metered apns.
7012 * {@hide}
7013 */
7014 @Override
7015 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7016 enforceModifyPermission();
7017 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018
7019 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007020 if (phone == null) {
7021 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7022 return;
7023 }
7024 try {
7025 phone.carrierActionSetMeteredApnsEnabled(enabled);
7026 } catch (Exception e) {
7027 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007028 } finally {
7029 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007030 }
7031 }
7032
7033 /**
7034 * Action set from carrier signalling broadcast receivers to enable/disable radio
7035 * @param subId the subscription ID that this action applies to.
7036 * @param enabled control enable or disable radio.
7037 * {@hide}
7038 */
7039 @Override
7040 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7041 enforceModifyPermission();
7042 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043
7044 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007045 if (phone == null) {
7046 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7047 return;
7048 }
7049 try {
7050 phone.carrierActionSetRadioEnabled(enabled);
7051 } catch (Exception e) {
7052 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053 } finally {
7054 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007055 }
7056 }
7057
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007058 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007059 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7060 * network status based on which carrier apps could apply actions accordingly,
7061 * enable/disable default url handler for example.
7062 *
7063 * @param subId the subscription ID that this action applies to.
7064 * @param report control start/stop reporting the default network status.
7065 * {@hide}
7066 */
7067 @Override
7068 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7069 enforceModifyPermission();
7070 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071
7072 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007073 if (phone == null) {
7074 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7075 return;
7076 }
7077 try {
7078 phone.carrierActionReportDefaultNetworkStatus(report);
7079 } catch (Exception e) {
7080 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 } finally {
7082 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007083 }
7084 }
7085
7086 /**
fionaxud9622282017-07-17 17:51:30 -07007087 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7088 * @param subId the subscription ID that this action applies to.
7089 * {@hide}
7090 */
7091 @Override
7092 public void carrierActionResetAll(int subId) {
7093 enforceModifyPermission();
7094 final Phone phone = getPhone(subId);
7095 if (phone == null) {
7096 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7097 return;
7098 }
7099 try {
7100 phone.carrierActionResetAll();
7101 } catch (Exception e) {
7102 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7103 }
7104 }
7105
7106 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007107 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7108 * bug report is being generated.
7109 */
7110 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007111 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007112 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7113 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007114 writer.println("Permission Denial: can't dump Phone from pid="
7115 + Binder.getCallingPid()
7116 + ", uid=" + Binder.getCallingUid()
7117 + "without permission "
7118 + android.Manifest.permission.DUMP);
7119 return;
7120 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007121 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007122 }
Jack Yueb89b242016-06-22 13:27:47 -07007123
Brad Ebingerdac2f002018-04-03 15:17:52 -07007124 @Override
7125 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7126 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7127 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007128 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7129 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007130 }
7131
Jack Yueb89b242016-06-22 13:27:47 -07007132 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007133 * Policy control of data connection. Usually used when data limit is passed.
7134 * @param enabled True if enabling the data, otherwise disabling.
7135 * @param subId Subscription index
7136 * {@hide}
7137 */
7138 @Override
7139 public void setPolicyDataEnabled(boolean enabled, int subId) {
7140 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141
7142 final long identity = Binder.clearCallingIdentity();
7143 try {
7144 Phone phone = getPhone(subId);
7145 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007146 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147 }
7148 } finally {
7149 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007150 }
7151 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007152
7153 /**
7154 * Get Client request stats
7155 * @return List of Client Request Stats
7156 * @hide
7157 */
7158 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007159 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7160 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007162 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007163 return null;
7164 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007165 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007166
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007167 final long identity = Binder.clearCallingIdentity();
7168 try {
7169 if (phone != null) {
7170 return phone.getClientRequestStats();
7171 }
7172
7173 return null;
7174 } finally {
7175 Binder.restoreCallingIdentity(identity);
7176 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007177 }
7178
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007179 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007180 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007181 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007182 }
Jack Yueb4124c2017-02-16 15:32:43 -08007183
7184 /**
Grace Chen70990072017-03-24 17:21:30 -07007185 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007186 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007187 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007188 * @param state State of SIM (power down, power up, pass through)
7189 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7190 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7191 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007192 *
7193 **/
7194 @Override
Grace Chen70990072017-03-24 17:21:30 -07007195 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007196 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007197 Phone phone = PhoneFactory.getPhone(slotIndex);
7198
vagdeviaf9a5b92018-08-15 16:01:53 -07007199 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201 final long identity = Binder.clearCallingIdentity();
7202 try {
7203 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007204 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007205 }
7206 } finally {
7207 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007208 }
7209 }
Shuo Qiandd210312017-04-12 22:11:33 +00007210
Tyler Gunn65d45c22017-06-05 11:22:26 -07007211 private boolean isUssdApiAllowed(int subId) {
7212 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007213 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007214 if (configManager == null) {
7215 return false;
7216 }
7217 PersistableBundle pb = configManager.getConfigForSubId(subId);
7218 if (pb == null) {
7219 return false;
7220 }
7221 return pb.getBoolean(
7222 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7223 }
7224
Shuo Qiandd210312017-04-12 22:11:33 +00007225 /**
7226 * Check if phone is in emergency callback mode
7227 * @return true if phone is in emergency callback mode
7228 * @param subId sub id
7229 */
goneil9c5f4872017-12-05 14:07:56 -08007230 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007231 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007232 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007233 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007234
7235 final long identity = Binder.clearCallingIdentity();
7236 try {
7237 if (phone != null) {
7238 return phone.isInEcm();
7239 } else {
7240 return false;
7241 }
7242 } finally {
7243 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007244 }
7245 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007246
7247 /**
7248 * Get the current signal strength information for the given subscription.
7249 * Because this information is not updated when the device is in a low power state
7250 * it should not be relied-upon to be current.
7251 * @param subId Subscription index
7252 * @return the most recent cached signal strength info from the modem
7253 */
7254 @Override
7255 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007256 final long identity = Binder.clearCallingIdentity();
7257 try {
7258 Phone p = getPhone(subId);
7259 if (p == null) {
7260 return null;
7261 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007263 return p.getSignalStrength();
7264 } finally {
7265 Binder.restoreCallingIdentity(identity);
7266 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007267 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007268
Pengquan Meng77b7f132018-08-22 14:49:57 -07007269 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007270 * Get the current modem radio state for the given slot.
7271 * @param slotIndex slot index.
7272 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007273 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007274 * @return the current radio power state from the modem
7275 */
7276 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007277 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007278 Phone phone = PhoneFactory.getPhone(slotIndex);
7279 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7281 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007282 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7283 }
7284
7285 final long identity = Binder.clearCallingIdentity();
7286 try {
7287 return phone.getRadioPowerState();
7288 } finally {
7289 Binder.restoreCallingIdentity(identity);
7290 }
7291 }
7292 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7293 }
7294
7295 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007296 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7297 *
7298 * <p>Requires one of the following permissions:
7299 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7300 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7301 * privileges.
7302 *
7303 * @param subId subscription id
7304 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7305 * {@code false}.
7306 */
7307 @Override
7308 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007309 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7310 null /* message */);
7311
Pengquan Menga1bb6272018-09-06 09:59:22 -07007312 boolean isEnabled = false;
7313 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007314 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007315 Phone phone = getPhone(subId);
7316 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007317 } catch (Exception e) {
7318 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7319 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007320 } finally {
7321 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007322 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007323 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007324 }
7325
7326
7327 /**
7328 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7329 *
7330 * <p> Requires permission:
7331 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7332 * privileges.
7333 *
7334 * @param subId subscription id
7335 * @param isEnabled {@code true} means enable, {@code false} means disable.
7336 */
7337 @Override
7338 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7340 mApp, subId, "setDataRoamingEnabled");
7341
Pengquan Menga1bb6272018-09-06 09:59:22 -07007342 final long identity = Binder.clearCallingIdentity();
7343 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007344 Phone phone = getPhone(subId);
7345 if (phone != null) {
7346 phone.setDataRoamingEnabled(isEnabled);
7347 }
7348 } finally {
7349 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007350 }
7351 }
7352
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007353 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007354 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007355 TelephonyPermissions
7356 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007357 mApp, subId, "isManualNetworkSelectionAllowed");
7358
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007359 boolean isAllowed = true;
7360 final long identity = Binder.clearCallingIdentity();
7361 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007362 Phone phone = getPhone(subId);
7363 if (phone != null) {
7364 isAllowed = phone.isCspPlmnEnabled();
7365 }
7366 } finally {
7367 Binder.restoreCallingIdentity(identity);
7368 }
7369 return isAllowed;
7370 }
7371
7372 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007373 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007374 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007375 try {
7376 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007377 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007378 } catch (SecurityException e) {
7379 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7380 // has carrier privileges on an active UICC
7381 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7382 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007383 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007384 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007385 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007386
7387 final long identity = Binder.clearCallingIdentity();
7388 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007389 UiccController uiccController = UiccController.getInstance();
7390 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007391 if (hasReadPermission) {
7392 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007393 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007394
7395 // Remove private info if the caller doesn't have access
7396 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7397 for (UiccCardInfo cardInfo : cardInfos) {
7398 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7399 // is available
7400 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7401 if (card == null || card.getUiccProfile() == null) {
7402 // assume no access if the card or profile is unavailable
7403 filteredInfos.add(cardInfo.getUnprivileged());
7404 continue;
7405 }
7406 UiccProfile profile = card.getUiccProfile();
7407 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7408 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7409 filteredInfos.add(cardInfo);
7410 } else {
7411 filteredInfos.add(cardInfo.getUnprivileged());
7412 }
7413 }
7414 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007415 } finally {
7416 Binder.restoreCallingIdentity(identity);
7417 }
7418 }
7419
7420 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007421 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007422 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 final long identity = Binder.clearCallingIdentity();
7425 try {
7426 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7427 if (slots == null) {
7428 Rlog.i(LOG_TAG, "slots is null.");
7429 return null;
7430 }
7431
7432 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7433 for (int i = 0; i < slots.length; i++) {
7434 UiccSlot slot = slots[i];
7435 if (slot == null) {
7436 continue;
7437 }
7438
Jordan Liu7be7e652019-05-06 18:55:02 +00007439 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440 UiccCard card = slot.getUiccCard();
7441 if (card != null) {
7442 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007443 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007444 cardId = slot.getEid();
7445 if (TextUtils.isEmpty(cardId)) {
7446 cardId = slot.getIccId();
7447 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007448 }
7449
Jordan Liu857451f2019-05-09 16:35:35 -07007450 if (cardId != null) {
7451 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7452 // if cardId is an EID, it's all digits so this is fine
7453 cardId = IccUtils.stripTrailingFs(cardId);
7454 }
7455
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 int cardState = 0;
7457 switch (slot.getCardState()) {
7458 case CARDSTATE_ABSENT:
7459 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7460 break;
7461 case CARDSTATE_PRESENT:
7462 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7463 break;
7464 case CARDSTATE_ERROR:
7465 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7466 break;
7467 case CARDSTATE_RESTRICTED:
7468 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7469 break;
7470 default:
7471 break;
7472
7473 }
7474
7475 infos[i] = new UiccSlotInfo(
7476 slot.isActive(),
7477 slot.isEuicc(),
7478 cardId,
7479 cardState,
7480 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007481 slot.isExtendedApduSupported(),
7482 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 }
7484 return infos;
7485 } finally {
7486 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007487 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007488 }
7489
7490 @Override
7491 public boolean switchSlots(int[] physicalSlots) {
7492 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493
7494 final long identity = Binder.clearCallingIdentity();
7495 try {
7496 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7497 } finally {
7498 Binder.restoreCallingIdentity(identity);
7499 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007500 }
Jack Yu4c988042018-02-27 15:30:01 -08007501
7502 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007503 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007504 final long identity = Binder.clearCallingIdentity();
7505 try {
7506 return UiccController.getInstance().getCardIdForDefaultEuicc();
7507 } finally {
7508 Binder.restoreCallingIdentity(identity);
7509 }
7510 }
7511
Pengquan Meng85728fb2018-03-12 16:31:21 -07007512 /**
goneil47ffb6e2018-04-06 15:40:58 -07007513 * A test API to reload the UICC profile.
7514 *
7515 * <p>Requires that the calling app has permission
7516 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7517 * @hide
7518 */
7519 @Override
7520 public void refreshUiccProfile(int subId) {
7521 enforceModifyPermission();
7522
7523 final long identity = Binder.clearCallingIdentity();
7524 try {
7525 Phone phone = getPhone(subId);
7526 if (phone == null) {
7527 return;
7528 }
7529 UiccCard uiccCard = phone.getUiccCard();
7530 if (uiccCard == null) {
7531 return;
7532 }
7533 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7534 if (uiccProfile == null) {
7535 return;
7536 }
7537 uiccProfile.refresh();
7538 } finally {
7539 Binder.restoreCallingIdentity(identity);
7540 }
7541 }
7542
7543 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007544 * Returns false if the mobile data is disabled by default, otherwise return true.
7545 */
7546 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007547 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007548 }
7549
7550 /**
7551 * Returns true if the data roaming is enabled by default, i.e the system property
7552 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7553 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7554 */
7555 private boolean getDefaultDataRoamingEnabled(int subId) {
7556 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007557 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007558 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007559 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7560 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7561 return isDataRoamingEnabled;
7562 }
7563
7564 /**
7565 * Returns the default network type for the given {@code subId}, if the default network type is
7566 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7567 */
7568 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007569 List<Integer> list = TelephonyProperties.default_network();
7570 int phoneId = mSubscriptionController.getPhoneId(subId);
7571 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7572 return list.get(phoneId);
7573 }
7574 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007575 }
fionaxua13278b2018-03-21 00:08:13 -07007576
7577 @Override
7578 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007579 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007580 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007581
7582 final long identity = Binder.clearCallingIdentity();
7583 try {
7584 final Phone phone = getPhone(subId);
7585 if (phone == null) {
7586 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7587 return;
7588 }
chen xueaba88a2019-03-15 13:15:10 -07007589 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7590 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591 } finally {
7592 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007593 }
fionaxua13278b2018-03-21 00:08:13 -07007594 }
7595
7596 @Override
7597 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007598 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007599
7600 final long identity = Binder.clearCallingIdentity();
7601 try {
7602 final Phone phone = getPhone(subId);
7603 if (phone == null) {
7604 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7605 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7606 }
7607 return phone.getCarrierIdListVersion();
7608 } finally {
7609 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007610 }
fionaxua13278b2018-03-21 00:08:13 -07007611 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007612
7613 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007614 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7615 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007617 mApp, subId, callingPackage, callingFeatureId,
7618 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007619 return -1;
7620 }
7621
7622 final long identity = Binder.clearCallingIdentity();
7623 try {
7624 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7625 } finally {
7626 Binder.restoreCallingIdentity(identity);
7627 }
7628 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007629
7630 @Override
7631 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007632 TelephonyPermissions
7633 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007634 mApp, subId, "getCdmaRoamingMode");
7635
7636 final long identity = Binder.clearCallingIdentity();
7637 try {
7638 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7639 } finally {
7640 Binder.restoreCallingIdentity(identity);
7641 }
7642 }
7643
7644 @Override
7645 public boolean setCdmaRoamingMode(int subId, int mode) {
7646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7647 mApp, subId, "setCdmaRoamingMode");
7648
7649 final long identity = Binder.clearCallingIdentity();
7650 try {
7651 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7652 } finally {
7653 Binder.restoreCallingIdentity(identity);
7654 }
7655 }
7656
7657 @Override
7658 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7660 mApp, subId, "setCdmaSubscriptionMode");
7661
7662 final long identity = Binder.clearCallingIdentity();
7663 try {
7664 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7665 } finally {
7666 Binder.restoreCallingIdentity(identity);
7667 }
7668 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007669
sqianc5eccab2018-10-19 18:46:41 -07007670 @Override
sqian8c685422019-02-22 15:55:18 -08007671 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007672 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007673 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007674 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7675 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007676 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7677 }
7678 final long identity = Binder.clearCallingIdentity();
7679 try {
sqian854d44b2018-12-12 16:48:18 -08007680 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7681 for (Phone phone: PhoneFactory.getPhones()) {
7682 if (phone.getEmergencyNumberTracker() != null
7683 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7684 emergencyNumberListInternal.put(
7685 phone.getSubId(),
7686 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7687 }
sqian11b7a0e2018-12-05 18:48:28 -08007688 }
sqian854d44b2018-12-12 16:48:18 -08007689 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007690 } finally {
7691 Binder.restoreCallingIdentity(identity);
7692 }
sqianc5eccab2018-10-19 18:46:41 -07007693 }
7694
7695 @Override
sqian8c685422019-02-22 15:55:18 -08007696 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007697 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007698 if (!exactMatch) {
7699 TelephonyPermissions
7700 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007701 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007702 }
7703 final long identity = Binder.clearCallingIdentity();
7704 try {
sqian854d44b2018-12-12 16:48:18 -08007705 for (Phone phone: PhoneFactory.getPhones()) {
7706 if (phone.getEmergencyNumberTracker() != null
7707 && phone.getEmergencyNumberTracker() != null) {
7708 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7709 number, exactMatch)) {
7710 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007711 }
7712 }
sqian11b7a0e2018-12-05 18:48:28 -08007713 }
7714 return false;
7715 } finally {
7716 Binder.restoreCallingIdentity(identity);
7717 }
7718 }
7719
sqianf4ca7ed2019-01-15 18:32:07 -08007720 /**
7721 * Update emergency number list for test mode.
7722 */
7723 @Override
7724 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7725 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7726 "updateEmergencyNumberListTestMode");
7727
7728 final long identity = Binder.clearCallingIdentity();
7729 try {
7730 for (Phone phone: PhoneFactory.getPhones()) {
7731 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7732 if (tracker != null) {
7733 tracker.executeEmergencyNumberTestModeCommand(action, num);
7734 }
7735 }
7736 } finally {
7737 Binder.restoreCallingIdentity(identity);
7738 }
7739 }
7740
7741 /**
7742 * Get the full emergency number list for test mode.
7743 */
7744 @Override
7745 public List<String> getEmergencyNumberListTestMode() {
7746 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7747 "getEmergencyNumberListTestMode");
7748
7749 final long identity = Binder.clearCallingIdentity();
7750 try {
7751 Set<String> emergencyNumbers = new HashSet<>();
7752 for (Phone phone: PhoneFactory.getPhones()) {
7753 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7754 if (tracker != null) {
7755 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7756 emergencyNumbers.add(num.getNumber());
7757 }
7758 }
7759 }
7760 return new ArrayList<>(emergencyNumbers);
7761 } finally {
7762 Binder.restoreCallingIdentity(identity);
7763 }
7764 }
7765
chen xud6b45bd2018-10-30 22:27:10 -07007766 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007767 public int getEmergencyNumberDbVersion(int subId) {
7768 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7769
7770 final long identity = Binder.clearCallingIdentity();
7771 try {
7772 final Phone phone = getPhone(subId);
7773 if (phone == null) {
7774 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7775 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7776 }
7777 return phone.getEmergencyNumberDbVersion();
7778 } finally {
7779 Binder.restoreCallingIdentity(identity);
7780 }
7781 }
7782
7783 @Override
7784 public void notifyOtaEmergencyNumberDbInstalled() {
7785 enforceModifyPermission();
7786
7787 final long identity = Binder.clearCallingIdentity();
7788 try {
7789 for (Phone phone: PhoneFactory.getPhones()) {
7790 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7791 if (tracker != null) {
7792 tracker.updateOtaEmergencyNumberDatabase();
7793 }
7794 }
7795 } finally {
7796 Binder.restoreCallingIdentity(identity);
7797 }
7798 }
7799
7800 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08007801 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08007802 enforceActiveEmergencySessionPermission();
7803
7804 final long identity = Binder.clearCallingIdentity();
7805 try {
7806 for (Phone phone: PhoneFactory.getPhones()) {
7807 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7808 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08007809 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7810 }
7811 }
7812 } finally {
7813 Binder.restoreCallingIdentity(identity);
7814 }
7815 }
7816
7817 @Override
7818 public void resetOtaEmergencyNumberDbFilePath() {
7819 enforceActiveEmergencySessionPermission();
7820
7821 final long identity = Binder.clearCallingIdentity();
7822 try {
7823 for (Phone phone: PhoneFactory.getPhones()) {
7824 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7825 if (tracker != null) {
7826 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08007827 }
7828 }
7829 } finally {
7830 Binder.restoreCallingIdentity(identity);
7831 }
7832 }
7833
7834 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007835 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7836 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7837 Phone phone = getPhone(subId);
7838 if (phone == null) {
7839 return null;
7840 }
7841 final long identity = Binder.clearCallingIdentity();
7842 try {
7843 UiccProfile profile = UiccController.getInstance()
7844 .getUiccProfileForPhone(phone.getPhoneId());
7845 if (profile != null) {
7846 return profile.getCertsFromCarrierPrivilegeAccessRules();
7847 }
7848 } finally {
7849 Binder.restoreCallingIdentity(identity);
7850 }
7851 return null;
7852 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007853
7854 /**
7855 * Enable or disable a modem stack.
7856 */
7857 @Override
7858 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7859 enforceModifyPermission();
7860
7861 final long identity = Binder.clearCallingIdentity();
7862 try {
7863 Phone phone = PhoneFactory.getPhone(slotIndex);
7864 if (phone == null) {
7865 return false;
7866 } else {
7867 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7868 }
7869 } finally {
7870 Binder.restoreCallingIdentity(identity);
7871 }
7872 }
Michelecea4cf22018-12-21 15:00:11 -08007873
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007874 /**
7875 * Whether a modem stack is enabled or not.
7876 */
7877 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007878 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7879 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007880 Phone phone = PhoneFactory.getPhone(slotIndex);
7881 if (phone == null) return false;
7882
7883 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007884 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7885 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007886 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7887 }
7888
7889 final long identity = Binder.clearCallingIdentity();
7890 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007891 try {
7892 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7893 } catch (NoSuchElementException ex) {
7894 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7895 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007896 } finally {
7897 Binder.restoreCallingIdentity(identity);
7898 }
7899 }
7900
Michelecea4cf22018-12-21 15:00:11 -08007901 @Override
Michele0ea7d782019-03-19 14:58:42 -07007902 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007903 enforceModifyPermission();
7904
7905 final long identity = Binder.clearCallingIdentity();
7906 try {
7907 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007908 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007909 .commit();
7910 } finally {
7911 Binder.restoreCallingIdentity(identity);
7912 }
7913 }
7914
7915 @Override
Michele0ea7d782019-03-19 14:58:42 -07007916 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007917 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007919 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7920 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007921 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007922 }
Michelecea4cf22018-12-21 15:00:11 -08007923
7924 final long identity = Binder.clearCallingIdentity();
7925 try {
Michele0ea7d782019-03-19 14:58:42 -07007926 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007927 } finally {
7928 Binder.restoreCallingIdentity(identity);
7929 }
7930 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007931
Michele0ea7d782019-03-19 14:58:42 -07007932 @TelephonyManager.IsMultiSimSupportedResult
7933 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007934 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7935 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7936 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007937 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7938 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007939 }
7940 // Check if the hardware supports multisim functionality. If usage of multisim is not
7941 // supported by the modem, indicate that it is restricted.
7942 PhoneCapability staticCapability =
7943 mPhoneConfigurationManager.getStaticPhoneCapability();
7944 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007945 loge("isMultiSimSupportedInternal: no static configuration available");
7946 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007947 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00007948 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007949 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7950 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007951 }
7952 // Check if support of multiple SIMs is restricted by carrier
7953 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007954 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007955 }
7956
Michele0ea7d782019-03-19 14:58:42 -07007957 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007958 }
7959
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007960 /**
7961 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007962 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7963 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7964 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007965 * @param numOfSims number of active sims we want to switch to
7966 */
7967 @Override
7968 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007969 if (numOfSims == 1) {
7970 enforceModifyPermission();
7971 } else {
7972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7973 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7974 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007975 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007976
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007977 try {
Michele30b57b22019-03-01 12:01:14 -08007978 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007979 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007980 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7981 return;
7982 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007983 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7984 } finally {
7985 Binder.restoreCallingIdentity(identity);
7986 }
7987 }
7988
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007989 @Override
7990 public boolean isApplicationOnUicc(int subId, int appType) {
7991 enforceReadPrivilegedPermission("isApplicationOnUicc");
7992 Phone phone = getPhone(subId);
7993 if (phone == null) {
7994 return false;
7995 }
7996 final long identity = Binder.clearCallingIdentity();
7997 try {
7998 UiccCard uiccCard = phone.getUiccCard();
7999 if (uiccCard == null) {
8000 return false;
8001 }
8002 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8003 if (uiccProfile == null) {
8004 return false;
8005 }
8006 if (TelephonyManager.APPTYPE_SIM <= appType
8007 && appType <= TelephonyManager.APPTYPE_ISIM) {
8008 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8009 }
8010 return false;
8011 } finally {
8012 Binder.restoreCallingIdentity(identity);
8013 }
8014 }
8015
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008016 /**
chen xub4baa772019-04-03 10:23:41 -07008017 * Get whether making changes to modem configurations will trigger reboot.
8018 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008019 */
8020 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008021 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8022 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008023 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008024 mApp, subId, callingPackage, callingFeatureId,
8025 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008026 return false;
8027 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008028 final long identity = Binder.clearCallingIdentity();
8029 try {
8030 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8031 } finally {
8032 Binder.restoreCallingIdentity(identity);
8033 }
8034 }
8035
Nathan Harold29f5f052019-02-15 13:41:57 -08008036 private void updateModemStateMetrics() {
8037 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8038 // TODO: check the state for each modem if the api is ready.
8039 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8040 }
8041
Pengquan Meng3889a572019-01-23 11:16:29 -08008042 @Override
8043 public int[] getSlotsMapping() {
8044 enforceReadPrivilegedPermission("getSlotsMapping");
8045
8046 final long identity = Binder.clearCallingIdentity();
8047 try {
8048 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8049 // All logical slots should have a mapping to a physical slot.
8050 int[] logicalSlotsMapping = new int[phoneCount];
8051 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8052 for (int i = 0; i < slotInfos.length; i++) {
8053 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8054 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8055 }
8056 }
8057 return logicalSlotsMapping;
8058 } finally {
8059 Binder.restoreCallingIdentity(identity);
8060 }
8061 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008062
8063 /**
8064 * Get the IRadio HAL Version
8065 */
8066 @Override
8067 public int getRadioHalVersion() {
8068 Phone phone = getDefaultPhone();
8069 if (phone == null) return -1;
8070 HalVersion hv = phone.getHalVersion();
8071 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8072 return hv.major * 100 + hv.minor;
8073 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008074
8075 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008076 * Get the current calling package name.
8077 * @return the current calling package name
8078 */
8079 @Override
8080 public String getCurrentPackageName() {
8081 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8082 }
8083
8084 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008085 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8086 * corresponding network requests on a subId.
8087 *
8088 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008089 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008090 * 2) APN is un-metered for this subscription, or
8091 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008092 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008093 *
8094 * @return whether data is allowed for a apn type.
8095 *
8096 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008097 */
8098 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008099 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008100 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8101 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008102
8103 // Now that all security checks passes, perform the operation as ourselves.
8104 final long identity = Binder.clearCallingIdentity();
8105 try {
8106 Phone phone = getPhone(subId);
8107 if (phone == null) return false;
8108
Jack Yu41407ee2019-05-13 16:54:09 -07008109 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008110 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8111 } finally {
8112 Binder.restoreCallingIdentity(identity);
8113 }
8114 }
8115
8116 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008117 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008118 enforceReadPrivilegedPermission("isApnMetered");
8119
8120 // Now that all security checks passes, perform the operation as ourselves.
8121 final long identity = Binder.clearCallingIdentity();
8122 try {
8123 Phone phone = getPhone(subId);
8124 if (phone == null) return true; // By default return true.
8125
Jack Yu41407ee2019-05-13 16:54:09 -07008126 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008127 } finally {
8128 Binder.restoreCallingIdentity(identity);
8129 }
8130 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008131
8132 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008133 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8134 int subscriptionId, IBooleanConsumer resultCallback) {
8135 enforceModifyPermission();
8136 long token = Binder.clearCallingIdentity();
8137 try {
8138 Phone phone = getPhone(subscriptionId);
8139 if (phone == null) {
8140 try {
8141 if (resultCallback != null) {
8142 resultCallback.accept(false);
8143 }
8144 } catch (RemoteException e) {
8145 // ignore
8146 }
8147 return;
8148 }
8149 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8150 Pair.create(specifiers, (x) -> {
8151 try {
8152 if (resultCallback != null) {
8153 resultCallback.accept(x);
8154 }
8155 } catch (RemoteException e) {
8156 // ignore
8157 }
8158 });
8159 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8160 } finally {
8161 Binder.restoreCallingIdentity(token);
8162 }
8163 }
8164
8165 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008166 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8167 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8168 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8169 if (iccRecords == null) {
8170 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8171 return false;
8172 }
8173 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8174 }
8175
8176 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008177 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8178 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008179 if (callingPackage == null) {
8180 callingPackage = getCurrentPackageName();
8181 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008182 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8183 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008184 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8185 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008186 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8187 }
8188 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8189 Intent intent = new Intent();
8190 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8191 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8192 // Bring up choose default SMS subscription dialog right now
8193 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8194 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8195 mApp.startActivity(intent);
8196 }
chen xud5ca2d52019-05-28 15:20:57 -07008197
8198 @Override
8199 public String getMmsUAProfUrl(int subId) {
8200 //TODO investigate if this API should require proper permission check in R b/133791609
8201 final long identity = Binder.clearCallingIdentity();
8202 try {
8203 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8204 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8205 } finally {
8206 Binder.restoreCallingIdentity(identity);
8207 }
8208 }
8209
8210 @Override
8211 public String getMmsUserAgent(int subId) {
8212 //TODO investigate if this API should require proper permission check in R b/133791609
8213 final long identity = Binder.clearCallingIdentity();
8214 try {
8215 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8216 .getString(com.android.internal.R.string.config_mms_user_agent);
8217 } finally {
8218 Binder.restoreCallingIdentity(identity);
8219 }
8220 }
Jack Yub07d4972019-05-28 16:12:25 -07008221
8222 @Override
8223 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8224 enforceModifyPermission();
8225
8226 // Now that all security checks passes, perform the operation as ourselves.
8227 final long identity = Binder.clearCallingIdentity();
8228 try {
8229 Phone phone = getPhone(subId);
8230 if (phone == null) return false;
8231
8232 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8233 } finally {
8234 Binder.restoreCallingIdentity(identity);
8235 }
8236 }
8237
8238 @Override
8239 public boolean isDataAllowedInVoiceCall(int subId) {
8240 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8241
8242 // Now that all security checks passes, perform the operation as ourselves.
8243 final long identity = Binder.clearCallingIdentity();
8244 try {
8245 Phone phone = getPhone(subId);
8246 if (phone == null) return false;
8247
8248 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8249 } finally {
8250 Binder.restoreCallingIdentity(identity);
8251 }
8252 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008253
changbetty97defcf2019-12-24 15:40:37 +08008254 @Override
8255 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8256 enforceModifyPermission();
8257
8258 // Now that all security checks passes, perform the operation as ourselves.
8259 final long identity = Binder.clearCallingIdentity();
8260 try {
8261 Phone phone = getPhone(subId);
8262 if (phone == null) return false;
8263
8264 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8265 } finally {
8266 Binder.restoreCallingIdentity(identity);
8267 }
8268 }
8269
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008270 /**
8271 * Updates whether conference event pacakge handling is enabled.
8272 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8273 * otherwise.
8274 */
8275 @Override
8276 public void setCepEnabled(boolean isCepEnabled) {
8277 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8278
8279 final long identity = Binder.clearCallingIdentity();
8280 try {
8281 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8282 for (Phone phone : PhoneFactory.getPhones()) {
8283 Phone defaultPhone = phone.getImsPhone();
8284 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8285 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8286 ImsPhoneCallTracker imsPhoneCallTracker =
8287 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8288 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8289 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8290 + imsPhone.getMsisdn());
8291 }
8292 }
8293 } finally {
8294 Binder.restoreCallingIdentity(identity);
8295 }
8296 }
allenwtsu46dcc572020-01-08 18:24:03 +08008297
8298 /**
8299 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8300 *
8301 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8302 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8303 * before being read.
8304 */
8305 @Override
8306 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8307 isCompressed) {
8308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8309 mApp, subId, "notifyRcsAutoConfigurationReceived");
8310 try {
8311 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8312 if (configBinder == null) {
8313 Rlog.e(LOG_TAG, "null result for getImsConfig");
8314 } else {
8315 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8316 }
8317 } catch (RemoteException e) {
8318 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8319 }
8320 }
zoey chenf95ca592019-12-30 16:11:23 +08008321
8322 @Override
8323 public boolean isIccLockEnabled(int subId) {
8324 enforceReadPrivilegedPermission("isIccLockEnabled");
8325
8326 // Now that all security checks passes, perform the operation as ourselves.
8327 final long identity = Binder.clearCallingIdentity();
8328 try {
8329 Phone phone = getPhone(subId);
8330 if (phone != null && phone.getIccCard() != null) {
8331 return phone.getIccCard().getIccLockEnabled();
8332 } else {
8333 return false;
8334 }
8335 } finally {
8336 Binder.restoreCallingIdentity(identity);
8337 }
8338 }
8339
8340 /**
8341 * Set the ICC pin lock enabled or disabled..
8342 *
8343 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8344 * 0 or a positive integer as the attempts remaining value.
8345 *
8346 */
8347 @Override
8348 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8349 enforceModifyPermission();
8350
8351 Phone phone = getPhone(subId);
8352 if (phone == null) {
8353 return 0;
8354 }
8355 // Now that all security checks passes, perform the operation as ourselves.
8356 final long identity = Binder.clearCallingIdentity();
8357 try {
8358 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8359 new Pair<Boolean, String>(enabled, password), phone, null);
8360 return attemptsRemaining;
8361
8362 } catch (Exception e) {
8363 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8364 } finally {
8365 Binder.restoreCallingIdentity(identity);
8366 }
8367 return 0;
8368 }
8369
8370 /**
8371 * Change the ICC password used in ICC pin lock.
8372 *
8373 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8374 * 0 or a positive integer as the attempts remaining value.
8375 *
8376 */
8377 @Override
8378 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8379 enforceModifyPermission();
8380
8381 Phone phone = getPhone(subId);
8382 if (phone == null) {
8383 return 0;
8384 }
8385 // Now that all security checks passes, perform the operation as ourselves.
8386 final long identity = Binder.clearCallingIdentity();
8387 try {
8388 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8389 new Pair<String, String>(oldPassword, newPassword), phone, null);
8390 return attemptsRemaining;
8391
8392 } catch (Exception e) {
8393 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8394 } finally {
8395 Binder.restoreCallingIdentity(identity);
8396 }
8397 return 0;
8398 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008399
8400 @Override
8401 public boolean canConnectTo5GInDsdsMode() {
8402 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008404}