blob: 59a05c7e990000a174d2a208a3318c861674324f [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;
1866 } else {
1867 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1868 }
1869 } else {
1870 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 mDone = true;
1873 UnlockSim.this.notifyAll();
1874 }
1875 break;
1876 }
1877 }
1878 };
1879 UnlockSim.this.notifyAll();
1880 }
1881 Looper.loop();
1882 }
1883
1884 /*
1885 * Use PIN or PUK to unlock SIM card
1886 *
1887 * If PUK is null, unlock SIM card with PIN
1888 *
1889 * If PUK is not null, unlock SIM card with PUK and set PIN code
1890 */
Wink Saville9de0f752013-10-22 19:04:03 -07001891 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892
1893 while (mHandler == null) {
1894 try {
1895 wait();
1896 } catch (InterruptedException e) {
1897 Thread.currentThread().interrupt();
1898 }
1899 }
1900 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1901
1902 if (puk == null) {
1903 mSimCard.supplyPin(pin, callback);
1904 } else {
1905 mSimCard.supplyPuk(puk, pin, callback);
1906 }
1907
1908 while (!mDone) {
1909 try {
1910 Log.d(LOG_TAG, "wait for done");
1911 wait();
1912 } catch (InterruptedException e) {
1913 // Restore the interrupted status
1914 Thread.currentThread().interrupt();
1915 }
1916 }
1917 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001918 int[] resultArray = new int[2];
1919 resultArray[0] = mResult;
1920 resultArray[1] = mRetryCount;
1921 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 }
1923 }
1924
1925 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001926 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001927
1928 }
1929
Wink Savilleb564aae2014-10-23 10:18:09 -07001930 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 // No permission check needed here: this call is harmless, and it's
1932 // needed for the ServiceState.requestStateUpdate() call (which is
1933 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001934 final long identity = Binder.clearCallingIdentity();
1935 try {
1936 final Phone phone = getPhone(subId);
1937 if (phone != null) {
1938 phone.updateServiceLocation();
1939 }
1940 } finally {
1941 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001945 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001946 @Override
1947 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001948 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001949 }
1950
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001951 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001952 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1953 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1954 callingFeatureId);
1955 }
1956
1957 @Deprecated
1958 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001959 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001960 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1961 }
1962
1963 @Override
1964 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1965 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001966 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001967 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001968 return false;
1969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001970
1971 final long identity = Binder.clearCallingIdentity();
1972 try {
1973 return isRadioOnForSubscriber(subId);
1974 } finally {
1975 Binder.restoreCallingIdentity(identity);
1976 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001977 }
1978
1979 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001980 final long identity = Binder.clearCallingIdentity();
1981 try {
1982 final Phone phone = getPhone(subId);
1983 if (phone != null) {
1984 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1985 } else {
1986 return false;
1987 }
1988 } finally {
1989 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 }
1992
1993 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001994 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 }
Wink Saville36469e72014-06-11 15:17:00 -07001996
Wink Savilleb564aae2014-10-23 10:18:09 -07001997 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001999
2000 final long identity = Binder.clearCallingIdentity();
2001 try {
2002 final Phone phone = getPhone(subId);
2003 if (phone != null) {
2004 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2005 }
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 }
Wink Saville36469e72014-06-11 15:17:00 -07002009 }
2010
2011 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002012 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002013 }
2014
Wink Savilleb564aae2014-10-23 10:18:09 -07002015 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002016 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002017
2018 final long identity = Binder.clearCallingIdentity();
2019 try {
2020 final Phone phone = getPhone(subId);
2021 if (phone == null) {
2022 return false;
2023 }
2024 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2025 toggleRadioOnOffForSubscriber(subId);
2026 }
2027 return true;
2028 } finally {
2029 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 }
Wink Saville36469e72014-06-11 15:17:00 -07002032
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002033 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002034 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002035 /*
2036 * If any of the Radios are available, it will need to be
2037 * shutdown. So return true if any Radio is available.
2038 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002039 final long identity = Binder.clearCallingIdentity();
2040 try {
2041 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2042 Phone phone = PhoneFactory.getPhone(i);
2043 if (phone != null && phone.isRadioAvailable()) return true;
2044 }
2045 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2046 return false;
2047 } finally {
2048 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002049 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002050 }
2051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002052 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002053 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054 enforceModifyPermission();
2055
2056 final long identity = Binder.clearCallingIdentity();
2057 try {
2058 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2059 logv("Shutting down Phone " + i);
2060 shutdownRadioUsingPhoneId(i);
2061 }
2062 } finally {
2063 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002064 }
2065 }
2066
2067 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002068 Phone phone = PhoneFactory.getPhone(phoneId);
2069 if (phone != null && phone.isRadioAvailable()) {
2070 phone.shutdownRadio();
2071 }
2072 }
2073
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002074 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002075 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002076
2077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2080 if (defaultPhone != null) {
2081 defaultPhone.setRadioPower(turnOn);
2082 return true;
2083 } else {
2084 loge("There's no default phone.");
2085 return false;
2086 }
2087 } finally {
2088 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002089 }
Wink Saville36469e72014-06-11 15:17:00 -07002090 }
2091
Wink Savilleb564aae2014-10-23 10:18:09 -07002092 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002094
2095 final long identity = Binder.clearCallingIdentity();
2096 try {
2097 final Phone phone = getPhone(subId);
2098 if (phone != null) {
2099 phone.setRadioPower(turnOn);
2100 return true;
2101 } else {
2102 return false;
2103 }
2104 } finally {
2105 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 }
2108
Wink Saville36469e72014-06-11 15:17:00 -07002109 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002110 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 public boolean enableDataConnectivity() {
2112 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002113
2114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 int subId = mSubscriptionController.getDefaultDataSubId();
2117 final Phone phone = getPhone(subId);
2118 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002119 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002120 return true;
2121 } else {
2122 return false;
2123 }
2124 } finally {
2125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 }
2128
Wink Saville36469e72014-06-11 15:17:00 -07002129 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002130 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002131 public boolean disableDataConnectivity() {
2132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002133
2134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 int subId = mSubscriptionController.getDefaultDataSubId();
2137 final Phone phone = getPhone(subId);
2138 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002139 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002140 return true;
2141 } else {
2142 return false;
2143 }
2144 } finally {
2145 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002146 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 }
2148
Sanket Padawe356d7632015-06-22 14:03:32 -07002149 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002150 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002151 final long identity = Binder.clearCallingIdentity();
2152 try {
2153 final Phone phone = getPhone(subId);
2154 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002155 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002156 } else {
2157 return false;
2158 }
2159 } finally {
2160 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 }
2163
2164 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002165 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002166 }
2167
pkanwarae03a6b2016-11-06 20:37:09 -08002168 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002169 enforceCallPermission();
2170
2171 final long identity = Binder.clearCallingIdentity();
2172 try {
2173 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2174 return;
2175 }
2176 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2177 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2178 } finally {
2179 Binder.restoreCallingIdentity(identity);
2180 }
pkanwar32d516d2016-10-14 19:37:38 -07002181 };
2182
Wink Savilleb564aae2014-10-23 10:18:09 -07002183 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002185
2186 final long identity = Binder.clearCallingIdentity();
2187 try {
2188 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2189 return false;
2190 }
2191 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2192 } finally {
2193 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 }
2196
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002198 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002199 }
2200
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002201 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002202 final long identity = Binder.clearCallingIdentity();
2203 try {
2204 Phone phone = PhoneFactory.getPhone(slotIndex);
2205 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2206 PhoneConstantConversions.convertCallState(phone.getState());
2207 } finally {
2208 Binder.restoreCallingIdentity(identity);
2209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 }
2211
Sanket Padawe356d7632015-06-22 14:03:32 -07002212 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002213 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002214 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2215 }
2216
2217 @Override
2218 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002219 final long identity = Binder.clearCallingIdentity();
2220 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002221 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222 if (phone != null) {
2223 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2224 } else {
2225 return PhoneConstantConversions.convertDataState(
2226 PhoneConstants.DataState.DISCONNECTED);
2227 }
2228 } finally {
2229 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 }
2232
Sanket Padawe356d7632015-06-22 14:03:32 -07002233 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002234 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002235 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2236 }
2237
2238 @Override
2239 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002240 final long identity = Binder.clearCallingIdentity();
2241 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002242 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002243 if (phone != null) {
2244 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2245 } else {
2246 return TelephonyManager.DATA_ACTIVITY_NONE;
2247 }
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 }
2252
2253 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002254 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002255 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002256 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002257
2258 LocationAccessPolicy.LocationPermissionResult locationResult =
2259 LocationAccessPolicy.checkLocationPermission(mApp,
2260 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2261 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002262 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002263 .setCallingPid(Binder.getCallingPid())
2264 .setCallingUid(Binder.getCallingUid())
2265 .setMethod("getCellLocation")
2266 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2267 .build());
2268 switch (locationResult) {
2269 case DENIED_HARD:
2270 throw new SecurityException("Not allowed to access cell location");
2271 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002272 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2273 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 }
2275
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002276 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002277 final long identity = Binder.clearCallingIdentity();
2278 try {
2279 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002280 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002281 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002282 } finally {
2283 Binder.restoreCallingIdentity(identity);
2284 }
Svetoslav64fad262015-04-14 14:35:21 -07002285 }
2286
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 @Override
Jack Yu01425032020-02-22 19:38:58 -08002288 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002289 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2290 // registered cell info, so return a NULL country instead.
2291 final long identity = Binder.clearCallingIdentity();
2292 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002293 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2294 // Get default phone in this case.
2295 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2296 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002297 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002298 // Todo: fix this when we can get the actual cellular network info when the device
2299 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002300 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002301 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2302 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002303 return "";
2304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305 Phone phone = PhoneFactory.getPhone(phoneId);
2306 if (phone != null) {
2307 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002308 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002309 if (sst != null) {
2310 LocaleTracker lt = sst.getLocaleTracker();
2311 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002312 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2313 return lt.getCurrentCountry();
2314 } else if (emergencyNumberTracker != null) {
2315 return emergencyNumberTracker.getEmergencyCountryIso();
2316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002317 }
2318 }
2319 }
2320 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002321 } finally {
2322 Binder.restoreCallingIdentity(identity);
2323 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002324 }
2325
2326 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002328 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002329 }
2330
Sanket Padawe356d7632015-06-22 14:03:32 -07002331 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002332 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 mApp.enforceCallingOrSelfPermission(
2334 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002335
2336 final long identity = Binder.clearCallingIdentity();
2337 try {
2338 final Phone phone = getPhone(subId);
2339 if (phone != null) {
2340 phone.enableLocationUpdates();
2341 }
2342 } finally {
2343 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 }
2346
2347 @Override
2348 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002349 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002350 }
2351
Sanket Padawe356d7632015-06-22 14:03:32 -07002352 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002353 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 mApp.enforceCallingOrSelfPermission(
2355 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002356
2357 final long identity = Binder.clearCallingIdentity();
2358 try {
2359 final Phone phone = getPhone(subId);
2360 if (phone != null) {
2361 phone.disableLocationUpdates();
2362 }
2363 } finally {
2364 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 }
2367
Nathan Harold31d7ff32018-10-15 20:20:30 -07002368 /**
2369 * Returns the target SDK version number for a given package name.
2370 *
Nathan Haroldec184742019-07-10 17:04:16 -07002371 * This call MUST be invoked before clearing the calling UID.
2372 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002373 * @return target SDK if the package is found or INT_MAX.
2374 */
2375 private int getTargetSdk(String packageName) {
2376 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002377 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002378 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002379 if (ai != null) return ai.targetSdkVersion;
2380 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002381 loge("Failed to get package info for pkg="
2382 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002383 }
2384 return Integer.MAX_VALUE;
2385 }
2386
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 @Override
2388 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002389 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2390 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002391 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002392 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2393 throw new SecurityException(
2394 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2395 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002396
Jordan Liu1617b712019-07-10 15:06:26 -07002397 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002398 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2399 return null;
2400 }
Svetoslav64fad262015-04-14 14:35:21 -07002401
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002402 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002404 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002405 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406
Nathan Haroldf180aac2018-06-01 18:43:55 -07002407 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2408 for (CellInfo ci : info) {
2409 if (ci instanceof CellInfoGsm) {
2410 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2411 } else if (ci instanceof CellInfoWcdma) {
2412 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2413 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002415 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 }
2417
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002418 private List<CellInfo> getCachedCellInfo() {
2419 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2420 for (Phone phone : PhoneFactory.getPhones()) {
2421 List<CellInfo> info = phone.getAllCellInfo();
2422 if (info != null) cellInfos.addAll(info);
2423 }
2424 return cellInfos;
2425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426
2427 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002428 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002429 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002430 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002431
2432 LocationAccessPolicy.LocationPermissionResult locationResult =
2433 LocationAccessPolicy.checkLocationPermission(mApp,
2434 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2435 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002436 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002437 .setCallingPid(Binder.getCallingPid())
2438 .setCallingUid(Binder.getCallingUid())
2439 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002440 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002441 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2442 .build());
2443 switch (locationResult) {
2444 case DENIED_HARD:
2445 throw new SecurityException("Not allowed to access cell info");
2446 case DENIED_SOFT:
2447 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 }
2449
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002450 final int targetSdk = getTargetSdk(callingPackage);
2451 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2452 return getCachedCellInfo();
2453 }
2454
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002455 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002456 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457 final long identity = Binder.clearCallingIdentity();
2458 try {
2459 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2460 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002461 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002462 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002463 if (info != null) cellInfos.addAll(info);
2464 }
2465 return cellInfos;
2466 } finally {
2467 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 }
2469 }
2470
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002471 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002472 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2473 String callingFeatureId) {
2474 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2475 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002476 }
2477
2478 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002479 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2480 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002481 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002482 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002483 }
2484
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002485 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2486 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002487 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002488 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002489
2490 LocationAccessPolicy.LocationPermissionResult locationResult =
2491 LocationAccessPolicy.checkLocationPermission(mApp,
2492 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2493 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002494 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002495 .setCallingPid(Binder.getCallingPid())
2496 .setCallingUid(Binder.getCallingUid())
2497 .setMethod("requestCellInfoUpdate")
2498 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2499 .build());
2500 switch (locationResult) {
2501 case DENIED_HARD:
2502 throw new SecurityException("Not allowed to access cell info");
2503 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002504 try {
2505 cb.onCellInfo(new ArrayList<CellInfo>());
2506 } catch (RemoteException re) {
2507 // Drop without consequences
2508 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002509 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002510 }
2511
Nathan Harolda939a962019-05-09 10:13:47 -07002512
2513 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002514 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2515
2516 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2517 }
2518
2519 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002521 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002522 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523
2524 final long identity = Binder.clearCallingIdentity();
2525 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002526 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527 } finally {
2528 Binder.restoreCallingIdentity(identity);
2529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002530 }
2531
Shishir Agrawala9f32182016-04-12 12:00:16 -07002532 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002533 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002534 Phone phone = PhoneFactory.getPhone(slotIndex);
2535 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002536 return null;
2537 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002538 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002539 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002540 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002541 return null;
2542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543
2544 final long identity = Binder.clearCallingIdentity();
2545 try {
2546 return phone.getImei();
2547 } finally {
2548 Binder.restoreCallingIdentity(identity);
2549 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002550 }
2551
2552 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002553 public String getTypeAllocationCodeForSlot(int slotIndex) {
2554 Phone phone = PhoneFactory.getPhone(slotIndex);
2555 String tac = null;
2556 if (phone != null) {
2557 String imei = phone.getImei();
2558 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2559 }
2560 return tac;
2561 }
2562
2563 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002564 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002565 Phone phone = PhoneFactory.getPhone(slotIndex);
2566 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002567 return null;
2568 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002569
Jeff Davidson913390f2018-02-23 17:11:49 -08002570 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002571 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002572 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002573 return null;
2574 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002575
2576 final long identity = Binder.clearCallingIdentity();
2577 try {
2578 return phone.getMeid();
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
2581 }
Jack Yu2af8d712017-03-15 17:14:14 -07002582 }
2583
2584 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002585 public String getManufacturerCodeForSlot(int slotIndex) {
2586 Phone phone = PhoneFactory.getPhone(slotIndex);
2587 String manufacturerCode = null;
2588 if (phone != null) {
2589 String meid = phone.getMeid();
2590 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2591 }
2592 return manufacturerCode;
2593 }
2594
2595 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002596 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2597 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002598 Phone phone = PhoneFactory.getPhone(slotIndex);
2599 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002600 return null;
2601 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002602 int subId = phone.getSubId();
2603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002604 mApp, subId, callingPackage, callingFeatureId,
2605 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002606 return null;
2607 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002608
2609 final long identity = Binder.clearCallingIdentity();
2610 try {
2611 return phone.getDeviceSvn();
2612 } finally {
2613 Binder.restoreCallingIdentity(identity);
2614 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002615 }
2616
fionaxu43304da2017-11-27 22:51:16 -08002617 @Override
2618 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 final long identity = Binder.clearCallingIdentity();
2620 try {
2621 final Phone phone = getPhone(subId);
2622 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2623 } finally {
2624 Binder.restoreCallingIdentity(identity);
2625 }
fionaxu43304da2017-11-27 22:51:16 -08002626 }
2627
2628 @Override
2629 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630 final long identity = Binder.clearCallingIdentity();
2631 try {
2632 final Phone phone = getPhone(subId);
2633 return phone == null ? null : phone.getCarrierName();
2634 } finally {
2635 Binder.restoreCallingIdentity(identity);
2636 }
fionaxu43304da2017-11-27 22:51:16 -08002637 }
2638
calvinpanffe225e2018-11-01 19:43:06 +08002639 @Override
chen xu0026ca62019-03-06 15:28:50 -08002640 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 final Phone phone = getPhone(subId);
2644 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002645 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002646 } finally {
2647 Binder.restoreCallingIdentity(identity);
2648 }
2649 }
2650
2651 @Override
chen xu0026ca62019-03-06 15:28:50 -08002652 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002653 final long identity = Binder.clearCallingIdentity();
2654 try {
2655 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002656 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002657 } finally {
2658 Binder.restoreCallingIdentity(identity);
2659 }
2660 }
2661
chen xu651eec72018-11-11 19:03:44 -08002662 @Override
chen xu864e11c2018-12-06 22:10:03 -08002663 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2664 if (!isSubscriptionMccMnc) {
2665 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2666 }
chen xu651eec72018-11-11 19:03:44 -08002667 final Phone phone = PhoneFactory.getPhone(slotIndex);
2668 if (phone == null) {
2669 return TelephonyManager.UNKNOWN_CARRIER_ID;
2670 }
2671 final long identity = Binder.clearCallingIdentity();
2672 try {
2673 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
2676 }
2677 }
2678
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 //
2680 // Internal helper methods.
2681 //
2682
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002683 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2685 *
2686 * @throws SecurityException if the caller does not have the required permission
2687 */
2688 private void enforceModifyPermission() {
2689 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2690 }
2691
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002692 /**
2693 * Make sure the caller is system.
2694 *
2695 * @throws SecurityException if the caller is not system.
2696 */
2697 private void enforceSystemCaller() {
2698 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2699 throw new SecurityException("Caller must be system");
2700 }
2701 }
2702
Shuo Qianf2b2df42019-11-13 17:43:31 -08002703 private void enforceActiveEmergencySessionPermission() {
2704 mApp.enforceCallingOrSelfPermission(
2705 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2706 }
2707
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 /**
2709 * Make sure the caller has the CALL_PHONE permission.
2710 *
2711 * @throws SecurityException if the caller does not have the required permission
2712 */
2713 private void enforceCallPermission() {
2714 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2715 }
2716
paulhu423b5f22019-08-23 19:17:33 +08002717 private void enforceSettingsPermission() {
2718 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002719 }
2720
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 private String createTelUrl(String number) {
2722 if (TextUtils.isEmpty(number)) {
2723 return null;
2724 }
2725
Jake Hambye994d462014-02-03 13:10:13 -08002726 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 }
2728
Ihab Awadf9e92732013-12-05 18:02:52 -08002729 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2731 }
2732
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002733 private static void logv(String msg) {
2734 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2735 }
2736
Ihab Awadf9e92732013-12-05 18:02:52 -08002737 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2739 }
2740
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002741 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002743 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002744 }
2745
Sanket Padawe356d7632015-06-22 14:03:32 -07002746 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002747 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002748 final long identity = Binder.clearCallingIdentity();
2749 try {
2750 final Phone phone = PhoneFactory.getPhone(slotIndex);
2751 if (phone == null) {
2752 return PhoneConstants.PHONE_TYPE_NONE;
2753 } else {
2754 return phone.getPhoneType();
2755 }
2756 } finally {
2757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002758 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 }
2760
2761 /**
2762 * Returns the CDMA ERI icon index to display
2763 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002764 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002765 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2766 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2767 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002768 }
2769
Sanket Padawe356d7632015-06-22 14:03:32 -07002770 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002771 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2772 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002773 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002774 mApp, subId, callingPackage, callingFeatureId,
2775 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002776 return -1;
2777 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778
2779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 final Phone phone = getPhone(subId);
2782 if (phone != null) {
2783 return phone.getCdmaEriIconIndex();
2784 } else {
2785 return -1;
2786 }
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 }
2791
2792 /**
2793 * Returns the CDMA ERI icon mode,
2794 * 0 - ON
2795 * 1 - FLASHING
2796 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002797 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002798 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2799 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2800 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002801 }
2802
Sanket Padawe356d7632015-06-22 14:03:32 -07002803 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002804 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2805 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002806 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002807 mApp, subId, callingPackage, callingFeatureId,
2808 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002809 return -1;
2810 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811
2812 final long identity = Binder.clearCallingIdentity();
2813 try {
2814 final Phone phone = getPhone(subId);
2815 if (phone != null) {
2816 return phone.getCdmaEriIconMode();
2817 } else {
2818 return -1;
2819 }
2820 } finally {
2821 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002822 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002823 }
2824
2825 /**
2826 * Returns the CDMA ERI text,
2827 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002828 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002829 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2830 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2831 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002832 }
2833
Sanket Padawe356d7632015-06-22 14:03:32 -07002834 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002835 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2836 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002837 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002838 mApp, subId, callingPackage, callingFeatureId,
2839 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002840 return null;
2841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002842
2843 final long identity = Binder.clearCallingIdentity();
2844 try {
2845 final Phone phone = getPhone(subId);
2846 if (phone != null) {
2847 return phone.getCdmaEriText();
2848 } else {
2849 return null;
2850 }
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002853 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002854 }
2855
2856 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002857 * Returns the CDMA MDN.
2858 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002859 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002860 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2862 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863
2864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002867 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868 return phone.getLine1Number();
2869 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002870 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002871 return null;
2872 }
2873 } finally {
2874 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002875 }
2876 }
2877
2878 /**
2879 * Returns the CDMA MIN.
2880 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002881 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002882 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2884 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885
2886 final long identity = Binder.clearCallingIdentity();
2887 try {
2888 final Phone phone = getPhone(subId);
2889 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2890 return phone.getCdmaMin();
2891 } else {
2892 return null;
2893 }
2894 } finally {
2895 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002896 }
2897 }
2898
Hall Liud892bec2018-11-30 14:51:45 -08002899 @Override
2900 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2901 INumberVerificationCallback callback, String callingPackage) {
2902 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2903 != PERMISSION_GRANTED) {
2904 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2905 }
2906 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2907
2908 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2909 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2910 throw new SecurityException("Calling package must be configured in the device config");
2911 }
2912
2913 if (range == null) {
2914 throw new NullPointerException("Range must be non-null");
2915 }
2916
2917 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002918 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002919
2920 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2921 }
2922
Junda Liuca05d5d2014-08-14 22:36:34 -07002923 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002924 * Returns true if CDMA provisioning needs to run.
2925 */
2926 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927 final long identity = Binder.clearCallingIdentity();
2928 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002929 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930 } finally {
2931 Binder.restoreCallingIdentity(identity);
2932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 }
2934
2935 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002936 * Sets the voice mail number of a given subId.
2937 */
2938 @Override
2939 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002940 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2941 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942
2943 final long identity = Binder.clearCallingIdentity();
2944 try {
2945 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2946 new Pair<String, String>(alphaTag, number), new Integer(subId));
2947 return success;
2948 } finally {
2949 Binder.restoreCallingIdentity(identity);
2950 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002951 }
2952
Ta-wei Yen87c49842016-05-13 21:19:52 -07002953 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002954 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2955 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002956 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2957 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002958 if (!TextUtils.equals(callingPackage, systemDialer)) {
2959 throw new SecurityException("caller must be system dialer");
2960 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002961
2962 final long identity = Binder.clearCallingIdentity();
2963 try {
2964 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2965 if (phoneAccountHandle == null) {
2966 return null;
2967 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002968 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002969 } finally {
2970 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002971 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002972 }
2973
2974 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002975 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2976 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002977 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002979 mApp, subId, callingPackage, callingFeatureId,
2980 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002981 return null;
2982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002984 final long identity = Binder.clearCallingIdentity();
2985 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002986 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002987 } finally {
2988 Binder.restoreCallingIdentity(identity);
2989 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002990 }
2991
2992 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002993 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2994 VisualVoicemailSmsFilterSettings settings) {
2995 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996
2997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003000 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 } finally {
3002 Binder.restoreCallingIdentity(identity);
3003 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003004 }
3005
3006 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003007 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3008 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003009
3010 final long identity = Binder.clearCallingIdentity();
3011 try {
3012 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003013 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003014 } finally {
3015 Binder.restoreCallingIdentity(identity);
3016 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003017 }
3018
3019 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003020 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3021 String callingPackage, int subId) {
3022 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023
3024 final long identity = Binder.clearCallingIdentity();
3025 try {
3026 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003027 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003031 }
3032
3033 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003034 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003035 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003036
3037 final long identity = Binder.clearCallingIdentity();
3038 try {
3039 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003040 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003044 }
3045
3046 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003047 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3048 String callingAttributionTag, int subId, String number, int port, String text,
3049 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003050 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003051 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003052 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003053 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003054 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3055 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003056 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003057
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003058 /**
fionaxu0152e512016-11-14 13:36:14 -08003059 * Sets the voice activation state of a given subId.
3060 */
3061 @Override
3062 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3064 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065
3066 final long identity = Binder.clearCallingIdentity();
3067 try {
3068 final Phone phone = getPhone(subId);
3069 if (phone != null) {
3070 phone.setVoiceActivationState(activationState);
3071 } else {
3072 loge("setVoiceActivationState fails with invalid subId: " + subId);
3073 }
3074 } finally {
3075 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003076 }
3077 }
3078
3079 /**
3080 * Sets the data activation state of a given subId.
3081 */
3082 @Override
3083 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3085 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003086
3087 final long identity = Binder.clearCallingIdentity();
3088 try {
3089 final Phone phone = getPhone(subId);
3090 if (phone != null) {
3091 phone.setDataActivationState(activationState);
3092 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003093 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003094 }
3095 } finally {
3096 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003097 }
3098 }
3099
3100 /**
3101 * Returns the voice activation state of a given subId.
3102 */
3103 @Override
3104 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003105 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003106
fionaxu0152e512016-11-14 13:36:14 -08003107 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003108 final long identity = Binder.clearCallingIdentity();
3109 try {
3110 if (phone != null) {
3111 return phone.getVoiceActivationState();
3112 } else {
3113 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3114 }
3115 } finally {
3116 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003117 }
3118 }
3119
3120 /**
3121 * Returns the data activation state of a given subId.
3122 */
3123 @Override
3124 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003125 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003126
fionaxu0152e512016-11-14 13:36:14 -08003127 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 if (phone != null) {
3131 return phone.getDataActivationState();
3132 } else {
3133 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3134 }
3135 } finally {
3136 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003137 }
3138 }
3139
3140 /**
Wink Saville36469e72014-06-11 15:17:00 -07003141 * Returns the unread count of voicemails for a subId
3142 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003143 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003144 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3145 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003146 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003147 mApp, subId, callingPackage, callingFeatureId,
3148 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003149 return 0;
3150 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003151 final long identity = Binder.clearCallingIdentity();
3152 try {
3153 final Phone phone = getPhone(subId);
3154 if (phone != null) {
3155 return phone.getVoiceMessageCount();
3156 } else {
3157 return 0;
3158 }
3159 } finally {
3160 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003162 }
3163
3164 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003165 * returns true, if the device is in a state where both voice and data
3166 * are supported simultaneously. This can change based on location or network condition.
3167 */
3168 @Override
3169 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170 final long identity = Binder.clearCallingIdentity();
3171 try {
3172 final Phone phone = getPhone(subId);
3173 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3174 } finally {
3175 Binder.restoreCallingIdentity(identity);
3176 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003177 }
3178
3179 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003180 * Send the dialer code if called from the current default dialer or the caller has
3181 * carrier privilege.
3182 * @param inputCode The dialer code to send
3183 */
3184 @Override
3185 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003186 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003187 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003188 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3189 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003190 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003191 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003192 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003193 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194
3195 final long identity = Binder.clearCallingIdentity();
3196 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003197 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
fionaxu235cc5e2017-03-06 22:25:57 -08003201 }
3202
Pengquan Menga1bb6272018-09-06 09:59:22 -07003203 @Override
3204 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003205 TelephonyPermissions
3206 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3207 mApp, subId, "getNetworkSelectionMode");
3208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 if (!isActiveSubscription(subId)) {
3211 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3212 }
3213 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3214 } finally {
3215 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003216 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003217 }
3218
Brad Ebinger35c841c2018-10-01 10:40:55 -07003219 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003220 public boolean isInEmergencySmsMode() {
3221 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 for (Phone phone : PhoneFactory.getPhones()) {
3225 if (phone.isInEmergencySmsMode()) {
3226 return true;
3227 }
3228 }
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
3232 return false;
3233 }
3234
shilu366312e2019-12-17 09:28:10 -08003235 /**
3236 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3237 * @param subId The subscription to use to check the configuration.
3238 * @param c The callback that will be used to send the result.
3239 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003240 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003241 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3242 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003243 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3244 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003245
Brad Ebinger77b832e2019-10-17 17:03:22 -07003246 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3247 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3248 "IMS not available on device.");
3249 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003250 final long token = Binder.clearCallingIdentity();
3251 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003252 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003253 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003254 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003255 } catch (ImsException e) {
3256 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003257 } finally {
3258 Binder.restoreCallingIdentity(token);
3259 }
3260 }
3261
shilu366312e2019-12-17 09:28:10 -08003262 /**
3263 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3264 * @param subId The subscription to use to check the configuration.
3265 * @param c The callback that will be used to send the result.
3266 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003267 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003268 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003269 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3270 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003271 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3272 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3273 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003274 final long token = Binder.clearCallingIdentity();
3275 try {
3276 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3277 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3278 .removeRegistrationCallbackForSubscription(c, subId);
3279 } catch (ImsException e) {
3280 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3281 + "is inactive, ignoring unregister.");
3282 // If the subscription is no longer active, just return, since the callback
3283 // will already have been removed internally.
3284 } finally {
3285 Binder.restoreCallingIdentity(token);
3286 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003287 }
3288
Brad Ebinger774ba362019-10-22 17:36:18 -07003289 /**
3290 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3291 */
3292 @Override
3293 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3294 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3295 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3296 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3297 "IMS not available on device.");
3298 }
3299 final long token = Binder.clearCallingIdentity();
3300 try {
3301 Phone phone = getPhone(subId);
3302 if (phone == null) {
3303 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3304 + subId + "'");
3305 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3306 }
3307 phone.getImsRegistrationState(regState -> {
3308 try {
3309 consumer.accept((regState == null)
3310 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3311 } catch (RemoteException e) {
3312 // Ignore if the remote process is no longer available to call back.
3313 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3314 }
3315 });
3316 } finally {
3317 Binder.restoreCallingIdentity(token);
3318 }
3319 }
3320
3321 /**
3322 * Get the transport type for the IMS service registration state.
3323 */
3324 @Override
3325 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003326 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3327 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003328 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3329 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3330 "IMS not available on device.");
3331 }
3332 final long token = Binder.clearCallingIdentity();
3333 try {
3334 Phone phone = getPhone(subId);
3335 if (phone == null) {
3336 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3337 + subId + "'");
3338 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3339 }
3340 phone.getImsRegistrationTech(regTech -> {
3341 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3342 int regTechConverted = (regTech == null)
3343 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3344 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3345 regTechConverted);
3346 try {
3347 consumer.accept(regTechConverted);
3348 } catch (RemoteException e) {
3349 // Ignore if the remote process is no longer available to call back.
3350 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3351 }
3352 });
3353 } finally {
3354 Binder.restoreCallingIdentity(token);
3355 }
3356 }
3357
shilu366312e2019-12-17 09:28:10 -08003358 /**
3359 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3360 * @param subId The subscription to use to check the configuration.
3361 * @param c The callback that will be used to send the result.
3362 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003364 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3365 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003366 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3367 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003368 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3369 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3370 "IMS not available on device.");
3371 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003372 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3373 final long token = Binder.clearCallingIdentity();
3374 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003375 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003376 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003377 } catch (ImsException e) {
3378 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003379 } finally {
3380 Binder.restoreCallingIdentity(token);
3381 }
3382 }
3383
shilu366312e2019-12-17 09:28:10 -08003384 /**
3385 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3386 * @param subId The subscription to use to check the configuration.
3387 * @param c The callback that will be used to send the result.
3388 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003389 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003390 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003391 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3392 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003393 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3394 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3395 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003396
3397 final long token = Binder.clearCallingIdentity();
3398 try {
3399 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3400 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003401 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003402 } catch (ImsException e) {
3403 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3404 + "is inactive, ignoring unregister.");
3405 // If the subscription is no longer active, just return, since the callback
3406 // will already have been removed internally.
3407 } finally {
3408 Binder.restoreCallingIdentity(token);
3409 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003410 }
3411
3412 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003413 public boolean isCapable(int subId, int capability, int regTech) {
3414 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003415 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3416 final long token = Binder.clearCallingIdentity();
3417 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003418 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003419 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003420 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003421 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3422 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003423 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003424 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3425 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 } finally {
3427 Binder.restoreCallingIdentity(token);
3428 }
3429 }
3430
3431 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003432 public boolean isAvailable(int subId, int capability, int regTech) {
3433 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003434 final long token = Binder.clearCallingIdentity();
3435 try {
3436 Phone phone = getPhone(subId);
3437 if (phone == null) return false;
3438 return phone.isImsCapabilityAvailable(capability, regTech);
3439 } finally {
3440 Binder.restoreCallingIdentity(token);
3441 }
3442 }
3443
Brad Ebinger77b832e2019-10-17 17:03:22 -07003444 /**
3445 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3446 * subscription.
3447 * @param subId The subscription to use to check the configuration.
3448 * @param callback The callback that will be used to send the result.
3449 * @param capability The MmTelFeature capability that will be used to send the result.
3450 * @param transportType The transport type of the MmTelFeature capability.
3451 */
3452 @Override
3453 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3454 int transportType) {
3455 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3456 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3457 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3458 "IMS not available on device.");
3459 }
3460 final long token = Binder.clearCallingIdentity();
3461 try {
3462 int slotId = getSlotIndex(subId);
3463 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3464 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3465 + subId + "'");
3466 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3467 }
3468 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3469 transportType, aBoolean -> {
3470 try {
3471 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3472 } catch (RemoteException e) {
3473 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3474 + "running. Ignore");
3475 }
3476 });
3477 } finally {
3478 Binder.restoreCallingIdentity(token);
3479 }
3480 }
3481
shilu366312e2019-12-17 09:28:10 -08003482 /**
3483 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3484 * @param subId The subscription to use to check the configuration.
3485 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003486 @Override
3487 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003488 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3489 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003490
Brad Ebinger35c841c2018-10-01 10:40:55 -07003491 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3492 final long token = Binder.clearCallingIdentity();
3493 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003494 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003495 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003496 } catch (ImsException e) {
3497 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003498 } finally {
3499 Binder.restoreCallingIdentity(token);
3500 }
3501 }
3502
3503 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003504 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003506 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003510 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003511 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003512 } catch (ImsException e) {
3513 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003514 } finally {
3515 Binder.restoreCallingIdentity(identity);
3516 }
3517 }
3518
shilu366312e2019-12-17 09:28:10 -08003519 /**
3520 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3521 * @param subId The subscription to use to check the configuration.
3522 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003523 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003524 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003525 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3526 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003527 final long identity = Binder.clearCallingIdentity();
3528 try {
3529 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003530 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3531 } catch (ImsException e) {
3532 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003533 } finally {
3534 Binder.restoreCallingIdentity(identity);
3535 }
3536 }
3537
3538 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003539 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003541 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003542 final long identity = Binder.clearCallingIdentity();
3543 try {
3544 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003545 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003546 } catch (ImsException e) {
3547 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003548 } finally {
3549 Binder.restoreCallingIdentity(identity);
3550 }
3551 }
3552
shilu366312e2019-12-17 09:28:10 -08003553 /**
3554 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3555 * @param subId The subscription to use to check the configuration.
3556 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003557 @Override
3558 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003559 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3560 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003564 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003565 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003566 } catch (ImsException e) {
3567 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003568 } finally {
3569 Binder.restoreCallingIdentity(identity);
3570 }
3571 }
3572
3573 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003574 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003576 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003577 final long identity = Binder.clearCallingIdentity();
3578 try {
3579 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003580 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003581 } catch (ImsException e) {
3582 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003583 } finally {
3584 Binder.restoreCallingIdentity(identity);
3585 }
3586 }
3587
shilu366312e2019-12-17 09:28:10 -08003588 /**
3589 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3590 * @param subId The subscription to use to check the configuration.
3591 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 @Override
3593 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003594 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3595 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003599 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003600 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003601 } catch (ImsException e) {
3602 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003603 } finally {
3604 Binder.restoreCallingIdentity(identity);
3605 }
3606 }
3607
3608 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003609 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003611 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003612 final long identity = Binder.clearCallingIdentity();
3613 try {
3614 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003615 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003616 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003617 } catch (ImsException e) {
3618 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003619 } finally {
3620 Binder.restoreCallingIdentity(identity);
3621 }
3622 }
3623
3624 @Override
3625 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3627 "setVoWiFiNonPersistent");
3628 final long identity = Binder.clearCallingIdentity();
3629 try {
3630 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003631 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003632 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003633 } catch (ImsException e) {
3634 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003635 } finally {
3636 Binder.restoreCallingIdentity(identity);
3637 }
3638 }
3639
shilu366312e2019-12-17 09:28:10 -08003640 /**
3641 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3642 * @param subId The subscription to use to check the configuration.
3643 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003644 @Override
3645 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003646 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3647 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003651 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003652 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003653 } catch (ImsException e) {
3654 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003655 } finally {
3656 Binder.restoreCallingIdentity(identity);
3657 }
3658 }
3659
3660 @Override
3661 public void setVoWiFiModeSetting(int subId, int mode) {
3662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3663 "setVoWiFiModeSetting");
3664 final long identity = Binder.clearCallingIdentity();
3665 try {
3666 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003667 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003668 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003669 } catch (ImsException e) {
3670 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003671 } finally {
3672 Binder.restoreCallingIdentity(identity);
3673 }
3674 }
3675
3676 @Override
3677 public int getVoWiFiRoamingModeSetting(int subId) {
3678 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3679 final long identity = Binder.clearCallingIdentity();
3680 try {
3681 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003682 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003683 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003684 } catch (ImsException e) {
3685 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003686 } finally {
3687 Binder.restoreCallingIdentity(identity);
3688 }
3689 }
3690
3691 @Override
3692 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3694 "setVoWiFiRoamingModeSetting");
3695 final long identity = Binder.clearCallingIdentity();
3696 try {
3697 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003698 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003699 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003700 } catch (ImsException e) {
3701 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003702 } finally {
3703 Binder.restoreCallingIdentity(identity);
3704 }
3705 }
3706
3707 @Override
3708 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3710 "setRttCapabilityEnabled");
3711 final long identity = Binder.clearCallingIdentity();
3712 try {
3713 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003714 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3715 } catch (ImsException e) {
3716 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003717 } finally {
3718 Binder.restoreCallingIdentity(identity);
3719 }
3720 }
3721
shilu366312e2019-12-17 09:28:10 -08003722 /**
3723 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3724 * @param subId The subscription to use to check the configuration.
3725 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003726 @Override
3727 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003728 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3729 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003730 final long identity = Binder.clearCallingIdentity();
3731 try {
3732 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003733 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003734 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003735 } catch (ImsException e) {
3736 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
3740 }
3741
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003742 @Override
3743 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3744 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3745 final long identity = Binder.clearCallingIdentity();
3746 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003747 if (!isImsAvailableOnDevice()) {
3748 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3749 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003750 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003751 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003752 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003753 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003754 } catch (ImsException e) {
3755 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003756 } finally {
3757 Binder.restoreCallingIdentity(identity);
3758 }
3759 }
3760
3761 @Override
3762 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3763 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3764 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003765 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3766 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3767 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003768 try {
3769 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003770 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003771 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003772 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003773 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3774 + "is inactive, ignoring unregister.");
3775 // If the subscription is no longer active, just return, since the callback will already
3776 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003777 } finally {
3778 Binder.restoreCallingIdentity(identity);
3779 }
3780 }
3781
allenwtsu99c623b2020-01-03 18:24:23 +08003782
3783 private void checkModifyPhoneStatePermission(int subId, String message) {
3784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3785 message);
3786 }
3787
3788 private boolean isImsProvisioningRequired(int subId, int capability,
3789 boolean isMmtelCapability) {
3790 Phone phone = getPhone(subId);
3791 if (phone == null) {
3792 loge("phone instance null for subid " + subId);
3793 return false;
3794 }
3795 if (isMmtelCapability) {
3796 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3797 return false;
3798 }
3799 } else {
3800 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3801 return false;
3802 }
3803 }
3804 return true;
3805 }
3806
3807 @Override
3808 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3809 boolean isProvisioned) {
3810 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3811
3812 final long identity = Binder.clearCallingIdentity();
3813 try {
3814 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3815 if (!isImsProvisioningRequired(subId, capability, false)) {
3816 return;
3817 }
3818
3819 // this capability requires provisioning, route to the correct API.
3820 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3821 switch (capability) {
3822 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3823 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3824 ims.setEabProvisioned(isProvisioned);
3825 break;
3826 default: {
3827 throw new IllegalArgumentException("Tried to set provisioning for "
3828 + "rcs capability '" + capability + "', which does not require "
3829 + "provisioning.");
3830 }
3831 }
3832 } finally {
3833 Binder.restoreCallingIdentity(identity);
3834 }
3835
3836 }
3837
3838
3839 @Override
3840 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3841 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3842 final long identity = Binder.clearCallingIdentity();
3843 try {
3844 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3845 if (!isImsProvisioningRequired(subId, capability, false)) {
3846 return true;
3847 }
3848
3849 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3850 switch (capability) {
3851 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3852 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3853 return ims.isEabProvisionedOnDevice();
3854
3855 default: {
3856 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3857 + "capability '" + capability + "', which does not require "
3858 + "provisioning.");
3859 }
3860 }
3861
3862 } finally {
3863 Binder.restoreCallingIdentity(identity);
3864 }
3865 }
3866
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003867 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003868 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3869 boolean isProvisioned) {
3870 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3871 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3872 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3873 }
allenwtsu99c623b2020-01-03 18:24:23 +08003874 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003875 final long identity = Binder.clearCallingIdentity();
3876 try {
3877 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003878 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003879 return;
3880 }
3881
3882 // this capability requires provisioning, route to the correct API.
3883 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3884 switch (capability) {
3885 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3886 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3887 ims.setVolteProvisioned(isProvisioned);
3888 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3889 ims.setWfcProvisioned(isProvisioned);
3890 }
3891 break;
3892 }
3893 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3894 // There is currently no difference in VT provisioning type.
3895 ims.setVtProvisioned(isProvisioned);
3896 break;
3897 }
3898 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3899 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3900 // change the capability of the feature instead if needed.
3901 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3902 == isProvisioned) {
3903 // No change in provisioning.
3904 return;
3905 }
3906 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3907 try {
3908 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003909 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003910 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3911 + ", Exception" + e.getMessage());
3912 }
3913 break;
3914 }
3915 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003916 throw new IllegalArgumentException("Tried to set provisioning for "
3917 + "MmTel capability '" + capability + "', which does not require "
3918 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003919 }
3920 }
3921
3922 } finally {
3923 Binder.restoreCallingIdentity(identity);
3924 }
3925 }
3926
3927 @Override
3928 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3929 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3930 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3931 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3932 }
3933 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003937 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003938 return true;
3939 }
3940
3941 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3942 switch (capability) {
3943 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3944 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3945 return ims.isVolteProvisionedOnDevice();
3946 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3947 return ims.isWfcProvisionedOnDevice();
3948 }
3949 // This should never happen, since we are checking tech above to make sure it
3950 // is either LTE or IWLAN.
3951 throw new IllegalArgumentException("Invalid radio technology for voice "
3952 + "capability.");
3953 }
3954 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3955 // There is currently no difference in VT provisioning type.
3956 return ims.isVtProvisionedOnDevice();
3957 }
3958 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3959 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3960 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3961 }
3962 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003963 throw new IllegalArgumentException(
3964 "Tried to get provisioning for MmTel capability '" + capability
3965 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003966 }
3967 }
3968
3969 } finally {
3970 Binder.restoreCallingIdentity(identity);
3971 }
3972 }
3973
3974 @Override
3975 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3976 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3977 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3978 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3979 }
3980 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3981 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3982 return (provisionedBits & capability) > 0;
3983 }
3984
3985 @Override
3986 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3987 boolean isProvisioned) {
3988 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3989 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3990 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3991 }
3992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3993 "setProvisioningStatusForCapability");
3994 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3995 // If the current provisioning status for capability already matches isProvisioned,
3996 // do nothing.
3997 if (((provisionedBits & capability) > 0) == isProvisioned) {
3998 return;
3999 }
4000 if (isProvisioned) {
4001 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4002 } else {
4003 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4004 }
4005 }
4006
4007 /**
4008 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4009 * technology. The bitfield should mirror the bitfield defined by
4010 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4011 */
4012 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4013 String key = getMmTelProvisioningKey(subId, tech);
4014 // Default is no capabilities are provisioned.
4015 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4016 }
4017
4018 /**
4019 * Sets the MmTel capability provisioning bitfield (defined by
4020 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4021 * technology specified.
4022 *
4023 * Note: This is a synchronous command and should not be called on UI thread.
4024 */
4025 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4026 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4027 String key = getMmTelProvisioningKey(subId, tech);
4028 editor.putInt(key, newField);
4029 editor.commit();
4030 }
4031
4032 private static String getMmTelProvisioningKey(int subId, int tech) {
4033 // resulting key is provision_ims_mmtel_{subId}_{tech}
4034 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4035 }
4036
4037 /**
4038 * Query CarrierConfig to see if the specified capability requires provisioning for the
4039 * carrier associated with the subscription id.
4040 */
4041 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4042 int capability) {
4043 CarrierConfigManager configManager = new CarrierConfigManager(context);
4044 PersistableBundle c = configManager.getConfigForSubId(subId);
4045 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004046 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004047 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4048 false);
4049 boolean requireVoiceVtProvisioning = c.getBoolean(
4050 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4051
4052 // First check to make sure that the capability requires provisioning.
4053 switch (capability) {
4054 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4055 // intentional fallthrough
4056 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4057 if (requireVoiceVtProvisioning) {
4058 // Voice and Video requires provisioning
4059 return true;
4060 }
4061 break;
4062 }
4063 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4064 if (requireUtProvisioning) {
4065 // UT requires provisioning
4066 return true;
4067 }
4068 break;
4069 }
4070 }
4071 return false;
4072 }
4073
allenwtsu99c623b2020-01-03 18:24:23 +08004074 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4075 int capability) {
4076 CarrierConfigManager configManager = new CarrierConfigManager(context);
4077 PersistableBundle c = configManager.getConfigForSubId(subId);
4078
4079 boolean requireRcsProvisioning = c.getBoolean(
4080 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4081
4082 // First check to make sure that the capability requires provisioning.
4083 switch (capability) {
4084 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4085 // intentional fallthrough
4086 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4087 if (requireRcsProvisioning) {
4088 // OPTION or PRESENCE requires provisioning
4089 return true;
4090 }
4091 break;
4092 }
4093 }
4094 return false;
4095 }
4096
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004097 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004098 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004099 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4100 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4101 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004102 enforceReadPrivilegedPermission("getImsProvisioningInt");
4103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004106 int slotId = getSlotIndex(subId);
4107 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4108 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4109 + subId + "' for key:" + key);
4110 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4111 }
4112 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004113 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004114 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4115 + subId + "' for key:" + key);
4116 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004117 } finally {
4118 Binder.restoreCallingIdentity(identity);
4119 }
4120 }
4121
4122 @Override
4123 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004124 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4125 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4126 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004127 enforceReadPrivilegedPermission("getImsProvisioningString");
4128 final long identity = Binder.clearCallingIdentity();
4129 try {
4130 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004131 int slotId = getSlotIndex(subId);
4132 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4133 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4134 + subId + "' for key:" + key);
4135 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4136 }
4137 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004138 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004139 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4140 + subId + "' for key:" + key);
4141 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004142 } finally {
4143 Binder.restoreCallingIdentity(identity);
4144 }
4145 }
4146
4147 @Override
4148 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004149 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4150 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4151 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4153 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004154 final long identity = Binder.clearCallingIdentity();
4155 try {
4156 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004157 int slotId = getSlotIndex(subId);
4158 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4159 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4160 + subId + "' for key:" + key);
4161 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4162 }
4163 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004164 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004165 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4166 + "' for key:" + key);
4167 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004168 } finally {
4169 Binder.restoreCallingIdentity(identity);
4170 }
4171 }
4172
4173 @Override
4174 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004175 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4176 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4177 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004178 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4179 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004180 final long identity = Binder.clearCallingIdentity();
4181 try {
4182 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004183 int slotId = getSlotIndex(subId);
4184 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4185 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4186 + subId + "' for key:" + key);
4187 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4188 }
4189 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004190 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004191 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4192 + "' for key:" + key);
4193 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004194 } finally {
4195 Binder.restoreCallingIdentity(identity);
4196 }
4197 }
4198
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004199 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004200 int slotId = SubscriptionManager.getSlotIndex(subId);
4201 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004202 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4203 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004204 }
4205 return slotId;
4206 }
4207
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004208 private int getSlotIndex(int subId) {
4209 int slotId = SubscriptionManager.getSlotIndex(subId);
4210 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4211 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4212 }
4213 return slotId;
4214 }
4215
Wink Saville36469e72014-06-11 15:17:00 -07004216 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004217 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004218 */
4219 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004220 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4221 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004222 final int targetSdk = getTargetSdk(callingPackage);
4223 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004224 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004225 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004226 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004227 mApp, subId, callingPackage, callingFeatureId,
4228 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004229 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4230 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004232 final long identity = Binder.clearCallingIdentity();
4233 try {
4234 final Phone phone = getPhone(subId);
4235 if (phone != null) {
4236 return phone.getServiceState().getDataNetworkType();
4237 } else {
4238 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4239 }
4240 } finally {
4241 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004243 }
4244
4245 /**
4246 * Returns the data network type
4247 */
4248 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004249 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4250 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4251 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004252 }
4253
4254 /**
4255 * Returns the data network type for a subId
4256 */
4257 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004258 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4259 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004261 mApp, subId, callingPackage, callingFeatureId,
4262 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004263 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4264 }
4265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004266 final long identity = Binder.clearCallingIdentity();
4267 try {
4268 final Phone phone = getPhone(subId);
4269 if (phone != null) {
4270 return phone.getServiceState().getDataNetworkType();
4271 } else {
4272 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4273 }
4274 } finally {
4275 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004277 }
4278
4279 /**
Wink Saville36469e72014-06-11 15:17:00 -07004280 * Returns the Voice network type for a subId
4281 */
4282 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004283 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4284 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004286 mApp, subId, callingPackage, callingFeatureId,
4287 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004288 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4289 }
4290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004291 final long identity = Binder.clearCallingIdentity();
4292 try {
4293 final Phone phone = getPhone(subId);
4294 if (phone != null) {
4295 return phone.getServiceState().getVoiceNetworkType();
4296 } else {
4297 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4298 }
4299 } finally {
4300 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004301 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004302 }
4303
4304 /**
4305 * @return true if a ICC card is present
4306 */
4307 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004308 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004309 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4310 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004311 }
4312
4313 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004314 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004315 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004316 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004317 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004318 final long identity = Binder.clearCallingIdentity();
4319 try {
4320 final Phone phone = PhoneFactory.getPhone(slotIndex);
4321 if (phone != null) {
4322 return phone.getIccCard().hasIccCard();
4323 } else {
4324 return false;
4325 }
4326 } finally {
4327 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004329 }
4330
4331 /**
4332 * Return if the current radio is LTE on CDMA. This
4333 * is a tri-state return value as for a period of time
4334 * the mode may be unknown.
4335 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004336 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004337 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004338 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004339 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004340 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004341 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4342 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4343 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004344 }
4345
Sanket Padawe356d7632015-06-22 14:03:32 -07004346 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004347 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4348 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004349 try {
4350 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4351 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004352 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4353 }
4354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004355 final long identity = Binder.clearCallingIdentity();
4356 try {
4357 final Phone phone = getPhone(subId);
4358 if (phone == null) {
4359 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4360 } else {
4361 return phone.getLteOnCdmaMode();
4362 }
4363 } finally {
4364 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004365 }
Wink Saville36469e72014-06-11 15:17:00 -07004366 }
4367
Wink Saville36469e72014-06-11 15:17:00 -07004368 /**
4369 * {@hide}
4370 * Returns Default subId, 0 in the case of single standby.
4371 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004372 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004373 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004374 }
4375
Shishir Agrawala9f32182016-04-12 12:00:16 -07004376 private int getSlotForDefaultSubscription() {
4377 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4378 }
4379
Wink Savilleb564aae2014-10-23 10:18:09 -07004380 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004381 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004382 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004383
Pengquan Menge92a50d2018-09-21 15:54:48 -07004384 private boolean isActiveSubscription(int subId) {
4385 return mSubscriptionController.isActiveSubId(subId);
4386 }
4387
Ihab Awadf2177b72013-11-25 13:33:23 -08004388 /**
4389 * @see android.telephony.TelephonyManager.WifiCallingChoices
4390 */
4391 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004392 final long identity = Binder.clearCallingIdentity();
4393 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004394 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004395 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4396 getWhenToMakeWifiCallsDefaultPreference());
4397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004400 }
4401
4402 /**
4403 * @see android.telephony.TelephonyManager.WifiCallingChoices
4404 */
4405 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406 final long identity = Binder.clearCallingIdentity();
4407 try {
4408 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004409 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4411 } finally {
4412 Binder.restoreCallingIdentity(identity);
4413 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004414 }
4415
Sailesh Nepald1e68152013-12-12 19:08:02 -08004416 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004417 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004418 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004419 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004420
Jordan Liu4c733742019-02-28 12:03:40 -08004421 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4422 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4423 if (phoneId == -1) {
4424 throw new IllegalArgumentException("Given slot index: " + slotIndex
4425 + " does not correspond to an active phone");
4426 }
4427 return PhoneFactory.getPhone(phoneId);
4428 }
4429
Shishir Agrawal566b7612013-10-28 14:41:00 -07004430 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004431 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4432 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4434 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004435 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004436 if (DBG) {
4437 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4438 }
4439 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4440 p2);
4441 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004442
Jordan Liu4c733742019-02-28 12:03:40 -08004443
4444 @Override
4445 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4446 int slotIndex, String callingPackage, String aid, int p2) {
4447 enforceModifyPermission();
4448 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4449 if (DBG) {
4450 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4451 }
4452 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4453 callingPackage, aid, p2);
4454 }
4455
4456 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4457 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458 final long identity = Binder.clearCallingIdentity();
4459 try {
4460 if (TextUtils.equals(ISDR_AID, aid)) {
4461 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004462 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4463 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004464 if (bestComponent == null
4465 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4466 loge("The calling package is not allowed to access ISD-R.");
4467 throw new SecurityException(
4468 "The calling package is not allowed to access ISD-R.");
4469 }
Derek Tan740e1672017-06-27 14:56:27 -07004470 }
Derek Tan740e1672017-06-27 14:56:27 -07004471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004473 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4474 null /* workSource */);
4475 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004476 return response;
4477 } finally {
4478 Binder.restoreCallingIdentity(identity);
4479 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004480 }
4481
4482 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004483 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4485 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004486 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4487 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4488 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004489
Jordan Liu4c733742019-02-28 12:03:40 -08004490 @Override
4491 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4492 enforceModifyPermission();
4493 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4494 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4495 channel);
4496 }
4497
4498 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499 final long identity = Binder.clearCallingIdentity();
4500 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004501 if (channel < 0) {
4502 return false;
4503 }
Jordan Liu4c733742019-02-28 12:03:40 -08004504 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4505 null /* workSource */);
4506 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004507 return success;
4508 } finally {
4509 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004510 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004511 }
4512
4513 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004514 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004515 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4517 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004518 if (DBG) {
4519 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4520 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4521 + p3 + " data=" + data);
4522 }
4523 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4524 command, p1, p2, p3, data);
4525 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004526
Jordan Liu4c733742019-02-28 12:03:40 -08004527 @Override
4528 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4529 int command, int p1, int p2, int p3, String data) {
4530 enforceModifyPermission();
4531 if (DBG) {
4532 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4533 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4534 + p3 + " data=" + data);
4535 }
4536 return iccTransmitApduLogicalChannelWithPermission(
4537 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4538 data);
4539 }
4540
4541 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4542 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004543 final long identity = Binder.clearCallingIdentity();
4544 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004545 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004546 return "";
4547 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004549 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004550 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4551 null /* workSource */);
4552 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 // Append the returned status code to the end of the response payload.
4555 String s = Integer.toHexString(
4556 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4557 if (response.payload != null) {
4558 s = IccUtils.bytesToHexString(response.payload) + s;
4559 }
4560 return s;
4561 } finally {
4562 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004563 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004564 }
Jake Hambye994d462014-02-03 13:10:13 -08004565
Evan Charltonc66da362014-05-16 14:06:40 -07004566 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004567 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4568 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4570 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004572 if (DBG) {
4573 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4574 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4575 }
4576 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4577 cla, command, p1, p2, p3, data);
4578 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004579
Jordan Liu4c733742019-02-28 12:03:40 -08004580 @Override
4581 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4582 int command, int p1, int p2, int p3, String data) {
4583 enforceModifyPermission();
4584 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4585 if (DBG) {
4586 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4587 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4588 + " data=" + data);
4589 }
4590
4591 return iccTransmitApduBasicChannelWithPermission(
4592 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4593 p2, p3, data);
4594 }
4595
4596 // open APDU basic channel assuming the caller has sufficient permissions
4597 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4598 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004599 final long identity = Binder.clearCallingIdentity();
4600 try {
4601 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4602 && TextUtils.equals(ISDR_AID, data)) {
4603 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004604 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4605 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004606 if (bestComponent == null
4607 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4608 loge("The calling package is not allowed to select ISD-R.");
4609 throw new SecurityException(
4610 "The calling package is not allowed to select ISD-R.");
4611 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004612 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004614 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004615 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4616 null /* workSource */);
4617 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004619 // Append the returned status code to the end of the response payload.
4620 String s = Integer.toHexString(
4621 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4622 if (response.payload != null) {
4623 s = IccUtils.bytesToHexString(response.payload) + s;
4624 }
4625 return s;
4626 } finally {
4627 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004628 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004629 }
4630
4631 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004632 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004633 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4635 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637 final long identity = Binder.clearCallingIdentity();
4638 try {
4639 if (DBG) {
4640 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4641 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4642 }
4643
4644 IccIoResult response =
4645 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4646 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4647 subId);
4648
4649 if (DBG) {
4650 log("Exchange SIM_IO [R]" + response);
4651 }
4652
4653 byte[] result = null;
4654 int length = 2;
4655 if (response.payload != null) {
4656 length = 2 + response.payload.length;
4657 result = new byte[length];
4658 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4659 } else {
4660 result = new byte[length];
4661 }
4662
4663 result[length - 1] = (byte) response.sw2;
4664 result[length - 2] = (byte) response.sw1;
4665 return result;
4666 } finally {
4667 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004668 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004669 }
4670
Nathan Haroldb3014052017-01-25 15:57:32 -08004671 /**
4672 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4673 * on a particular subscription
4674 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004675 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4676 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004677 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004678 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004679 return null;
4680 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681
4682 final long identity = Binder.clearCallingIdentity();
4683 try {
4684 if (appType != TelephonyManager.APPTYPE_USIM
4685 && appType != TelephonyManager.APPTYPE_SIM) {
4686 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4687 return null;
4688 }
4689 Object response = sendRequest(
4690 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4691 if (response instanceof String[]) {
4692 return (String[]) response;
4693 }
yincheng zhaod698b842019-09-06 17:06:54 -07004694 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004695 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004696 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004697 } finally {
4698 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004699 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004700 }
4701
yincheng zhaod698b842019-09-06 17:06:54 -07004702 /**
4703 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4704 * subscription.
4705 *
4706 * @param subId the id of the subscription.
4707 * @param appType the uicc app type, must be USIM or SIM.
4708 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4709 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004710 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004711 * @return number of fplmns that is successfully written to the SIM.
4712 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004713 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4714 String callingFeatureId) {
4715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4716 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004717 if (DBG) logv("no permissions for setForbiddenplmns");
4718 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4719 }
4720 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4721 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4722 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4723 }
4724 if (fplmns == null) {
4725 throw new IllegalArgumentException("Fplmn List provided is null");
4726 }
4727 for (String fplmn : fplmns) {
4728 if (!CellIdentity.isValidPlmn(fplmn)) {
4729 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4730 }
4731 }
4732 final long identity = Binder.clearCallingIdentity();
4733 try {
4734 Object response = sendRequest(
4735 CMD_SET_FORBIDDEN_PLMNS,
4736 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4737 subId);
4738 return (int) response;
4739 } finally {
4740 Binder.restoreCallingIdentity(identity);
4741 }
4742 }
4743
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004744 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004745 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4747 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004748
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004749 final long identity = Binder.clearCallingIdentity();
4750 try {
4751 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4752 if (response.payload == null) {
4753 return "";
4754 }
Evan Charltonc66da362014-05-16 14:06:40 -07004755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004756 // Append the returned status code to the end of the response payload.
4757 String s = Integer.toHexString(
4758 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4759 s = IccUtils.bytesToHexString(response.payload) + s;
4760 return s;
4761 } finally {
4762 Binder.restoreCallingIdentity(identity);
4763 }
Evan Charltonc66da362014-05-16 14:06:40 -07004764 }
4765
Jake Hambye994d462014-02-03 13:10:13 -08004766 /**
4767 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4768 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4769 *
4770 * @param itemID the ID of the item to read
4771 * @return the NV item as a String, or null on error.
4772 */
4773 @Override
4774 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004775 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4777 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004778
4779 final long identity = Binder.clearCallingIdentity();
4780 try {
4781 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004782 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4784 return value;
4785 } finally {
4786 Binder.restoreCallingIdentity(identity);
4787 }
Jake Hambye994d462014-02-03 13:10:13 -08004788 }
4789
4790 /**
4791 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4792 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4793 *
4794 * @param itemID the ID of the item to read
4795 * @param itemValue the value to write, as a String
4796 * @return true on success; false on any failure
4797 */
4798 @Override
4799 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004800 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4802 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004803
4804 final long identity = Binder.clearCallingIdentity();
4805 try {
4806 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4807 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004808 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004809 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4810 return success;
4811 } finally {
4812 Binder.restoreCallingIdentity(identity);
4813 }
Jake Hambye994d462014-02-03 13:10:13 -08004814 }
4815
4816 /**
4817 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4818 * Used for device configuration by some CDMA operators.
4819 *
4820 * @param preferredRoamingList byte array containing the new PRL
4821 * @return true on success; false on any failure
4822 */
4823 @Override
4824 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4826 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004827
4828 final long identity = Binder.clearCallingIdentity();
4829 try {
4830 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4831 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4832 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4833 return success;
4834 } finally {
4835 Binder.restoreCallingIdentity(identity);
4836 }
Jake Hambye994d462014-02-03 13:10:13 -08004837 }
4838
4839 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004840 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004841 * Used for device configuration by some CDMA operators.
4842 *
chen xu6dac5ab2018-10-26 17:39:23 -07004843 * @param slotIndex - device slot.
4844 *
Jake Hambye994d462014-02-03 13:10:13 -08004845 * @return true on success; false on any failure
4846 */
4847 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004848 public boolean resetModemConfig(int slotIndex) {
4849 Phone phone = PhoneFactory.getPhone(slotIndex);
4850 if (phone != null) {
4851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4852 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853
chen xu6dac5ab2018-10-26 17:39:23 -07004854 final long identity = Binder.clearCallingIdentity();
4855 try {
4856 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4857 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4858 return success;
4859 } finally {
4860 Binder.restoreCallingIdentity(identity);
4861 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004862 }
chen xu6dac5ab2018-10-26 17:39:23 -07004863 return false;
4864 }
4865
4866 /**
4867 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4868 *
4869 * @param slotIndex - device slot.
4870 *
4871 * @return true on success; false on any failure
4872 */
4873 @Override
4874 public boolean rebootModem(int slotIndex) {
4875 Phone phone = PhoneFactory.getPhone(slotIndex);
4876 if (phone != null) {
4877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4878 mApp, phone.getSubId(), "rebootModem");
4879
4880 final long identity = Binder.clearCallingIdentity();
4881 try {
4882 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4883 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4884 return success;
4885 } finally {
4886 Binder.restoreCallingIdentity(identity);
4887 }
4888 }
4889 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004890 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004891
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004892 public String[] getPcscfAddress(String apnType, String callingPackage,
4893 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004894 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4896 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004897 return new String[0];
4898 }
4899
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900 final long identity = Binder.clearCallingIdentity();
4901 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004902 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
Wink Saville36469e72014-06-11 15:17:00 -07004906 }
4907
Brad Ebinger51f743a2017-01-23 13:50:20 -08004908 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004909 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4910 * {@link #disableIms(int)}.
4911 * @param slotIndex device slot.
4912 */
4913 public void resetIms(int slotIndex) {
4914 enforceModifyPermission();
4915
4916 final long identity = Binder.clearCallingIdentity();
4917 try {
4918 if (mImsResolver == null) {
4919 // may happen if the does not support IMS.
4920 return;
4921 }
4922 mImsResolver.disableIms(slotIndex);
4923 mImsResolver.enableIms(slotIndex);
4924 } finally {
4925 Binder.restoreCallingIdentity(identity);
4926 }
4927 }
4928
4929 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004930 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4931 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004932 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004933 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004934 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935
4936 final long identity = Binder.clearCallingIdentity();
4937 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004938 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004939 // may happen if the device does not support IMS.
4940 return;
4941 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004942 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943 } finally {
4944 Binder.restoreCallingIdentity(identity);
4945 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004946 }
4947
4948 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004949 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4950 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004951 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004952 public void disableIms(int slotId) {
4953 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954
4955 final long identity = Binder.clearCallingIdentity();
4956 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004957 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004958 // may happen if the device does not support IMS.
4959 return;
4960 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004961 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962 } finally {
4963 Binder.restoreCallingIdentity(identity);
4964 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004965 }
4966
4967 /**
4968 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4969 * feature or {@link null} if the service is not available. If the feature is available, the
4970 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4971 */
4972 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004973 IImsServiceFeatureCallback callback) {
4974 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975
4976 final long identity = Binder.clearCallingIdentity();
4977 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004978 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004979 // may happen if the device does not support IMS.
4980 return null;
4981 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004982 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983 } finally {
4984 Binder.restoreCallingIdentity(identity);
4985 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004986 }
4987
4988 /**
4989 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4990 * feature during emergency calling or {@link null} if the service is not available. If the
4991 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4992 * listener for feature updates.
4993 */
4994 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4995 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996
4997 final long identity = Binder.clearCallingIdentity();
4998 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004999 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005000 // may happen if the device does not support IMS.
5001 return null;
5002 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005003 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 } finally {
5005 Binder.restoreCallingIdentity(identity);
5006 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005007 }
5008
Brad Ebinger5f64b052017-12-14 14:26:15 -08005009 /**
5010 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005011 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005012 */
5013 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5014 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005015
5016 final long identity = Binder.clearCallingIdentity();
5017 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005018 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005019 // may happen if the device does not support IMS.
5020 return null;
5021 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005022 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023 } finally {
5024 Binder.restoreCallingIdentity(identity);
5025 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005026 }
5027
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005028 /**
5029 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005030 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005031 */
5032 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5033 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005034
5035 final long identity = Binder.clearCallingIdentity();
5036 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005037 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005038 // may happen if the device does not support IMS.
5039 return null;
5040 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005041 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042 } finally {
5043 Binder.restoreCallingIdentity(identity);
5044 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005045 }
5046
Brad Ebinger884c07b2018-02-15 16:17:40 -08005047 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005048 * Sets the ImsService Package Name that Telephony will bind to.
5049 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005050 * @param slotIndex the slot ID that the ImsService should bind for.
5051 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005052 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005053 * @param featureTypes An integer array of feature types associated with a packageName.
5054 * @param packageName The name of the package that the current configuration will be replaced
5055 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005056 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005057 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005058 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5059 int[] featureTypes, String packageName) {
5060 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5061 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5063 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005064 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 final long identity = Binder.clearCallingIdentity();
5067 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005068 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005069 // may happen if the device does not support IMS.
5070 return false;
5071 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005072 Map<Integer, String> featureConfig = new HashMap<>();
5073 for (int featureType : featureTypes) {
5074 featureConfig.put(featureType, packageName);
5075 }
5076 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5077 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 } finally {
5079 Binder.restoreCallingIdentity(identity);
5080 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005081 }
5082
5083 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005084 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005085 *
5086 * @param slotId The slot that the ImsService is associated with.
5087 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5088 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005089 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005090 * @return the package name of the ImsService configuration.
5091 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005092 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5093 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005094 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005095 TelephonyPermissions
5096 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5097 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5098 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005099
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005100 final long identity = Binder.clearCallingIdentity();
5101 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005102 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005103 // may happen if the device does not support IMS.
5104 return "";
5105 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005106 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005107 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5108 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005109 } finally {
5110 Binder.restoreCallingIdentity(identity);
5111 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005112 }
5113
Brad Ebinger77b832e2019-10-17 17:03:22 -07005114 /**
5115 * Get the MmTelFeature state associated with the requested subscription id.
5116 * @param subId The subscription that the MmTelFeature is associated with.
5117 * @param callback A callback with an integer containing the
5118 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5119 */
5120 @Override
5121 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5122 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5123 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5124 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5125 "IMS not available on device.");
5126 }
5127 final long token = Binder.clearCallingIdentity();
5128 try {
5129 int slotId = getSlotIndex(subId);
5130 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5131 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5132 + subId + "'");
5133 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5134 }
5135 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5136 try {
5137 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5138 } catch (RemoteException e) {
5139 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5140 + "Ignore");
5141 }
5142 });
5143 } finally {
5144 Binder.restoreCallingIdentity(token);
5145 }
5146 }
5147
Wink Saville36469e72014-06-11 15:17:00 -07005148 public void setImsRegistrationState(boolean registered) {
5149 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005150
5151 final long identity = Binder.clearCallingIdentity();
5152 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005153 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 } finally {
5155 Binder.restoreCallingIdentity(identity);
5156 }
Wink Saville36469e72014-06-11 15:17:00 -07005157 }
5158
5159 /**
Stuart Scott54788802015-03-30 13:18:01 -07005160 * Set the network selection mode to automatic.
5161 *
5162 */
5163 @Override
5164 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5166 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167
5168 final long identity = Binder.clearCallingIdentity();
5169 try {
shilufc958392020-01-20 11:36:01 -08005170 if (!isActiveSubscription(subId)) {
5171 return;
5172 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5174 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
5177 }
Stuart Scott54788802015-03-30 13:18:01 -07005178 }
5179
Pengquan Mengea84e042018-09-20 14:57:26 -07005180 /**
5181 * Ask the radio to connect to the input network and change selection mode to manual.
5182 *
5183 * @param subId the id of the subscription.
5184 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5185 * the operator to attach to.
5186 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5187 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5188 * normal network selection next time.
5189 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005190 */
5191 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005192 public boolean setNetworkSelectionModeManual(
5193 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005194 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5195 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005196
5197 if (!isActiveSubscription(subId)) {
5198 return false;
5199 }
5200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 final long identity = Binder.clearCallingIdentity();
5202 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005203 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005205 if (DBG) {
5206 log("setNetworkSelectionModeManual: subId: " + subId
5207 + " operator: " + operatorInfo);
5208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005209 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5210 } finally {
5211 Binder.restoreCallingIdentity(identity);
5212 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005213 }
5214
5215 /**
5216 * Scans for available networks.
5217 */
5218 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005219 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5220 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5222 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005223 LocationAccessPolicy.LocationPermissionResult locationResult =
5224 LocationAccessPolicy.checkLocationPermission(mApp,
5225 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5226 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005227 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005228 .setCallingPid(Binder.getCallingPid())
5229 .setCallingUid(Binder.getCallingUid())
5230 .setMethod("getCellNetworkScanResults")
5231 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5232 .build());
5233 switch (locationResult) {
5234 case DENIED_HARD:
5235 throw new SecurityException("Not allowed to access scan results -- location");
5236 case DENIED_SOFT:
5237 return null;
5238 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239
Pengquan Menga1bb6272018-09-06 09:59:22 -07005240 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 try {
5242 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005243 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 } finally {
5246 Binder.restoreCallingIdentity(identity);
5247 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005248 }
5249
5250 /**
sqian80370722020-01-29 15:02:51 -08005251 * Get the call forwarding info, given the call forwarding reason.
5252 */
5253 @Override
5254 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5255 enforceReadPrivilegedPermission("getCallForwarding");
5256 long identity = Binder.clearCallingIdentity();
5257 try {
5258 if (DBG) {
5259 log("getCallForwarding: subId " + subId
5260 + " callForwardingReason" + callForwardingReason);
5261 }
5262 return (CallForwardingInfo) sendRequest(
5263 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5264 } finally {
5265 Binder.restoreCallingIdentity(identity);
5266 }
5267 }
5268
5269 /**
5270 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5271 * reason, the number to forward, and the timeout before the forwarding is attempted.
5272 */
5273 @Override
5274 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5275 enforceModifyPermission();
5276 long identity = Binder.clearCallingIdentity();
5277 try {
5278 if (DBG) {
5279 log("setCallForwarding: subId " + subId
5280 + " callForwardingInfo" + callForwardingInfo);
5281 }
5282 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
5286 }
5287
5288 /**
5289 * Get the call forwarding info, given the call forwarding reason.
5290 */
5291 @Override
5292 public int getCallWaitingStatus(int subId) {
5293 enforceReadPrivilegedPermission("getCallForwarding");
5294 long identity = Binder.clearCallingIdentity();
5295 try {
5296 if (DBG) log("getCallWaitingStatus: subId " + subId);
5297 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5298 } finally {
5299 Binder.restoreCallingIdentity(identity);
5300 }
5301 }
5302
5303 /**
5304 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5305 * reason, the number to forward, and the timeout before the forwarding is attempted.
5306 */
5307 @Override
5308 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5309 enforceModifyPermission();
5310 long identity = Binder.clearCallingIdentity();
5311 try {
5312 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5313 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5314 } finally {
5315 Binder.restoreCallingIdentity(identity);
5316 }
5317 }
5318
5319 /**
yinxub1bed742017-04-17 11:45:04 -07005320 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005321 *
yinxub1bed742017-04-17 11:45:04 -07005322 * @param subId id of the subscription
5323 * @param request contains the radio access networks with bands/channels to scan
5324 * @param messenger callback messenger for scan results or errors
5325 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005326 * @return the id of the requested scan which can be used to stop the scan.
5327 */
5328 @Override
5329 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005330 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5332 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005333 LocationAccessPolicy.LocationPermissionResult locationResult =
5334 LocationAccessPolicy.checkLocationPermission(mApp,
5335 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5336 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005337 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005338 .setCallingPid(Binder.getCallingPid())
5339 .setCallingUid(Binder.getCallingUid())
5340 .setMethod("requestNetworkScan")
5341 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5342 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005343 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005344 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005345 if (e != null) {
5346 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5347 throw e;
5348 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005349 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005350 return TelephonyScanManager.INVALID_SCAN_ID;
5351 }
5352 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353 }
Hall Liu912dfd32019-04-25 14:02:26 -07005354 int callingUid = Binder.getCallingUid();
5355 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005356 final long identity = Binder.clearCallingIdentity();
5357 try {
5358 return mNetworkScanRequestTracker.startNetworkScan(
5359 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005360 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005361 } finally {
5362 Binder.restoreCallingIdentity(identity);
5363 }
yinxu504e1392017-04-12 16:03:22 -07005364 }
5365
Hall Liub2ac8ef2019-02-28 15:56:23 -08005366 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005367 NetworkScanRequest request, int subId) {
5368 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5369 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5370 boolean hasNetworkScanPermission =
5371 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5372 == PERMISSION_GRANTED;
5373
5374 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5375 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5376 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005377 }
5378
5379 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5380 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005381 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5382 return new SecurityException("Specific channels must not be"
5383 + " scanned without location access.");
5384 }
5385 }
5386 }
5387
Hall Liub2ac8ef2019-02-28 15:56:23 -08005388 return null;
5389 }
5390
yinxu504e1392017-04-12 16:03:22 -07005391 /**
5392 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005393 *
5394 * @param subId id of the subscription
5395 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005396 */
5397 @Override
5398 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5400 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401
Hall Liu912dfd32019-04-25 14:02:26 -07005402 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 final long identity = Binder.clearCallingIdentity();
5404 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005405 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 } finally {
5407 Binder.restoreCallingIdentity(identity);
5408 }
yinxu504e1392017-04-12 16:03:22 -07005409 }
5410
5411 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005412 * Get the calculated preferred network type.
5413 * Used for debugging incorrect network type.
5414 *
5415 * @return the preferred network type, defined in RILConstants.java.
5416 */
5417 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005418 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005419 final Phone defaultPhone = getDefaultPhone();
5420 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005421 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005422 return RILConstants.PREFERRED_NETWORK_MODE;
5423 }
5424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 final long identity = Binder.clearCallingIdentity();
5426 try {
5427 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005428 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429 } finally {
5430 Binder.restoreCallingIdentity(identity);
5431 }
Junda Liu84d15a22014-07-02 11:21:04 -07005432 }
5433
5434 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005435 * Get the preferred network type.
5436 * Used for device configuration by some CDMA operators.
5437 *
5438 * @return the preferred network type, defined in RILConstants.java.
5439 */
5440 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005441 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005442 TelephonyPermissions
5443 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5444 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445
5446 final long identity = Binder.clearCallingIdentity();
5447 try {
5448 if (DBG) log("getPreferredNetworkType");
5449 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5450 int networkType = (result != null ? result[0] : -1);
5451 if (DBG) log("getPreferredNetworkType: " + networkType);
5452 return networkType;
5453 } finally {
5454 Binder.restoreCallingIdentity(identity);
5455 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005456 }
5457
5458 /**
5459 * Set the preferred network type.
5460 * Used for device configuration by some CDMA operators.
5461 *
5462 * @param networkType the preferred network type, defined in RILConstants.java.
5463 * @return true on success; false on any failure.
5464 */
5465 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005466 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5468 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469
5470 final long identity = Binder.clearCallingIdentity();
5471 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005472 Settings.Global.putInt(mApp.getContentResolver(),
5473 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5474 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 } finally {
5476 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005477 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005478 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005479
5480 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005481 * Get the allowed network types that store in the telephony provider.
5482 *
5483 * @param subId the id of the subscription.
5484 * @return allowedNetworkTypes the allowed network types.
5485 */
5486 @Override
5487 public long getAllowedNetworkTypes(int subId) {
5488 TelephonyPermissions
5489 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5490 mApp, subId, "getAllowedNetworkTypes");
5491
5492 final long identity = Binder.clearCallingIdentity();
5493 try {
5494 return SubscriptionManager.getLongSubscriptionProperty(
5495 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5496 } finally {
5497 Binder.restoreCallingIdentity(identity);
5498 }
5499 }
5500
5501 /**
5502 * Set the allowed network types.
5503 *
5504 * @param subId the id of the subscription.
5505 * @param allowedNetworkTypes the allowed network types.
5506 * @return true on success; false on any failure.
5507 */
5508 @Override
5509 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5511 mApp, subId, "setAllowedNetworkTypes");
5512 final long identity = Binder.clearCallingIdentity();
5513 try {
5514 SubscriptionManager.setSubscriptionProperty(subId,
5515 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5516 String.valueOf(allowedNetworkTypes));
5517 return setPreferredNetworkTypesInternal(subId);
5518 } finally {
5519 Binder.restoreCallingIdentity(identity);
5520 }
5521 }
5522
5523 private boolean setPreferredNetworkTypesInternal(int subId) {
5524 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5525 Settings.Global.getInt(mApp.getContentResolver(),
5526 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5527 RILConstants.PREFERRED_NETWORK_MODE));
5528 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5529 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5530 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5531 (int) (networkTypeBitMask & allowedNetworkTypes));
5532
5533 if (DBG) {
5534 log("setPreferredNetworkTypesInternal: subId " + subId
5535 + " networkTypes " + networkTypeBitMask
5536 + " allowedNetworkTypes " + allowedNetworkTypes
5537 + " networkMode " + networkMode);
5538 }
5539
5540 Boolean success = (Boolean) sendRequest(
5541 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5542 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5543 return success;
5544 }
5545
5546 /**
Miaoa84611c2019-03-15 09:21:10 +08005547 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005548 *
Miaoa84611c2019-03-15 09:21:10 +08005549 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005550 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005551 * @hide
5552 */
5553 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005554 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005557 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 try {
Miaoa84611c2019-03-15 09:21:10 +08005559 if (phone != null) {
5560 return phone.hasMatchedTetherApnSetting();
5561 } else {
5562 return false;
5563 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564 } finally {
5565 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005566 }
Junda Liu475951f2014-11-07 16:45:03 -08005567 }
5568
5569 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005570 * Set mobile data enabled
5571 * Used by the user through settings etc to turn on/off mobile data
5572 *
5573 * @param enable {@code true} turn turn data on, else {@code false}
5574 */
5575 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005576 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5578 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579
5580 final long identity = Binder.clearCallingIdentity();
5581 try {
5582 int phoneId = mSubscriptionController.getPhoneId(subId);
5583 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5584 Phone phone = PhoneFactory.getPhone(phoneId);
5585 if (phone != null) {
5586 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005587 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005589 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590 }
5591 } finally {
5592 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005593 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005594 }
5595
5596 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005597 * Enable or disable always reporting signal strength changes from radio.
5598 *
5599 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5600 */
5601 @Override
5602 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5603 enforceModifyPermission();
5604 enforceSystemCaller();
5605
5606 final long identity = Binder.clearCallingIdentity();
5607 final Phone phone = getPhone(subId);
5608 try {
5609 if (phone != null) {
5610 if (DBG) {
5611 log("setAlwaysReportSignalStrength: subId=" + subId
5612 + " isEnable=" + isEnable);
5613 }
5614 phone.setAlwaysReportSignalStrength(isEnable);
5615 } else {
5616 loge("setAlwaysReportSignalStrength: no phone found for subId="
5617 + subId);
5618 }
5619 } finally {
5620 Binder.restoreCallingIdentity(identity);
5621 }
5622 }
5623
5624 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005625 * Get the user enabled state of Mobile Data.
5626 *
5627 * TODO: remove and use isUserDataEnabled.
5628 * This can't be removed now because some vendor codes
5629 * calls through ITelephony directly while they should
5630 * use TelephonyManager.
5631 *
5632 * @return true on enabled
5633 */
5634 @Override
5635 public boolean getDataEnabled(int subId) {
5636 return isUserDataEnabled(subId);
5637 }
5638
5639 /**
5640 * Get whether mobile data is enabled per user setting.
5641 *
5642 * There are other factors deciding whether mobile data is actually enabled, but they are
5643 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005644 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005645 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005646 *
5647 * @return {@code true} if data is enabled else {@code false}
5648 */
5649 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005650 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005651 try {
5652 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5653 null);
5654 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5656 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658
5659 final long identity = Binder.clearCallingIdentity();
5660 try {
5661 int phoneId = mSubscriptionController.getPhoneId(subId);
5662 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5663 Phone phone = PhoneFactory.getPhone(phoneId);
5664 if (phone != null) {
5665 boolean retVal = phone.isUserDataEnabled();
5666 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5667 return retVal;
5668 } else {
5669 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5670 return false;
5671 }
5672 } finally {
5673 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005674 }
5675 }
5676
5677 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005678 * Checks if the device is capable of mobile data by considering whether whether the
5679 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5680 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005681 *
Shuo Qian985d1232020-01-08 14:30:06 -08005682 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005683 */
5684 @Override
5685 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005686 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687
5688 final long identity = Binder.clearCallingIdentity();
5689 try {
5690 int phoneId = mSubscriptionController.getPhoneId(subId);
5691 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5692 Phone phone = PhoneFactory.getPhone(phoneId);
5693 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005694 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5696 return retVal;
5697 } else {
5698 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5699 return false;
5700 }
5701 } finally {
5702 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005703 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005704 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005705
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005706 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005707 Phone phone) {
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
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005713 PackageManager pkgMgr = phone.getContext().getPackageManager();
5714 String[] packages = pkgMgr.getPackagesForUid(uid);
5715
5716 final long identity = Binder.clearCallingIdentity();
5717 try {
5718 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5719 SubscriptionManager subManager = (SubscriptionManager)
5720 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5721 for (String pkg : packages) {
5722 if (subManager.canManageSubscription(subInfo, pkg)) {
5723 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5724 }
5725 }
5726 return privilegeFromSim;
5727 } finally {
5728 Binder.restoreCallingIdentity(identity);
5729 }
5730 }
5731
5732 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5733 String pkgName) {
5734 //load access rules from carrier configs, and check those as well: b/139133814
5735 SubscriptionController subController = SubscriptionController.getInstance();
5736 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5737 || subController == null) return privilegeFromSim;
5738
5739 final long identity = Binder.clearCallingIdentity();
5740 try {
5741 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5742 SubscriptionManager subManager = (SubscriptionManager)
5743 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5744 return subManager.canManageSubscription(subInfo, pkgName)
5745 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5746 } finally {
5747 Binder.restoreCallingIdentity(identity);
5748 }
5749 }
5750
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005751 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005752 public int getCarrierPrivilegeStatus(int subId) {
5753 final Phone phone = getPhone(subId);
5754 if (phone == null) {
5755 loge("getCarrierPrivilegeStatus: Invalid subId");
5756 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5757 }
5758 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005759 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005760 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005761 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5762 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005763
5764 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5765 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005766 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005767 }
Junda Liu29340342014-07-10 15:23:27 -07005768
5769 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005770 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005771 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005772 final Phone phone = getPhone(subId);
5773 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005774 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005775 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5776 }
5777 UiccProfile profile =
5778 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5779 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005780 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005781 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5782 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005783 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005784 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005785 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005786 }
5787
5788 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005789 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5790 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005791 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005792 }
5793
5794 int phoneId = SubscriptionManager.getPhoneId(subId);
5795 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005796 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005797 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005798 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5799 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005800 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5801 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5802 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005803 }
5804
5805 @Override
5806 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005807 if (TextUtils.isEmpty(pkgName))
5808 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005809 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5810 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5811 UiccCard card = UiccController.getInstance().getUiccCard(i);
5812 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005813 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005814 continue;
5815 }
5816
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005817 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5818 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5819 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005820 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5821 break;
5822 }
5823 }
5824
5825 return result;
Junda Liu29340342014-07-10 15:23:27 -07005826 }
Derek Tan89e89d42014-07-08 17:00:10 -07005827
5828 @Override
Junda Liue64de782015-04-16 17:19:16 -07005829 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5830 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5831 loge("phoneId " + phoneId + " is not valid.");
5832 return null;
5833 }
5834 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005835 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005836 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005837 return null ;
5838 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005839 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005840 }
5841
Amith Yamasani6e118872016-02-19 12:53:51 -08005842 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005843 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005844 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005845 List<String> privilegedPackages = new ArrayList<>();
5846 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005847 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5848 // has UICC in that slot.
5849 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005850 if (card.hasCarrierPrivilegeRules()) {
5851 if (packages == null) {
5852 // Only check packages in user 0 for now
5853 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005854 PackageManager.MATCH_DISABLED_COMPONENTS
5855 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005856 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005857 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005858 }
5859 for (int p = packages.size() - 1; p >= 0; p--) {
5860 PackageInfo pkgInfo = packages.get(p);
5861 if (pkgInfo != null && pkgInfo.packageName != null
5862 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005863 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005864 privilegedPackages.add(pkgInfo.packageName);
5865 }
5866 }
5867 }
5868 }
5869 return privilegedPackages;
5870 }
5871
chen xuf7e9fe82019-05-09 19:31:02 -07005872 @Override
5873 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005874 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5875
5876 final long identity = Binder.clearCallingIdentity();
5877
chen xuf7e9fe82019-05-09 19:31:02 -07005878 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005879 try {
5880 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5881 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5882 }
5883 } finally {
5884 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005885 }
5886 return privilegedPackages;
5887 }
5888
Wink Savilleb564aae2014-10-23 10:18:09 -07005889 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005890 final Phone phone = getPhone(subId);
5891 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005892 if (card == null) {
5893 loge("getIccId: No UICC");
5894 return null;
5895 }
5896 String iccId = card.getIccId();
5897 if (TextUtils.isEmpty(iccId)) {
5898 loge("getIccId: ICC ID is null or empty.");
5899 return null;
5900 }
5901 return iccId;
5902 }
5903
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005904 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005905 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5906 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005907 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005908 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005910 final long identity = Binder.clearCallingIdentity();
5911 try {
5912 final String iccId = getIccId(subId);
5913 final Phone phone = getPhone(subId);
5914 if (phone == null) {
5915 return false;
5916 }
5917 final String subscriberId = phone.getSubscriberId();
5918
5919 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005920 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921 + subscriberId + " to " + number);
5922 }
5923
5924 if (TextUtils.isEmpty(iccId)) {
5925 return false;
5926 }
5927
5928 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5929
5930 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5931 if (alphaTag == null) {
5932 editor.remove(alphaTagPrefKey);
5933 } else {
5934 editor.putString(alphaTagPrefKey, alphaTag);
5935 }
5936
5937 // Record both the line number and IMSI for this ICCID, since we need to
5938 // track all merged IMSIs based on line number
5939 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5940 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5941 if (number == null) {
5942 editor.remove(numberPrefKey);
5943 editor.remove(subscriberPrefKey);
5944 } else {
5945 editor.putString(numberPrefKey, number);
5946 editor.putString(subscriberPrefKey, subscriberId);
5947 }
5948
5949 editor.commit();
5950 return true;
5951 } finally {
5952 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005953 }
Derek Tan7226c842014-07-02 17:42:23 -07005954 }
5955
5956 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005957 public String getLine1NumberForDisplay(int subId, String callingPackage,
5958 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005959 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005961 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005962 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
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 numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5971 if (DBG_MERGE) {
5972 log("getLine1NumberForDisplay returning "
5973 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5974 }
5975 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005977 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5978 return null;
5979 } finally {
5980 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005981 }
Derek Tan7226c842014-07-02 17:42:23 -07005982 }
5983
5984 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005985 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5986 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005988 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005989 return null;
5990 }
Derek Tan97ebb422014-09-05 16:55:38 -07005991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 final long identity = Binder.clearCallingIdentity();
5993 try {
5994 String iccId = getIccId(subId);
5995 if (iccId != null) {
5996 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5997 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5998 }
5999 return null;
6000 } finally {
6001 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006002 }
Derek Tan7226c842014-07-02 17:42:23 -07006003 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006004
6005 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006006 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6007 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006008 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6009 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006010 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006011 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006012 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006013 return null;
6014 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006015
Jordan Liub49b04b2019-05-06 14:45:15 -07006016 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6017 // the process, where TelephonyManager was instantiated.
6018 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006019 final long identity = Binder.clearCallingIdentity();
6020 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006021 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 final TelephonyManager tele = TelephonyManager.from(context);
6023 final SubscriptionManager sub = SubscriptionManager.from(context);
6024
6025 // Figure out what subscribers are currently active
6026 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027
Jordan Liub49b04b2019-05-06 14:45:15 -07006028 // Only consider subs which match the current subId
6029 // This logic can be simplified. See b/131189269 for progress.
6030 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006031 activeSubscriberIds.add(tele.getSubscriberId(subId));
6032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033
6034 // First pass, find a number override for an active subscriber
6035 String mergeNumber = null;
6036 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6037 for (String key : prefs.keySet()) {
6038 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6039 final String subscriberId = (String) prefs.get(key);
6040 if (activeSubscriberIds.contains(subscriberId)) {
6041 final String iccId = key.substring(
6042 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6043 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6044 mergeNumber = (String) prefs.get(numberKey);
6045 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006046 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006047 + " for active subscriber " + subscriberId);
6048 }
6049 if (!TextUtils.isEmpty(mergeNumber)) {
6050 break;
6051 }
6052 }
6053 }
6054 }
6055
6056 // Shortcut when no active merged subscribers
6057 if (TextUtils.isEmpty(mergeNumber)) {
6058 return null;
6059 }
6060
6061 // Second pass, find all subscribers under that line override
6062 final ArraySet<String> result = new ArraySet<>();
6063 for (String key : prefs.keySet()) {
6064 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6065 final String number = (String) prefs.get(key);
6066 if (mergeNumber.equals(number)) {
6067 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6068 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6069 final String subscriberId = (String) prefs.get(subscriberKey);
6070 if (!TextUtils.isEmpty(subscriberId)) {
6071 result.add(subscriberId);
6072 }
6073 }
6074 }
6075 }
6076
6077 final String[] resultArray = result.toArray(new String[result.size()]);
6078 Arrays.sort(resultArray);
6079 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006080 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6082 }
6083 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006084 } finally {
6085 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006086 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006087 }
6088
6089 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006090 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6091 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6092
6093 final long identity = Binder.clearCallingIdentity();
6094 try {
6095 final TelephonyManager telephonyManager = mApp.getSystemService(
6096 TelephonyManager.class);
6097 String subscriberId = telephonyManager.getSubscriberId(subId);
6098 if (subscriberId == null) {
6099 if (DBG) {
6100 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6101 + subId);
6102 }
6103 return null;
6104 }
6105
6106 final SubscriptionInfo info = SubscriptionController.getInstance()
6107 .getSubscriptionInfo(subId);
6108 final ParcelUuid groupUuid = info.getGroupUuid();
6109 // If it doesn't belong to any group, return just subscriberId of itself.
6110 if (groupUuid == null) {
6111 return new String[]{subscriberId};
6112 }
6113
6114 // Get all subscriberIds from the group.
6115 final List<String> mergedSubscriberIds = new ArrayList<>();
6116 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006117 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6118 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006119 for (SubscriptionInfo subInfo : groupInfos) {
6120 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6121 if (subscriberId != null) {
6122 mergedSubscriberIds.add(subscriberId);
6123 }
6124 }
6125
6126 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6127 } finally {
6128 Binder.restoreCallingIdentity(identity);
6129
6130 }
6131 }
6132
6133 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006134 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006135 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006136 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137
6138 final long identity = Binder.clearCallingIdentity();
6139 try {
6140 final Phone phone = getPhone(subId);
6141 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6142 } finally {
6143 Binder.restoreCallingIdentity(identity);
6144 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006145 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006146
6147 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006148 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006149 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6150 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006151 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6152 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006153
6154 final long identity = Binder.clearCallingIdentity();
6155 try {
6156 final Phone phone = getPhone(subId);
6157 if (phone == null) {
6158 return false;
6159 }
6160 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6161 cdmaNonRoamingList);
6162 } finally {
6163 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006164 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006165 }
6166
6167 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006168 @Deprecated
6169 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6170 enforceModifyPermission();
6171
6172 int returnValue = 0;
6173 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006174 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006175 if(result.exception == null) {
6176 if (result.result != null) {
6177 byte[] responseData = (byte[])(result.result);
6178 if(responseData.length > oemResp.length) {
6179 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6180 responseData.length + "bytes. Buffer Size is " +
6181 oemResp.length + "bytes.");
6182 }
6183 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6184 returnValue = responseData.length;
6185 }
6186 } else {
6187 CommandException ex = (CommandException) result.exception;
6188 returnValue = ex.getCommandError().ordinal();
6189 if(returnValue > 0) returnValue *= -1;
6190 }
6191 } catch (RuntimeException e) {
6192 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6193 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6194 if(returnValue > 0) returnValue *= -1;
6195 }
6196
6197 return returnValue;
6198 }
6199
6200 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006201 public void setRadioCapability(RadioAccessFamily[] rafs) {
6202 try {
6203 ProxyController.getInstance().setRadioCapability(rafs);
6204 } catch (RuntimeException e) {
6205 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6206 }
6207 }
6208
6209 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006210 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006211 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006212 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006213 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006214 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006215 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006216 final long identity = Binder.clearCallingIdentity();
6217 try {
chen xub97461a2018-10-26 14:17:57 -07006218 TelephonyPermissions
6219 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6220 mApp, phone.getSubId(), "getRadioAccessFamily");
6221 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006222 } finally {
6223 Binder.restoreCallingIdentity(identity);
6224 }
chen xub97461a2018-10-26 14:17:57 -07006225 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006226 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006227
6228 @Override
6229 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006230 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006231 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232
6233 final long identity = Binder.clearCallingIdentity();
6234 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006235 ImsManager.getInstance(defaultPhone.getContext(),
6236 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006240 }
6241
6242 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006243 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006244 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006245 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6246 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006247 return false;
6248 }
Svet Ganovb320e182015-04-16 12:30:10 -07006249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250 final long identity = Binder.clearCallingIdentity();
6251 try {
6252 // Check the user preference and the system-level IMS setting. Even if the user has
6253 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6254 // In the long run, we may instead need to check if there exists a connection service
6255 // which can support video calling.
6256 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006257 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258 return imsManager.isVtEnabledByPlatform()
6259 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6260 && imsManager.isVtEnabledByUser();
6261 } finally {
6262 Binder.restoreCallingIdentity(identity);
6263 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006264 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006265
Andrew Leea1239f22015-03-02 17:44:07 -08006266 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006267 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6268 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006269 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006270 mApp, subId, callingPackage, callingFeatureId,
6271 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272 return false;
6273 }
6274
6275 final long identity = Binder.clearCallingIdentity();
6276 try {
6277 CarrierConfigManager configManager =
6278 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006279 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6281 } finally {
6282 Binder.restoreCallingIdentity(identity);
6283 }
Andrew Leea1239f22015-03-02 17:44:07 -08006284 }
6285
6286 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006287 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006289 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 return false;
6291 }
6292
6293 final long identity = Binder.clearCallingIdentity();
6294 try {
6295 CarrierConfigManager configManager =
6296 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006297 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6299 } finally {
6300 Binder.restoreCallingIdentity(identity);
6301 }
Andrew Leea1239f22015-03-02 17:44:07 -08006302 }
6303
Andrew Lee9431b832015-03-09 18:46:45 -07006304 @Override
6305 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006306 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006307 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006308 }
6309
6310 @Override
6311 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006312 final long identity = Binder.clearCallingIdentity();
6313 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006314 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 } finally {
6316 Binder.restoreCallingIdentity(identity);
6317 }
Andrew Lee9431b832015-03-09 18:46:45 -07006318 }
6319
Hall Liuf6668912018-10-31 17:05:23 -07006320 /**
6321 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6322 * support for the feature and device firmware support.
6323 *
6324 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6325 */
6326 @Override
6327 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006329 final Phone phone = getPhone(subscriptionId);
6330 if (phone == null) {
6331 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6332 return false;
6333 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006335 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006336 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6337 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006338 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006339 return isCarrierSupported && isDeviceSupported;
6340 } finally {
6341 Binder.restoreCallingIdentity(identity);
6342 }
Hall Liu98187582018-01-22 19:15:32 -08006343 }
6344
Hall Liuf6668912018-10-31 17:05:23 -07006345 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006346 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6347 * RTT setting, will return true if the device and carrier both support RTT.
6348 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006349 */
6350 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006351 final long identity = Binder.clearCallingIdentity();
6352 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006353 boolean isRttSupported = isRttSupported(subscriptionId);
6354 boolean isUserRttSettingOn = Settings.Secure.getInt(
6355 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6356 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6357 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6358 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006359 } finally {
6360 Binder.restoreCallingIdentity(identity);
6361 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006362 }
6363
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006364 @Deprecated
6365 @Override
6366 public String getDeviceId(String callingPackage) {
6367 return getDeviceIdWithFeature(callingPackage, null);
6368 }
6369
Sanket Padawe7310cc72015-01-14 09:53:20 -08006370 /**
6371 * Returns the unique device ID of phone, for example, the IMEI for
6372 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6373 *
6374 * <p>Requires Permission:
6375 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6376 */
6377 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006378 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006379 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006380 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006381 return null;
6382 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006383 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006384 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006385 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006386 return null;
6387 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388
6389 final long identity = Binder.clearCallingIdentity();
6390 try {
6391 return phone.getDeviceId();
6392 } finally {
6393 Binder.restoreCallingIdentity(identity);
6394 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006395 }
6396
Ping Sunc67b7c22016-03-02 19:16:45 +08006397 /**
6398 * {@hide}
6399 * Returns the IMS Registration Status on a particular subid
6400 *
6401 * @param subId
6402 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006403 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006404 Phone phone = getPhone(subId);
6405 if (phone != null) {
6406 return phone.isImsRegistered();
6407 } else {
6408 return false;
6409 }
6410 }
6411
Santos Cordon7a1885b2015-02-03 11:15:19 -08006412 @Override
6413 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 final long identity = Binder.clearCallingIdentity();
6415 try {
6416 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006420 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006421
Tyler Gunnf70ed162019-04-03 15:28:53 -07006422 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006423 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006424 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006425 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006426 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006427 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6428 }
6429 final long identity = Binder.clearCallingIdentity();
6430 try {
6431 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6432 } finally {
6433 Binder.restoreCallingIdentity(identity);
6434 }
6435 }
6436
6437 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006438 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6439 final long identity = Binder.clearCallingIdentity();
6440 try {
6441 Phone phone = getPhone(subscriptionId);
6442 if (phone == null) {
6443 return null;
6444 }
6445 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6446 } finally {
6447 Binder.restoreCallingIdentity(identity);
6448 }
6449 }
6450
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006451 /**
6452 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006453 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006454 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006455 final long identity = Binder.clearCallingIdentity();
6456 try {
6457 Phone phone = getPhone(subId);
6458 if (phone != null) {
6459 return phone.isWifiCallingEnabled();
6460 } else {
6461 return false;
6462 }
6463 } finally {
6464 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006465 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006466 }
6467
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006468 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006469 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006470 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006471 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 final long identity = Binder.clearCallingIdentity();
6473 try {
6474 Phone phone = getPhone(subId);
6475 if (phone != null) {
6476 return phone.isVideoEnabled();
6477 } else {
6478 return false;
6479 }
6480 } finally {
6481 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006482 }
6483 }
6484
6485 /**
6486 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6487 * defined in {@link ImsRegistrationImplBase}.
6488 */
6489 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490 final long identity = Binder.clearCallingIdentity();
6491 try {
6492 Phone phone = getPhone(subId);
6493 if (phone != null) {
6494 return phone.getImsRegistrationTech();
6495 } else {
6496 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6497 }
6498 } finally {
6499 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006500 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006501 }
6502
Stuart Scott8eef64f2015-04-08 15:13:54 -07006503 @Override
6504 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006505 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006506 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6507 return;
6508 }
6509
Svet Ganovcc087f82015-05-12 20:35:54 -07006510 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006511
Svet Ganovcc087f82015-05-12 20:35:54 -07006512 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006513 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6514 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006515 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006516 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006517 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006518 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6519 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006520 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006521 // There has been issues when Sms raw table somehow stores orphan
6522 // fragments. They lead to garbled message when new fragments come
6523 // in and combined with those stale ones. In case this happens again,
6524 // user can reset all network settings which will clean up this table.
6525 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006526 // Clean up IMS settings as well here.
6527 int slotId = getSlotIndex(subId);
6528 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6529 ImsManager.getInstance(mApp, slotId).factoryReset();
6530 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006531
6532 // Erase modem config if erase modem on network setting is enabled.
6533 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6534 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6535 if (configValue != null && Boolean.parseBoolean(configValue)) {
6536 sendEraseModemConfig(getDefaultPhone());
6537 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006538 } finally {
6539 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006540 }
6541 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006542
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006543 private void cleanUpSmsRawTable(Context context) {
6544 ContentResolver resolver = context.getContentResolver();
6545 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6546 resolver.delete(uri, null, null);
6547 }
6548
Narayan Kamath1c496c22015-04-16 14:40:19 +01006549 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006550 public String getSimLocaleForSubscriber(int subId) {
6551 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6552 final Phone phone = getPhone(subId);
6553 if (phone == null) {
6554 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006555 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006556 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557 final long identity = Binder.clearCallingIdentity();
6558 try {
chen xu5d3637b2019-01-21 23:31:38 -08006559 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006560 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006561 if (info == null) {
6562 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6563 return null;
6564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565 // Try and fetch the locale from the carrier properties or from the SIM language
6566 // preferences (EF-PL and EF-LI)...
6567 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006569 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6570 if (localeFromDefaultSim != null) {
6571 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6572 if (DBG) log("Using locale from subId: " + subId + " locale: "
6573 + localeFromDefaultSim);
6574 return localeFromDefaultSim.toLanguageTag();
6575 } else {
6576 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006577 }
6578 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580 // The SIM language preferences only store a language (e.g. fr = French), not an
6581 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6582 // the SIM and carrier preferences does not include a country we add the country
6583 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006584 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006585 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006586 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006587 return mccLocale.toLanguageTag();
6588 }
6589
6590 if (DBG) log("No locale found - returning null");
6591 return null;
6592 } finally {
6593 Binder.restoreCallingIdentity(identity);
6594 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006595 }
6596
6597 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006598 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6599 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006600 }
6601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 /**
6603 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6604 */
6605 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006606 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6607 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006608 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006609
Chenjie Yu1ba97252018-01-11 18:16:20 -08006610 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006611 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006612
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006613 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006614 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6615 * representing the state of the modem.
6616 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006617 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6618 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006619 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006620 */
6621 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006622 public void requestModemActivityInfo(ResultReceiver result) {
6623 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006624 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006625
6626 final long identity = Binder.clearCallingIdentity();
6627 try {
sqian1a1be542020-03-05 11:37:28 -08006628 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629 } finally {
6630 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006631 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006632 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006633
Siddharth Rayb8114062018-06-17 15:02:38 -07006634 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6635 // less than total activity duration.
6636 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6637 if (info == null) {
6638 return false;
6639 }
6640 int activityDurationMs =
6641 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6642 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006643 int[] txTimeMs = info.getTransmitTimeMillis();
6644 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6645 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006646 }
6647 return (info.isValid()
6648 && (info.getSleepTimeMillis() <= activityDurationMs)
6649 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006650 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006651 && (totalTxTimeMs <= activityDurationMs));
6652 }
6653
Jack Yu85bd38a2015-11-09 11:34:32 -08006654 /**
6655 * {@hide}
6656 * Returns the service state information on specified subscription.
6657 */
6658 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006659 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6660 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006661 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006662 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006663 return null;
6664 }
6665
Hall Liuf19c44f2018-11-27 14:38:17 -08006666 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6667 LocationAccessPolicy.checkLocationPermission(mApp,
6668 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6669 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006670 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006671 .setCallingPid(Binder.getCallingPid())
6672 .setCallingUid(Binder.getCallingUid())
6673 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006674 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006675 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6676 .build());
6677
6678 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6679 LocationAccessPolicy.checkLocationPermission(mApp,
6680 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6681 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006682 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006683 .setCallingPid(Binder.getCallingPid())
6684 .setCallingUid(Binder.getCallingUid())
6685 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006686 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006687 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6688 .build());
6689 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6690 boolean hasFinePermission =
6691 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6692 boolean hasCoarsePermission =
6693 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006695 final long identity = Binder.clearCallingIdentity();
6696 try {
6697 final Phone phone = getPhone(subId);
6698 if (phone == null) {
6699 return null;
6700 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006701
Hall Liuf19c44f2018-11-27 14:38:17 -08006702 ServiceState ss = phone.getServiceState();
6703
6704 // Scrub out the location info in ServiceState depending on what level of access
6705 // the caller has.
6706 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006707 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6708 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006709 } finally {
6710 Binder.restoreCallingIdentity(identity);
6711 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006712 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006713
6714 /**
6715 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6716 *
6717 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6718 * voicemail ringtone.
6719 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6720 * PhoneAccount.
6721 */
6722 @Override
6723 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724 final long identity = Binder.clearCallingIdentity();
6725 try {
6726 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6727 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006728 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006729 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006731 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6732 } finally {
6733 Binder.restoreCallingIdentity(identity);
6734 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006735 }
6736
6737 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006738 * Sets the per-account voicemail ringtone.
6739 *
6740 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6741 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6742 *
6743 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6744 * voicemail ringtone.
6745 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6746 * PhoneAccount.
6747 */
6748 @Override
6749 public void setVoicemailRingtoneUri(String callingPackage,
6750 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006751 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006752 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006753 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6754 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6756 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6757 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006758 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759
6760 final long identity = Binder.clearCallingIdentity();
6761 try {
6762 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6763 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006764 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006765 }
6766 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6767 } finally {
6768 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006769 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006770 }
6771
6772 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006773 * Returns whether vibration is set for voicemail notification in Phone settings.
6774 *
6775 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6776 * voicemail vibration setting.
6777 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6778 */
6779 @Override
6780 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 final long identity = Binder.clearCallingIdentity();
6782 try {
6783 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6784 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006785 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006786 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6789 } finally {
6790 Binder.restoreCallingIdentity(identity);
6791 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006792 }
6793
Youhan Wange64578a2016-05-02 15:32:42 -07006794 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006795 * Sets the per-account voicemail vibration.
6796 *
6797 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6798 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6799 *
6800 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6801 * voicemail vibration setting.
6802 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6803 * specific PhoneAccount.
6804 */
6805 @Override
6806 public void setVoicemailVibrationEnabled(String callingPackage,
6807 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006808 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006809 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006810 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6811 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6813 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6814 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006815 }
6816
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006817 final long identity = Binder.clearCallingIdentity();
6818 try {
6819 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6820 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006821 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006822 }
6823 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6824 } finally {
6825 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006826 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006827 }
6828
6829 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006830 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6831 *
6832 * @throws SecurityException if the caller does not have the required permission
6833 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006834 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006835 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006836 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006837 }
6838
6839 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006840 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6841 * permission.
6842 *
6843 * @throws SecurityException if the caller does not have the required permission
6844 */
6845 private void enforceSendSmsPermission() {
6846 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6847 }
6848
6849 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006850 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006851 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006852 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006853 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006854 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006855 final long identity = Binder.clearCallingIdentity();
6856 try {
6857 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006858 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006859 if (componentName == null) {
6860 throw new SecurityException(
6861 "Caller not current active visual voicemail package[null]");
6862 }
6863 String vvmPackage = componentName.getPackageName();
6864 if (!callingPackage.equals(vvmPackage)) {
6865 throw new SecurityException("Caller not current active visual voicemail package["
6866 + vvmPackage + "]");
6867 }
6868 } finally {
6869 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006870 }
6871 }
6872
6873 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006874 * Return the application ID for the app type.
6875 *
6876 * @param subId the subscription ID that this request applies to.
6877 * @param appType the uicc app type.
6878 * @return Application ID for specificied app type, or null if no uicc.
6879 */
6880 @Override
6881 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006882 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006883 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006884
6885 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006886 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006887 if (phone == null) {
6888 return null;
6889 }
6890 String aid = null;
6891 try {
6892 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6893 .getApplicationByType(appType).getAid();
6894 } catch (Exception e) {
6895 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6896 }
6897 return aid;
6898 } finally {
6899 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006900 }
Youhan Wange64578a2016-05-02 15:32:42 -07006901 }
6902
Youhan Wang4001d252016-05-11 10:29:41 -07006903 /**
6904 * Return the Electronic Serial Number.
6905 *
6906 * @param subId the subscription ID that this request applies to.
6907 * @return ESN or null if error.
6908 */
6909 @Override
6910 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006911 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006912 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006913
6914 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006915 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006916 if (phone == null) {
6917 return null;
6918 }
6919 String esn = null;
6920 try {
6921 esn = phone.getEsn();
6922 } catch (Exception e) {
6923 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6924 }
6925 return esn;
6926 } finally {
6927 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006928 }
Youhan Wang4001d252016-05-11 10:29:41 -07006929 }
6930
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006931 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006932 * Return the Preferred Roaming List Version.
6933 *
6934 * @param subId the subscription ID that this request applies to.
6935 * @return PRLVersion or null if error.
6936 */
6937 @Override
6938 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006939 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006940 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006941
6942 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006943 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006944 if (phone == null) {
6945 return null;
6946 }
6947 String cdmaPrlVersion = null;
6948 try {
6949 cdmaPrlVersion = phone.getCdmaPrlVersion();
6950 } catch (Exception e) {
6951 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6952 }
6953 return cdmaPrlVersion;
6954 } finally {
6955 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006956 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006957 }
6958
6959 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006960 * Get snapshot of Telephony histograms
6961 * @return List of Telephony histograms
6962 * @hide
6963 */
6964 @Override
6965 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6967 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968
6969 final long identity = Binder.clearCallingIdentity();
6970 try {
6971 return RIL.getTelephonyRILTimingHistograms();
6972 } finally {
6973 Binder.restoreCallingIdentity(identity);
6974 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006975 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006976
6977 /**
6978 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006979 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6980 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006981 * Require system privileges. In the future we may add this to carrier APIs.
6982 *
Michele Berionne482f8202018-11-27 18:57:59 -08006983 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006984 */
6985 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006986 @TelephonyManager.SetCarrierRestrictionResult
6987 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006988 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006989 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006990
Michele Berionne482f8202018-11-27 18:57:59 -08006991 if (carrierRestrictionRules == null) {
6992 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006993 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995 final long identity = Binder.clearCallingIdentity();
6996 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006997 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006998 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006999 } finally {
7000 Binder.restoreCallingIdentity(identity);
7001 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007002 }
7003
7004 /**
7005 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007006 * Get the allowed carrier list and the excluded carrier list, including the priority between
7007 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007008 * Require system privileges. In the future we may add this to carrier APIs.
7009 *
Michele Berionne482f8202018-11-27 18:57:59 -08007010 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007011 */
7012 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007013 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007014 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007015 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007016
7017 final long identity = Binder.clearCallingIdentity();
7018 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007019 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7020 if (response instanceof CarrierRestrictionRules) {
7021 return (CarrierRestrictionRules) response;
7022 }
7023 // Response is an Exception of some kind,
7024 // which is signalled to the user as a NULL retval
7025 return null;
7026 } catch (Exception e) {
7027 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7028 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 } finally {
7030 Binder.restoreCallingIdentity(identity);
7031 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007032 }
7033
fionaxu59545b42016-05-25 15:53:37 -07007034 /**
7035 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7036 * @param subId the subscription ID that this action applies to.
7037 * @param enabled control enable or disable metered apns.
7038 * {@hide}
7039 */
7040 @Override
7041 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7042 enforceModifyPermission();
7043 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044
7045 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007046 if (phone == null) {
7047 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7048 return;
7049 }
7050 try {
7051 phone.carrierActionSetMeteredApnsEnabled(enabled);
7052 } catch (Exception e) {
7053 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007054 } finally {
7055 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007056 }
7057 }
7058
7059 /**
7060 * Action set from carrier signalling broadcast receivers to enable/disable radio
7061 * @param subId the subscription ID that this action applies to.
7062 * @param enabled control enable or disable radio.
7063 * {@hide}
7064 */
7065 @Override
7066 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7067 enforceModifyPermission();
7068 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007069
7070 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007071 if (phone == null) {
7072 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7073 return;
7074 }
7075 try {
7076 phone.carrierActionSetRadioEnabled(enabled);
7077 } catch (Exception e) {
7078 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 } finally {
7080 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007081 }
7082 }
7083
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007084 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007085 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7086 * network status based on which carrier apps could apply actions accordingly,
7087 * enable/disable default url handler for example.
7088 *
7089 * @param subId the subscription ID that this action applies to.
7090 * @param report control start/stop reporting the default network status.
7091 * {@hide}
7092 */
7093 @Override
7094 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7095 enforceModifyPermission();
7096 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097
7098 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007099 if (phone == null) {
7100 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7101 return;
7102 }
7103 try {
7104 phone.carrierActionReportDefaultNetworkStatus(report);
7105 } catch (Exception e) {
7106 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107 } finally {
7108 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007109 }
7110 }
7111
7112 /**
fionaxud9622282017-07-17 17:51:30 -07007113 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7114 * @param subId the subscription ID that this action applies to.
7115 * {@hide}
7116 */
7117 @Override
7118 public void carrierActionResetAll(int subId) {
7119 enforceModifyPermission();
7120 final Phone phone = getPhone(subId);
7121 if (phone == null) {
7122 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7123 return;
7124 }
7125 try {
7126 phone.carrierActionResetAll();
7127 } catch (Exception e) {
7128 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7129 }
7130 }
7131
7132 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007133 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7134 * bug report is being generated.
7135 */
7136 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007137 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007138 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7139 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007140 writer.println("Permission Denial: can't dump Phone from pid="
7141 + Binder.getCallingPid()
7142 + ", uid=" + Binder.getCallingUid()
7143 + "without permission "
7144 + android.Manifest.permission.DUMP);
7145 return;
7146 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007147 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007148 }
Jack Yueb89b242016-06-22 13:27:47 -07007149
Brad Ebingerdac2f002018-04-03 15:17:52 -07007150 @Override
7151 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7152 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7153 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007154 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7155 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007156 }
7157
Jack Yueb89b242016-06-22 13:27:47 -07007158 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007159 * Policy control of data connection. Usually used when data limit is passed.
7160 * @param enabled True if enabling the data, otherwise disabling.
7161 * @param subId Subscription index
7162 * {@hide}
7163 */
7164 @Override
7165 public void setPolicyDataEnabled(boolean enabled, int subId) {
7166 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007167
7168 final long identity = Binder.clearCallingIdentity();
7169 try {
7170 Phone phone = getPhone(subId);
7171 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007172 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173 }
7174 } finally {
7175 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007176 }
7177 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007178
7179 /**
7180 * Get Client request stats
7181 * @return List of Client Request Stats
7182 * @hide
7183 */
7184 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007185 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7186 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007187 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007188 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007189 return null;
7190 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007191 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007193 final long identity = Binder.clearCallingIdentity();
7194 try {
7195 if (phone != null) {
7196 return phone.getClientRequestStats();
7197 }
7198
7199 return null;
7200 } finally {
7201 Binder.restoreCallingIdentity(identity);
7202 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007203 }
7204
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007205 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007206 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007207 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007208 }
Jack Yueb4124c2017-02-16 15:32:43 -08007209
7210 /**
Grace Chen70990072017-03-24 17:21:30 -07007211 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007212 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007213 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007214 * @param state State of SIM (power down, power up, pass through)
7215 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7216 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7217 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007218 *
7219 **/
7220 @Override
Grace Chen70990072017-03-24 17:21:30 -07007221 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007222 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007223 Phone phone = PhoneFactory.getPhone(slotIndex);
7224
vagdeviaf9a5b92018-08-15 16:01:53 -07007225 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 final long identity = Binder.clearCallingIdentity();
7228 try {
7229 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007230 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007231 }
7232 } finally {
7233 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007234 }
7235 }
Shuo Qiandd210312017-04-12 22:11:33 +00007236
Tyler Gunn65d45c22017-06-05 11:22:26 -07007237 private boolean isUssdApiAllowed(int subId) {
7238 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007239 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007240 if (configManager == null) {
7241 return false;
7242 }
7243 PersistableBundle pb = configManager.getConfigForSubId(subId);
7244 if (pb == null) {
7245 return false;
7246 }
7247 return pb.getBoolean(
7248 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7249 }
7250
Shuo Qiandd210312017-04-12 22:11:33 +00007251 /**
7252 * Check if phone is in emergency callback mode
7253 * @return true if phone is in emergency callback mode
7254 * @param subId sub id
7255 */
goneil9c5f4872017-12-05 14:07:56 -08007256 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007257 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007258 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007259 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260
7261 final long identity = Binder.clearCallingIdentity();
7262 try {
7263 if (phone != null) {
7264 return phone.isInEcm();
7265 } else {
7266 return false;
7267 }
7268 } finally {
7269 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007270 }
7271 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007272
7273 /**
7274 * Get the current signal strength information for the given subscription.
7275 * Because this information is not updated when the device is in a low power state
7276 * it should not be relied-upon to be current.
7277 * @param subId Subscription index
7278 * @return the most recent cached signal strength info from the modem
7279 */
7280 @Override
7281 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282 final long identity = Binder.clearCallingIdentity();
7283 try {
7284 Phone p = getPhone(subId);
7285 if (p == null) {
7286 return null;
7287 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007289 return p.getSignalStrength();
7290 } finally {
7291 Binder.restoreCallingIdentity(identity);
7292 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007293 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007294
Pengquan Meng77b7f132018-08-22 14:49:57 -07007295 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007296 * Get the current modem radio state for the given slot.
7297 * @param slotIndex slot index.
7298 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007299 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007300 * @return the current radio power state from the modem
7301 */
7302 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007303 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007304 Phone phone = PhoneFactory.getPhone(slotIndex);
7305 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7307 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007308 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7309 }
7310
7311 final long identity = Binder.clearCallingIdentity();
7312 try {
7313 return phone.getRadioPowerState();
7314 } finally {
7315 Binder.restoreCallingIdentity(identity);
7316 }
7317 }
7318 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7319 }
7320
7321 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007322 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7323 *
7324 * <p>Requires one of the following permissions:
7325 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7326 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7327 * privileges.
7328 *
7329 * @param subId subscription id
7330 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7331 * {@code false}.
7332 */
7333 @Override
7334 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007335 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7336 null /* message */);
7337
Pengquan Menga1bb6272018-09-06 09:59:22 -07007338 boolean isEnabled = false;
7339 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007340 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007341 Phone phone = getPhone(subId);
7342 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007343 } catch (Exception e) {
7344 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7345 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007346 } finally {
7347 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007348 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007349 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007350 }
7351
7352
7353 /**
7354 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7355 *
7356 * <p> Requires permission:
7357 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7358 * privileges.
7359 *
7360 * @param subId subscription id
7361 * @param isEnabled {@code true} means enable, {@code false} means disable.
7362 */
7363 @Override
7364 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7366 mApp, subId, "setDataRoamingEnabled");
7367
Pengquan Menga1bb6272018-09-06 09:59:22 -07007368 final long identity = Binder.clearCallingIdentity();
7369 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007370 Phone phone = getPhone(subId);
7371 if (phone != null) {
7372 phone.setDataRoamingEnabled(isEnabled);
7373 }
7374 } finally {
7375 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007376 }
7377 }
7378
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007379 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007380 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007381 TelephonyPermissions
7382 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007383 mApp, subId, "isManualNetworkSelectionAllowed");
7384
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007385 boolean isAllowed = true;
7386 final long identity = Binder.clearCallingIdentity();
7387 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007388 Phone phone = getPhone(subId);
7389 if (phone != null) {
7390 isAllowed = phone.isCspPlmnEnabled();
7391 }
7392 } finally {
7393 Binder.restoreCallingIdentity(identity);
7394 }
7395 return isAllowed;
7396 }
7397
7398 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007399 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007400 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007401 try {
7402 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007403 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007404 } catch (SecurityException e) {
7405 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7406 // has carrier privileges on an active UICC
7407 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7408 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007409 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007410 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007411 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007412
7413 final long identity = Binder.clearCallingIdentity();
7414 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007415 UiccController uiccController = UiccController.getInstance();
7416 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007417 if (hasReadPermission) {
7418 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007419 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007420
7421 // Remove private info if the caller doesn't have access
7422 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7423 for (UiccCardInfo cardInfo : cardInfos) {
7424 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7425 // is available
7426 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7427 if (card == null || card.getUiccProfile() == null) {
7428 // assume no access if the card or profile is unavailable
7429 filteredInfos.add(cardInfo.getUnprivileged());
7430 continue;
7431 }
7432 UiccProfile profile = card.getUiccProfile();
7433 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7434 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7435 filteredInfos.add(cardInfo);
7436 } else {
7437 filteredInfos.add(cardInfo.getUnprivileged());
7438 }
7439 }
7440 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007441 } finally {
7442 Binder.restoreCallingIdentity(identity);
7443 }
7444 }
7445
7446 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007447 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007448 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007450 final long identity = Binder.clearCallingIdentity();
7451 try {
7452 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7453 if (slots == null) {
7454 Rlog.i(LOG_TAG, "slots is null.");
7455 return null;
7456 }
7457
7458 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7459 for (int i = 0; i < slots.length; i++) {
7460 UiccSlot slot = slots[i];
7461 if (slot == null) {
7462 continue;
7463 }
7464
Jordan Liu7be7e652019-05-06 18:55:02 +00007465 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 UiccCard card = slot.getUiccCard();
7467 if (card != null) {
7468 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007469 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007470 cardId = slot.getEid();
7471 if (TextUtils.isEmpty(cardId)) {
7472 cardId = slot.getIccId();
7473 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474 }
7475
Jordan Liu857451f2019-05-09 16:35:35 -07007476 if (cardId != null) {
7477 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7478 // if cardId is an EID, it's all digits so this is fine
7479 cardId = IccUtils.stripTrailingFs(cardId);
7480 }
7481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 int cardState = 0;
7483 switch (slot.getCardState()) {
7484 case CARDSTATE_ABSENT:
7485 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7486 break;
7487 case CARDSTATE_PRESENT:
7488 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7489 break;
7490 case CARDSTATE_ERROR:
7491 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7492 break;
7493 case CARDSTATE_RESTRICTED:
7494 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7495 break;
7496 default:
7497 break;
7498
7499 }
7500
7501 infos[i] = new UiccSlotInfo(
7502 slot.isActive(),
7503 slot.isEuicc(),
7504 cardId,
7505 cardState,
7506 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007507 slot.isExtendedApduSupported(),
7508 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 }
7510 return infos;
7511 } finally {
7512 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007513 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007514 }
7515
7516 @Override
7517 public boolean switchSlots(int[] physicalSlots) {
7518 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007519
7520 final long identity = Binder.clearCallingIdentity();
7521 try {
7522 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7523 } finally {
7524 Binder.restoreCallingIdentity(identity);
7525 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007526 }
Jack Yu4c988042018-02-27 15:30:01 -08007527
7528 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007529 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007530 final long identity = Binder.clearCallingIdentity();
7531 try {
7532 return UiccController.getInstance().getCardIdForDefaultEuicc();
7533 } finally {
7534 Binder.restoreCallingIdentity(identity);
7535 }
7536 }
7537
Pengquan Meng85728fb2018-03-12 16:31:21 -07007538 /**
goneil47ffb6e2018-04-06 15:40:58 -07007539 * A test API to reload the UICC profile.
7540 *
7541 * <p>Requires that the calling app has permission
7542 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7543 * @hide
7544 */
7545 @Override
7546 public void refreshUiccProfile(int subId) {
7547 enforceModifyPermission();
7548
7549 final long identity = Binder.clearCallingIdentity();
7550 try {
7551 Phone phone = getPhone(subId);
7552 if (phone == null) {
7553 return;
7554 }
7555 UiccCard uiccCard = phone.getUiccCard();
7556 if (uiccCard == null) {
7557 return;
7558 }
7559 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7560 if (uiccProfile == null) {
7561 return;
7562 }
7563 uiccProfile.refresh();
7564 } finally {
7565 Binder.restoreCallingIdentity(identity);
7566 }
7567 }
7568
7569 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007570 * Returns false if the mobile data is disabled by default, otherwise return true.
7571 */
7572 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007573 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007574 }
7575
7576 /**
7577 * Returns true if the data roaming is enabled by default, i.e the system property
7578 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7579 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7580 */
7581 private boolean getDefaultDataRoamingEnabled(int subId) {
7582 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007583 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007584 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007585 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7586 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7587 return isDataRoamingEnabled;
7588 }
7589
7590 /**
7591 * Returns the default network type for the given {@code subId}, if the default network type is
7592 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7593 */
7594 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007595 List<Integer> list = TelephonyProperties.default_network();
7596 int phoneId = mSubscriptionController.getPhoneId(subId);
7597 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7598 return list.get(phoneId);
7599 }
7600 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007601 }
fionaxua13278b2018-03-21 00:08:13 -07007602
7603 @Override
7604 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007605 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007606 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007607
7608 final long identity = Binder.clearCallingIdentity();
7609 try {
7610 final Phone phone = getPhone(subId);
7611 if (phone == null) {
7612 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7613 return;
7614 }
chen xueaba88a2019-03-15 13:15:10 -07007615 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7616 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007617 } finally {
7618 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007619 }
fionaxua13278b2018-03-21 00:08:13 -07007620 }
7621
7622 @Override
7623 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007624 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007625
7626 final long identity = Binder.clearCallingIdentity();
7627 try {
7628 final Phone phone = getPhone(subId);
7629 if (phone == null) {
7630 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7631 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7632 }
7633 return phone.getCarrierIdListVersion();
7634 } finally {
7635 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007636 }
fionaxua13278b2018-03-21 00:08:13 -07007637 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007638
7639 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007640 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7641 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007642 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007643 mApp, subId, callingPackage, callingFeatureId,
7644 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007645 return -1;
7646 }
7647
7648 final long identity = Binder.clearCallingIdentity();
7649 try {
7650 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7651 } finally {
7652 Binder.restoreCallingIdentity(identity);
7653 }
7654 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007655
7656 @Override
7657 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007658 TelephonyPermissions
7659 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007660 mApp, subId, "getCdmaRoamingMode");
7661
7662 final long identity = Binder.clearCallingIdentity();
7663 try {
7664 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7665 } finally {
7666 Binder.restoreCallingIdentity(identity);
7667 }
7668 }
7669
7670 @Override
7671 public boolean setCdmaRoamingMode(int subId, int mode) {
7672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7673 mApp, subId, "setCdmaRoamingMode");
7674
7675 final long identity = Binder.clearCallingIdentity();
7676 try {
7677 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7678 } finally {
7679 Binder.restoreCallingIdentity(identity);
7680 }
7681 }
7682
7683 @Override
7684 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7686 mApp, subId, "setCdmaSubscriptionMode");
7687
7688 final long identity = Binder.clearCallingIdentity();
7689 try {
7690 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7691 } finally {
7692 Binder.restoreCallingIdentity(identity);
7693 }
7694 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007695
sqianc5eccab2018-10-19 18:46:41 -07007696 @Override
sqian8c685422019-02-22 15:55:18 -08007697 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007698 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007700 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7701 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007702 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7703 }
7704 final long identity = Binder.clearCallingIdentity();
7705 try {
sqian854d44b2018-12-12 16:48:18 -08007706 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7707 for (Phone phone: PhoneFactory.getPhones()) {
7708 if (phone.getEmergencyNumberTracker() != null
7709 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7710 emergencyNumberListInternal.put(
7711 phone.getSubId(),
7712 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7713 }
sqian11b7a0e2018-12-05 18:48:28 -08007714 }
sqian854d44b2018-12-12 16:48:18 -08007715 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007716 } finally {
7717 Binder.restoreCallingIdentity(identity);
7718 }
sqianc5eccab2018-10-19 18:46:41 -07007719 }
7720
7721 @Override
sqian8c685422019-02-22 15:55:18 -08007722 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007723 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007724 if (!exactMatch) {
7725 TelephonyPermissions
7726 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007727 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007728 }
7729 final long identity = Binder.clearCallingIdentity();
7730 try {
sqian854d44b2018-12-12 16:48:18 -08007731 for (Phone phone: PhoneFactory.getPhones()) {
7732 if (phone.getEmergencyNumberTracker() != null
7733 && phone.getEmergencyNumberTracker() != null) {
7734 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7735 number, exactMatch)) {
7736 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007737 }
7738 }
sqian11b7a0e2018-12-05 18:48:28 -08007739 }
7740 return false;
7741 } finally {
7742 Binder.restoreCallingIdentity(identity);
7743 }
7744 }
7745
sqianf4ca7ed2019-01-15 18:32:07 -08007746 /**
7747 * Update emergency number list for test mode.
7748 */
7749 @Override
7750 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7751 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7752 "updateEmergencyNumberListTestMode");
7753
7754 final long identity = Binder.clearCallingIdentity();
7755 try {
7756 for (Phone phone: PhoneFactory.getPhones()) {
7757 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7758 if (tracker != null) {
7759 tracker.executeEmergencyNumberTestModeCommand(action, num);
7760 }
7761 }
7762 } finally {
7763 Binder.restoreCallingIdentity(identity);
7764 }
7765 }
7766
7767 /**
7768 * Get the full emergency number list for test mode.
7769 */
7770 @Override
7771 public List<String> getEmergencyNumberListTestMode() {
7772 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7773 "getEmergencyNumberListTestMode");
7774
7775 final long identity = Binder.clearCallingIdentity();
7776 try {
7777 Set<String> emergencyNumbers = new HashSet<>();
7778 for (Phone phone: PhoneFactory.getPhones()) {
7779 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7780 if (tracker != null) {
7781 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7782 emergencyNumbers.add(num.getNumber());
7783 }
7784 }
7785 }
7786 return new ArrayList<>(emergencyNumbers);
7787 } finally {
7788 Binder.restoreCallingIdentity(identity);
7789 }
7790 }
7791
chen xud6b45bd2018-10-30 22:27:10 -07007792 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007793 public int getEmergencyNumberDbVersion(int subId) {
7794 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7795
7796 final long identity = Binder.clearCallingIdentity();
7797 try {
7798 final Phone phone = getPhone(subId);
7799 if (phone == null) {
7800 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7801 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7802 }
7803 return phone.getEmergencyNumberDbVersion();
7804 } finally {
7805 Binder.restoreCallingIdentity(identity);
7806 }
7807 }
7808
7809 @Override
7810 public void notifyOtaEmergencyNumberDbInstalled() {
7811 enforceModifyPermission();
7812
7813 final long identity = Binder.clearCallingIdentity();
7814 try {
7815 for (Phone phone: PhoneFactory.getPhones()) {
7816 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7817 if (tracker != null) {
7818 tracker.updateOtaEmergencyNumberDatabase();
7819 }
7820 }
7821 } finally {
7822 Binder.restoreCallingIdentity(identity);
7823 }
7824 }
7825
7826 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08007827 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08007828 enforceActiveEmergencySessionPermission();
7829
7830 final long identity = Binder.clearCallingIdentity();
7831 try {
7832 for (Phone phone: PhoneFactory.getPhones()) {
7833 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7834 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08007835 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7836 }
7837 }
7838 } finally {
7839 Binder.restoreCallingIdentity(identity);
7840 }
7841 }
7842
7843 @Override
7844 public void resetOtaEmergencyNumberDbFilePath() {
7845 enforceActiveEmergencySessionPermission();
7846
7847 final long identity = Binder.clearCallingIdentity();
7848 try {
7849 for (Phone phone: PhoneFactory.getPhones()) {
7850 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7851 if (tracker != null) {
7852 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08007853 }
7854 }
7855 } finally {
7856 Binder.restoreCallingIdentity(identity);
7857 }
7858 }
7859
7860 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007861 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7862 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7863 Phone phone = getPhone(subId);
7864 if (phone == null) {
7865 return null;
7866 }
7867 final long identity = Binder.clearCallingIdentity();
7868 try {
7869 UiccProfile profile = UiccController.getInstance()
7870 .getUiccProfileForPhone(phone.getPhoneId());
7871 if (profile != null) {
7872 return profile.getCertsFromCarrierPrivilegeAccessRules();
7873 }
7874 } finally {
7875 Binder.restoreCallingIdentity(identity);
7876 }
7877 return null;
7878 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007879
7880 /**
7881 * Enable or disable a modem stack.
7882 */
7883 @Override
7884 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7885 enforceModifyPermission();
7886
7887 final long identity = Binder.clearCallingIdentity();
7888 try {
7889 Phone phone = PhoneFactory.getPhone(slotIndex);
7890 if (phone == null) {
7891 return false;
7892 } else {
7893 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7894 }
7895 } finally {
7896 Binder.restoreCallingIdentity(identity);
7897 }
7898 }
Michelecea4cf22018-12-21 15:00:11 -08007899
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007900 /**
7901 * Whether a modem stack is enabled or not.
7902 */
7903 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007904 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7905 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007906 Phone phone = PhoneFactory.getPhone(slotIndex);
7907 if (phone == null) return false;
7908
7909 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007910 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7911 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007912 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7913 }
7914
7915 final long identity = Binder.clearCallingIdentity();
7916 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007917 try {
7918 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7919 } catch (NoSuchElementException ex) {
7920 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7921 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007922 } finally {
7923 Binder.restoreCallingIdentity(identity);
7924 }
7925 }
7926
Michelecea4cf22018-12-21 15:00:11 -08007927 @Override
Michele0ea7d782019-03-19 14:58:42 -07007928 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007929 enforceModifyPermission();
7930
7931 final long identity = Binder.clearCallingIdentity();
7932 try {
7933 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007934 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007935 .commit();
7936 } finally {
7937 Binder.restoreCallingIdentity(identity);
7938 }
7939 }
7940
7941 @Override
Michele0ea7d782019-03-19 14:58:42 -07007942 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007943 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007945 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7946 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007947 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007948 }
Michelecea4cf22018-12-21 15:00:11 -08007949
7950 final long identity = Binder.clearCallingIdentity();
7951 try {
Michele0ea7d782019-03-19 14:58:42 -07007952 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007953 } finally {
7954 Binder.restoreCallingIdentity(identity);
7955 }
7956 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007957
Michele0ea7d782019-03-19 14:58:42 -07007958 @TelephonyManager.IsMultiSimSupportedResult
7959 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007960 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7961 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7962 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007963 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7964 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007965 }
7966 // Check if the hardware supports multisim functionality. If usage of multisim is not
7967 // supported by the modem, indicate that it is restricted.
7968 PhoneCapability staticCapability =
7969 mPhoneConfigurationManager.getStaticPhoneCapability();
7970 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007971 loge("isMultiSimSupportedInternal: no static configuration available");
7972 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007973 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00007974 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007975 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7976 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007977 }
7978 // Check if support of multiple SIMs is restricted by carrier
7979 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007980 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007981 }
7982
Michele0ea7d782019-03-19 14:58:42 -07007983 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007984 }
7985
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007986 /**
7987 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007988 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7989 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7990 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007991 * @param numOfSims number of active sims we want to switch to
7992 */
7993 @Override
7994 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007995 if (numOfSims == 1) {
7996 enforceModifyPermission();
7997 } else {
7998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7999 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8000 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008001 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008002
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008003 try {
Michele30b57b22019-03-01 12:01:14 -08008004 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008005 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008006 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8007 return;
8008 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008009 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8010 } finally {
8011 Binder.restoreCallingIdentity(identity);
8012 }
8013 }
8014
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008015 @Override
8016 public boolean isApplicationOnUicc(int subId, int appType) {
8017 enforceReadPrivilegedPermission("isApplicationOnUicc");
8018 Phone phone = getPhone(subId);
8019 if (phone == null) {
8020 return false;
8021 }
8022 final long identity = Binder.clearCallingIdentity();
8023 try {
8024 UiccCard uiccCard = phone.getUiccCard();
8025 if (uiccCard == null) {
8026 return false;
8027 }
8028 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8029 if (uiccProfile == null) {
8030 return false;
8031 }
8032 if (TelephonyManager.APPTYPE_SIM <= appType
8033 && appType <= TelephonyManager.APPTYPE_ISIM) {
8034 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8035 }
8036 return false;
8037 } finally {
8038 Binder.restoreCallingIdentity(identity);
8039 }
8040 }
8041
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008042 /**
chen xub4baa772019-04-03 10:23:41 -07008043 * Get whether making changes to modem configurations will trigger reboot.
8044 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008045 */
8046 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008047 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8048 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008050 mApp, subId, callingPackage, callingFeatureId,
8051 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008052 return false;
8053 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008054 final long identity = Binder.clearCallingIdentity();
8055 try {
8056 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8057 } finally {
8058 Binder.restoreCallingIdentity(identity);
8059 }
8060 }
8061
Nathan Harold29f5f052019-02-15 13:41:57 -08008062 private void updateModemStateMetrics() {
8063 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8064 // TODO: check the state for each modem if the api is ready.
8065 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8066 }
8067
Pengquan Meng3889a572019-01-23 11:16:29 -08008068 @Override
8069 public int[] getSlotsMapping() {
8070 enforceReadPrivilegedPermission("getSlotsMapping");
8071
8072 final long identity = Binder.clearCallingIdentity();
8073 try {
8074 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8075 // All logical slots should have a mapping to a physical slot.
8076 int[] logicalSlotsMapping = new int[phoneCount];
8077 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8078 for (int i = 0; i < slotInfos.length; i++) {
8079 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8080 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8081 }
8082 }
8083 return logicalSlotsMapping;
8084 } finally {
8085 Binder.restoreCallingIdentity(identity);
8086 }
8087 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008088
8089 /**
8090 * Get the IRadio HAL Version
8091 */
8092 @Override
8093 public int getRadioHalVersion() {
8094 Phone phone = getDefaultPhone();
8095 if (phone == null) return -1;
8096 HalVersion hv = phone.getHalVersion();
8097 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8098 return hv.major * 100 + hv.minor;
8099 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008100
8101 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008102 * Get the current calling package name.
8103 * @return the current calling package name
8104 */
8105 @Override
8106 public String getCurrentPackageName() {
8107 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8108 }
8109
8110 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008111 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8112 * corresponding network requests on a subId.
8113 *
8114 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008115 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008116 * 2) APN is un-metered for this subscription, or
8117 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008118 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008119 *
8120 * @return whether data is allowed for a apn type.
8121 *
8122 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008123 */
8124 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008125 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008126 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8127 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008128
8129 // Now that all security checks passes, perform the operation as ourselves.
8130 final long identity = Binder.clearCallingIdentity();
8131 try {
8132 Phone phone = getPhone(subId);
8133 if (phone == null) return false;
8134
Jack Yu41407ee2019-05-13 16:54:09 -07008135 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008136 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8137 } finally {
8138 Binder.restoreCallingIdentity(identity);
8139 }
8140 }
8141
8142 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008143 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008144 enforceReadPrivilegedPermission("isApnMetered");
8145
8146 // Now that all security checks passes, perform the operation as ourselves.
8147 final long identity = Binder.clearCallingIdentity();
8148 try {
8149 Phone phone = getPhone(subId);
8150 if (phone == null) return true; // By default return true.
8151
Jack Yu41407ee2019-05-13 16:54:09 -07008152 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008153 } finally {
8154 Binder.restoreCallingIdentity(identity);
8155 }
8156 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008157
8158 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008159 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8160 int subscriptionId, IBooleanConsumer resultCallback) {
8161 enforceModifyPermission();
8162 long token = Binder.clearCallingIdentity();
8163 try {
8164 Phone phone = getPhone(subscriptionId);
8165 if (phone == null) {
8166 try {
8167 if (resultCallback != null) {
8168 resultCallback.accept(false);
8169 }
8170 } catch (RemoteException e) {
8171 // ignore
8172 }
8173 return;
8174 }
8175 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8176 Pair.create(specifiers, (x) -> {
8177 try {
8178 if (resultCallback != null) {
8179 resultCallback.accept(x);
8180 }
8181 } catch (RemoteException e) {
8182 // ignore
8183 }
8184 });
8185 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8186 } finally {
8187 Binder.restoreCallingIdentity(token);
8188 }
8189 }
8190
8191 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008192 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8193 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8194 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8195 if (iccRecords == null) {
8196 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8197 return false;
8198 }
8199 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8200 }
8201
8202 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008203 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008204 if (callingPackage == null) {
8205 callingPackage = getCurrentPackageName();
8206 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008207 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8208 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8209 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8210 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8211 }
8212 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8213 Intent intent = new Intent();
8214 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8215 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8216 // Bring up choose default SMS subscription dialog right now
8217 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8218 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8219 mApp.startActivity(intent);
8220 }
chen xud5ca2d52019-05-28 15:20:57 -07008221
8222 @Override
8223 public String getMmsUAProfUrl(int subId) {
8224 //TODO investigate if this API should require proper permission check in R b/133791609
8225 final long identity = Binder.clearCallingIdentity();
8226 try {
8227 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8228 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8229 } finally {
8230 Binder.restoreCallingIdentity(identity);
8231 }
8232 }
8233
8234 @Override
8235 public String getMmsUserAgent(int subId) {
8236 //TODO investigate if this API should require proper permission check in R b/133791609
8237 final long identity = Binder.clearCallingIdentity();
8238 try {
8239 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8240 .getString(com.android.internal.R.string.config_mms_user_agent);
8241 } finally {
8242 Binder.restoreCallingIdentity(identity);
8243 }
8244 }
Jack Yub07d4972019-05-28 16:12:25 -07008245
8246 @Override
8247 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8248 enforceModifyPermission();
8249
8250 // Now that all security checks passes, perform the operation as ourselves.
8251 final long identity = Binder.clearCallingIdentity();
8252 try {
8253 Phone phone = getPhone(subId);
8254 if (phone == null) return false;
8255
8256 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8257 } finally {
8258 Binder.restoreCallingIdentity(identity);
8259 }
8260 }
8261
8262 @Override
8263 public boolean isDataAllowedInVoiceCall(int subId) {
8264 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8265
8266 // Now that all security checks passes, perform the operation as ourselves.
8267 final long identity = Binder.clearCallingIdentity();
8268 try {
8269 Phone phone = getPhone(subId);
8270 if (phone == null) return false;
8271
8272 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8273 } finally {
8274 Binder.restoreCallingIdentity(identity);
8275 }
8276 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008277
changbetty97defcf2019-12-24 15:40:37 +08008278 @Override
8279 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8280 enforceModifyPermission();
8281
8282 // Now that all security checks passes, perform the operation as ourselves.
8283 final long identity = Binder.clearCallingIdentity();
8284 try {
8285 Phone phone = getPhone(subId);
8286 if (phone == null) return false;
8287
8288 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8289 } finally {
8290 Binder.restoreCallingIdentity(identity);
8291 }
8292 }
8293
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008294 /**
8295 * Updates whether conference event pacakge handling is enabled.
8296 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8297 * otherwise.
8298 */
8299 @Override
8300 public void setCepEnabled(boolean isCepEnabled) {
8301 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8302
8303 final long identity = Binder.clearCallingIdentity();
8304 try {
8305 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8306 for (Phone phone : PhoneFactory.getPhones()) {
8307 Phone defaultPhone = phone.getImsPhone();
8308 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8309 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8310 ImsPhoneCallTracker imsPhoneCallTracker =
8311 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8312 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8313 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8314 + imsPhone.getMsisdn());
8315 }
8316 }
8317 } finally {
8318 Binder.restoreCallingIdentity(identity);
8319 }
8320 }
allenwtsu46dcc572020-01-08 18:24:03 +08008321
8322 /**
8323 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8324 *
8325 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8326 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8327 * before being read.
8328 */
8329 @Override
8330 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8331 isCompressed) {
8332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8333 mApp, subId, "notifyRcsAutoConfigurationReceived");
8334 try {
8335 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8336 if (configBinder == null) {
8337 Rlog.e(LOG_TAG, "null result for getImsConfig");
8338 } else {
8339 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8340 }
8341 } catch (RemoteException e) {
8342 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8343 }
8344 }
zoey chenf95ca592019-12-30 16:11:23 +08008345
8346 @Override
8347 public boolean isIccLockEnabled(int subId) {
8348 enforceReadPrivilegedPermission("isIccLockEnabled");
8349
8350 // Now that all security checks passes, perform the operation as ourselves.
8351 final long identity = Binder.clearCallingIdentity();
8352 try {
8353 Phone phone = getPhone(subId);
8354 if (phone != null && phone.getIccCard() != null) {
8355 return phone.getIccCard().getIccLockEnabled();
8356 } else {
8357 return false;
8358 }
8359 } finally {
8360 Binder.restoreCallingIdentity(identity);
8361 }
8362 }
8363
8364 /**
8365 * Set the ICC pin lock enabled or disabled..
8366 *
8367 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8368 * 0 or a positive integer as the attempts remaining value.
8369 *
8370 */
8371 @Override
8372 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8373 enforceModifyPermission();
8374
8375 Phone phone = getPhone(subId);
8376 if (phone == null) {
8377 return 0;
8378 }
8379 // Now that all security checks passes, perform the operation as ourselves.
8380 final long identity = Binder.clearCallingIdentity();
8381 try {
8382 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8383 new Pair<Boolean, String>(enabled, password), phone, null);
8384 return attemptsRemaining;
8385
8386 } catch (Exception e) {
8387 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8388 } finally {
8389 Binder.restoreCallingIdentity(identity);
8390 }
8391 return 0;
8392 }
8393
8394 /**
8395 * Change the ICC password used in ICC pin lock.
8396 *
8397 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8398 * 0 or a positive integer as the attempts remaining value.
8399 *
8400 */
8401 @Override
8402 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8403 enforceModifyPermission();
8404
8405 Phone phone = getPhone(subId);
8406 if (phone == null) {
8407 return 0;
8408 }
8409 // Now that all security checks passes, perform the operation as ourselves.
8410 final long identity = Binder.clearCallingIdentity();
8411 try {
8412 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8413 new Pair<String, String>(oldPassword, newPassword), phone, null);
8414 return attemptsRemaining;
8415
8416 } catch (Exception e) {
8417 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8418 } finally {
8419 Binder.restoreCallingIdentity(identity);
8420 }
8421 return 0;
8422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008423}