blob: 623e41a66f568097a2c5f265d9e6a52163593c71 [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
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002288 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2289 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002290 if (!TextUtils.isEmpty(callingPackage)) {
2291 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2293 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002294 return "";
2295 }
2296 }
2297
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002298 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2299 // registered cell info, so return a NULL country instead.
2300 final long identity = Binder.clearCallingIdentity();
2301 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002302 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2303 // Get default phone in this case.
2304 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2305 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002306 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002307 // Todo: fix this when we can get the actual cellular network info when the device
2308 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002309 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002310 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2311 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002312 return "";
2313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002314 Phone phone = PhoneFactory.getPhone(phoneId);
2315 if (phone != null) {
2316 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002317 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002318 if (sst != null) {
2319 LocaleTracker lt = sst.getLocaleTracker();
2320 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002321 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2322 return lt.getCurrentCountry();
2323 } else if (emergencyNumberTracker != null) {
2324 return emergencyNumberTracker.getEmergencyCountryIso();
2325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326 }
2327 }
2328 }
2329 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002330 } finally {
2331 Binder.restoreCallingIdentity(identity);
2332 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002333 }
2334
2335 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002337 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002338 }
2339
Sanket Padawe356d7632015-06-22 14:03:32 -07002340 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002341 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 mApp.enforceCallingOrSelfPermission(
2343 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344
2345 final long identity = Binder.clearCallingIdentity();
2346 try {
2347 final Phone phone = getPhone(subId);
2348 if (phone != null) {
2349 phone.enableLocationUpdates();
2350 }
2351 } finally {
2352 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 }
2355
2356 @Override
2357 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002358 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002359 }
2360
Sanket Padawe356d7632015-06-22 14:03:32 -07002361 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002362 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 mApp.enforceCallingOrSelfPermission(
2364 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002365
2366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 final Phone phone = getPhone(subId);
2369 if (phone != null) {
2370 phone.disableLocationUpdates();
2371 }
2372 } finally {
2373 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 }
2376
Nathan Harold31d7ff32018-10-15 20:20:30 -07002377 /**
2378 * Returns the target SDK version number for a given package name.
2379 *
Nathan Haroldec184742019-07-10 17:04:16 -07002380 * This call MUST be invoked before clearing the calling UID.
2381 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002382 * @return target SDK if the package is found or INT_MAX.
2383 */
2384 private int getTargetSdk(String packageName) {
2385 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002386 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002387 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002388 if (ai != null) return ai.targetSdkVersion;
2389 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002390 loge("Failed to get package info for pkg="
2391 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002392 }
2393 return Integer.MAX_VALUE;
2394 }
2395
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 @Override
2397 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002398 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2399 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002400 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002401 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2402 throw new SecurityException(
2403 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2404 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002405
Jordan Liu1617b712019-07-10 15:06:26 -07002406 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2408 return null;
2409 }
Svetoslav64fad262015-04-14 14:35:21 -07002410
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002411 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002413 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002414 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415
Nathan Haroldf180aac2018-06-01 18:43:55 -07002416 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2417 for (CellInfo ci : info) {
2418 if (ci instanceof CellInfoGsm) {
2419 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2420 } else if (ci instanceof CellInfoWcdma) {
2421 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002424 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 }
2426
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002427 private List<CellInfo> getCachedCellInfo() {
2428 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2429 for (Phone phone : PhoneFactory.getPhones()) {
2430 List<CellInfo> info = phone.getAllCellInfo();
2431 if (info != null) cellInfos.addAll(info);
2432 }
2433 return cellInfos;
2434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435
2436 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002437 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002438 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002439 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002440
2441 LocationAccessPolicy.LocationPermissionResult locationResult =
2442 LocationAccessPolicy.checkLocationPermission(mApp,
2443 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2444 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002445 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002446 .setCallingPid(Binder.getCallingPid())
2447 .setCallingUid(Binder.getCallingUid())
2448 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002449 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002450 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2451 .build());
2452 switch (locationResult) {
2453 case DENIED_HARD:
2454 throw new SecurityException("Not allowed to access cell info");
2455 case DENIED_SOFT:
2456 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 }
2458
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002459 final int targetSdk = getTargetSdk(callingPackage);
2460 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2461 return getCachedCellInfo();
2462 }
2463
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002464 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002465 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002466 final long identity = Binder.clearCallingIdentity();
2467 try {
2468 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2469 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002470 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002471 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472 if (info != null) cellInfos.addAll(info);
2473 }
2474 return cellInfos;
2475 } finally {
2476 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478 }
2479
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002480 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002481 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2482 String callingFeatureId) {
2483 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2484 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002485 }
2486
2487 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002488 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2489 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002490 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002491 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002492 }
2493
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002494 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2495 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002496 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002497 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002498
2499 LocationAccessPolicy.LocationPermissionResult locationResult =
2500 LocationAccessPolicy.checkLocationPermission(mApp,
2501 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2502 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002503 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002504 .setCallingPid(Binder.getCallingPid())
2505 .setCallingUid(Binder.getCallingUid())
2506 .setMethod("requestCellInfoUpdate")
2507 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2508 .build());
2509 switch (locationResult) {
2510 case DENIED_HARD:
2511 throw new SecurityException("Not allowed to access cell info");
2512 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002513 try {
2514 cb.onCellInfo(new ArrayList<CellInfo>());
2515 } catch (RemoteException re) {
2516 // Drop without consequences
2517 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002518 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002519 }
2520
Nathan Harolda939a962019-05-09 10:13:47 -07002521
2522 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002523 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2524
2525 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2526 }
2527
2528 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002530 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002531 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002532
2533 final long identity = Binder.clearCallingIdentity();
2534 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002535 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002536 } finally {
2537 Binder.restoreCallingIdentity(identity);
2538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539 }
2540
Shishir Agrawala9f32182016-04-12 12:00:16 -07002541 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002542 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002543 Phone phone = PhoneFactory.getPhone(slotIndex);
2544 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002545 return null;
2546 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002547 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002548 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002549 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002550 return null;
2551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 return phone.getImei();
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
2558 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002559 }
2560
2561 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002562 public String getTypeAllocationCodeForSlot(int slotIndex) {
2563 Phone phone = PhoneFactory.getPhone(slotIndex);
2564 String tac = null;
2565 if (phone != null) {
2566 String imei = phone.getImei();
2567 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2568 }
2569 return tac;
2570 }
2571
2572 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002573 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002574 Phone phone = PhoneFactory.getPhone(slotIndex);
2575 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002576 return null;
2577 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002578
Jeff Davidson913390f2018-02-23 17:11:49 -08002579 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002580 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002581 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002582 return null;
2583 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002584
2585 final long identity = Binder.clearCallingIdentity();
2586 try {
2587 return phone.getMeid();
2588 } finally {
2589 Binder.restoreCallingIdentity(identity);
2590 }
Jack Yu2af8d712017-03-15 17:14:14 -07002591 }
2592
2593 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002594 public String getManufacturerCodeForSlot(int slotIndex) {
2595 Phone phone = PhoneFactory.getPhone(slotIndex);
2596 String manufacturerCode = null;
2597 if (phone != null) {
2598 String meid = phone.getMeid();
2599 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2600 }
2601 return manufacturerCode;
2602 }
2603
2604 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002605 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2606 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002607 Phone phone = PhoneFactory.getPhone(slotIndex);
2608 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002609 return null;
2610 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002611 int subId = phone.getSubId();
2612 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002613 mApp, subId, callingPackage, callingFeatureId,
2614 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002615 return null;
2616 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617
2618 final long identity = Binder.clearCallingIdentity();
2619 try {
2620 return phone.getDeviceSvn();
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
2623 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002624 }
2625
fionaxu43304da2017-11-27 22:51:16 -08002626 @Override
2627 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628 final long identity = Binder.clearCallingIdentity();
2629 try {
2630 final Phone phone = getPhone(subId);
2631 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2632 } finally {
2633 Binder.restoreCallingIdentity(identity);
2634 }
fionaxu43304da2017-11-27 22:51:16 -08002635 }
2636
2637 @Override
2638 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 final Phone phone = getPhone(subId);
2642 return phone == null ? null : phone.getCarrierName();
2643 } finally {
2644 Binder.restoreCallingIdentity(identity);
2645 }
fionaxu43304da2017-11-27 22:51:16 -08002646 }
2647
calvinpanffe225e2018-11-01 19:43:06 +08002648 @Override
chen xu0026ca62019-03-06 15:28:50 -08002649 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002650 final long identity = Binder.clearCallingIdentity();
2651 try {
2652 final Phone phone = getPhone(subId);
2653 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002654 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002655 } finally {
2656 Binder.restoreCallingIdentity(identity);
2657 }
2658 }
2659
2660 @Override
chen xu0026ca62019-03-06 15:28:50 -08002661 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002665 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002666 } finally {
2667 Binder.restoreCallingIdentity(identity);
2668 }
2669 }
2670
chen xu651eec72018-11-11 19:03:44 -08002671 @Override
chen xu864e11c2018-12-06 22:10:03 -08002672 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2673 if (!isSubscriptionMccMnc) {
2674 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2675 }
chen xu651eec72018-11-11 19:03:44 -08002676 final Phone phone = PhoneFactory.getPhone(slotIndex);
2677 if (phone == null) {
2678 return TelephonyManager.UNKNOWN_CARRIER_ID;
2679 }
2680 final long identity = Binder.clearCallingIdentity();
2681 try {
2682 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
2685 }
2686 }
2687
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 //
2689 // Internal helper methods.
2690 //
2691
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002692 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2694 *
2695 * @throws SecurityException if the caller does not have the required permission
2696 */
2697 private void enforceModifyPermission() {
2698 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2699 }
2700
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002701 /**
2702 * Make sure the caller is system.
2703 *
2704 * @throws SecurityException if the caller is not system.
2705 */
2706 private void enforceSystemCaller() {
2707 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2708 throw new SecurityException("Caller must be system");
2709 }
2710 }
2711
Shuo Qianf2b2df42019-11-13 17:43:31 -08002712 private void enforceActiveEmergencySessionPermission() {
2713 mApp.enforceCallingOrSelfPermission(
2714 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2715 }
2716
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 /**
2718 * Make sure the caller has the CALL_PHONE permission.
2719 *
2720 * @throws SecurityException if the caller does not have the required permission
2721 */
2722 private void enforceCallPermission() {
2723 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2724 }
2725
paulhu423b5f22019-08-23 19:17:33 +08002726 private void enforceSettingsPermission() {
2727 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002728 }
2729
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 private String createTelUrl(String number) {
2731 if (TextUtils.isEmpty(number)) {
2732 return null;
2733 }
2734
Jake Hambye994d462014-02-03 13:10:13 -08002735 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 }
2737
Ihab Awadf9e92732013-12-05 18:02:52 -08002738 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2740 }
2741
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002742 private static void logv(String msg) {
2743 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2744 }
2745
Ihab Awadf9e92732013-12-05 18:02:52 -08002746 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002747 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2748 }
2749
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002750 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002752 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002753 }
2754
Sanket Padawe356d7632015-06-22 14:03:32 -07002755 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002756 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757 final long identity = Binder.clearCallingIdentity();
2758 try {
2759 final Phone phone = PhoneFactory.getPhone(slotIndex);
2760 if (phone == null) {
2761 return PhoneConstants.PHONE_TYPE_NONE;
2762 } else {
2763 return phone.getPhoneType();
2764 }
2765 } finally {
2766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 }
2769
2770 /**
2771 * Returns the CDMA ERI icon index to display
2772 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002773 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002774 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2775 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2776 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002777 }
2778
Sanket Padawe356d7632015-06-22 14:03:32 -07002779 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002780 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2781 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002782 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002783 mApp, subId, callingPackage, callingFeatureId,
2784 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002785 return -1;
2786 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787
2788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 final Phone phone = getPhone(subId);
2791 if (phone != null) {
2792 return phone.getCdmaEriIconIndex();
2793 } else {
2794 return -1;
2795 }
2796 } finally {
2797 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002798 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002799 }
2800
2801 /**
2802 * Returns the CDMA ERI icon mode,
2803 * 0 - ON
2804 * 1 - FLASHING
2805 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002806 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002807 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2808 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2809 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002810 }
2811
Sanket Padawe356d7632015-06-22 14:03:32 -07002812 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002813 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2814 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002815 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002816 mApp, subId, callingPackage, callingFeatureId,
2817 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002818 return -1;
2819 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820
2821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 final Phone phone = getPhone(subId);
2824 if (phone != null) {
2825 return phone.getCdmaEriIconMode();
2826 } else {
2827 return -1;
2828 }
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 }
2833
2834 /**
2835 * Returns the CDMA ERI text,
2836 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002837 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002838 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2839 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2840 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002841 }
2842
Sanket Padawe356d7632015-06-22 14:03:32 -07002843 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002844 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2845 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002846 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002847 mApp, subId, callingPackage, callingFeatureId,
2848 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002849 return null;
2850 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851
2852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 final Phone phone = getPhone(subId);
2855 if (phone != null) {
2856 return phone.getCdmaEriText();
2857 } else {
2858 return null;
2859 }
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002862 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002863 }
2864
2865 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002866 * Returns the CDMA MDN.
2867 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002868 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002869 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2871 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872
2873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002876 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002877 return phone.getLine1Number();
2878 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002879 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880 return null;
2881 }
2882 } finally {
2883 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002884 }
2885 }
2886
2887 /**
2888 * Returns the CDMA MIN.
2889 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002890 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002891 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2893 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894
2895 final long identity = Binder.clearCallingIdentity();
2896 try {
2897 final Phone phone = getPhone(subId);
2898 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2899 return phone.getCdmaMin();
2900 } else {
2901 return null;
2902 }
2903 } finally {
2904 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002905 }
2906 }
2907
Hall Liud892bec2018-11-30 14:51:45 -08002908 @Override
2909 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2910 INumberVerificationCallback callback, String callingPackage) {
2911 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2912 != PERMISSION_GRANTED) {
2913 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2914 }
2915 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2916
2917 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2918 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2919 throw new SecurityException("Calling package must be configured in the device config");
2920 }
2921
2922 if (range == null) {
2923 throw new NullPointerException("Range must be non-null");
2924 }
2925
2926 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002927 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002928
2929 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2930 }
2931
Junda Liuca05d5d2014-08-14 22:36:34 -07002932 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 * Returns true if CDMA provisioning needs to run.
2934 */
2935 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002938 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 } finally {
2940 Binder.restoreCallingIdentity(identity);
2941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002942 }
2943
2944 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002945 * Sets the voice mail number of a given subId.
2946 */
2947 @Override
2948 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002949 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2950 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2955 new Pair<String, String>(alphaTag, number), new Integer(subId));
2956 return success;
2957 } finally {
2958 Binder.restoreCallingIdentity(identity);
2959 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002960 }
2961
Ta-wei Yen87c49842016-05-13 21:19:52 -07002962 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002963 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2964 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002965 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2966 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002967 if (!TextUtils.equals(callingPackage, systemDialer)) {
2968 throw new SecurityException("caller must be system dialer");
2969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002970
2971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2974 if (phoneAccountHandle == null) {
2975 return null;
2976 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002977 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002978 } finally {
2979 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002980 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002981 }
2982
2983 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002984 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2985 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002986 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002988 mApp, subId, callingPackage, callingFeatureId,
2989 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002990 return null;
2991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002993 final long identity = Binder.clearCallingIdentity();
2994 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002995 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002996 } finally {
2997 Binder.restoreCallingIdentity(identity);
2998 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002999 }
3000
3001 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003002 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3003 VisualVoicemailSmsFilterSettings settings) {
3004 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005
3006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003009 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003010 } finally {
3011 Binder.restoreCallingIdentity(identity);
3012 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003013 }
3014
3015 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003016 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3017 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018
3019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003022 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 } finally {
3024 Binder.restoreCallingIdentity(identity);
3025 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003026 }
3027
3028 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003029 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3030 String callingPackage, int subId) {
3031 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003032
3033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003036 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003040 }
3041
3042 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003043 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003044 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003045
3046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003049 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050 } finally {
3051 Binder.restoreCallingIdentity(identity);
3052 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003053 }
3054
3055 @Override
3056 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3057 String number, int port, String text, PendingIntent sentIntent) {
3058 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003059 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003060 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003061 SmsController smsController = PhoneFactory.getSmsController();
3062 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3063 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003064 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003065
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003066 /**
fionaxu0152e512016-11-14 13:36:14 -08003067 * Sets the voice activation state of a given subId.
3068 */
3069 @Override
3070 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3072 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003073
3074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 final Phone phone = getPhone(subId);
3077 if (phone != null) {
3078 phone.setVoiceActivationState(activationState);
3079 } else {
3080 loge("setVoiceActivationState fails with invalid subId: " + subId);
3081 }
3082 } finally {
3083 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003084 }
3085 }
3086
3087 /**
3088 * Sets the data activation state of a given subId.
3089 */
3090 @Override
3091 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3093 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003094
3095 final long identity = Binder.clearCallingIdentity();
3096 try {
3097 final Phone phone = getPhone(subId);
3098 if (phone != null) {
3099 phone.setDataActivationState(activationState);
3100 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003101 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102 }
3103 } finally {
3104 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003105 }
3106 }
3107
3108 /**
3109 * Returns the voice activation state of a given subId.
3110 */
3111 @Override
3112 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003113 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114
fionaxu0152e512016-11-14 13:36:14 -08003115 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116 final long identity = Binder.clearCallingIdentity();
3117 try {
3118 if (phone != null) {
3119 return phone.getVoiceActivationState();
3120 } else {
3121 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3122 }
3123 } finally {
3124 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003125 }
3126 }
3127
3128 /**
3129 * Returns the data activation state of a given subId.
3130 */
3131 @Override
3132 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003133 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003134
fionaxu0152e512016-11-14 13:36:14 -08003135 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 if (phone != null) {
3139 return phone.getDataActivationState();
3140 } else {
3141 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3142 }
3143 } finally {
3144 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003145 }
3146 }
3147
3148 /**
Wink Saville36469e72014-06-11 15:17:00 -07003149 * Returns the unread count of voicemails for a subId
3150 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003151 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003152 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3153 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003154 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003155 mApp, subId, callingPackage, callingFeatureId,
3156 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003157 return 0;
3158 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003159 final long identity = Binder.clearCallingIdentity();
3160 try {
3161 final Phone phone = getPhone(subId);
3162 if (phone != null) {
3163 return phone.getVoiceMessageCount();
3164 } else {
3165 return 0;
3166 }
3167 } finally {
3168 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170 }
3171
3172 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003173 * returns true, if the device is in a state where both voice and data
3174 * are supported simultaneously. This can change based on location or network condition.
3175 */
3176 @Override
3177 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003178 final long identity = Binder.clearCallingIdentity();
3179 try {
3180 final Phone phone = getPhone(subId);
3181 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3182 } finally {
3183 Binder.restoreCallingIdentity(identity);
3184 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003185 }
3186
3187 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003188 * Send the dialer code if called from the current default dialer or the caller has
3189 * carrier privilege.
3190 * @param inputCode The dialer code to send
3191 */
3192 @Override
3193 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003194 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003195 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003196 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3197 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003198 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003199 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003200 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003201 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202
3203 final long identity = Binder.clearCallingIdentity();
3204 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003205 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206 } finally {
3207 Binder.restoreCallingIdentity(identity);
3208 }
fionaxu235cc5e2017-03-06 22:25:57 -08003209 }
3210
Pengquan Menga1bb6272018-09-06 09:59:22 -07003211 @Override
3212 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003213 TelephonyPermissions
3214 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3215 mApp, subId, "getNetworkSelectionMode");
3216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 if (!isActiveSubscription(subId)) {
3219 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3220 }
3221 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3222 } finally {
3223 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003224 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003225 }
3226
Brad Ebinger35c841c2018-10-01 10:40:55 -07003227 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003228 public boolean isInEmergencySmsMode() {
3229 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3230 final long identity = Binder.clearCallingIdentity();
3231 try {
3232 for (Phone phone : PhoneFactory.getPhones()) {
3233 if (phone.isInEmergencySmsMode()) {
3234 return true;
3235 }
3236 }
3237 } finally {
3238 Binder.restoreCallingIdentity(identity);
3239 }
3240 return false;
3241 }
3242
shilu366312e2019-12-17 09:28:10 -08003243 /**
3244 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3245 * @param subId The subscription to use to check the configuration.
3246 * @param c The callback that will be used to send the result.
3247 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003248 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003249 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3250 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003251 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3252 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003253
Brad Ebinger77b832e2019-10-17 17:03:22 -07003254 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3255 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3256 "IMS not available on device.");
3257 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003258 final long token = Binder.clearCallingIdentity();
3259 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003260 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003261 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003262 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003263 } catch (ImsException e) {
3264 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003265 } finally {
3266 Binder.restoreCallingIdentity(token);
3267 }
3268 }
3269
shilu366312e2019-12-17 09:28:10 -08003270 /**
3271 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3272 * @param subId The subscription to use to check the configuration.
3273 * @param c The callback that will be used to send the result.
3274 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003275 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003276 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003277 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3278 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003279 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3280 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3281 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003282 final long token = Binder.clearCallingIdentity();
3283 try {
3284 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3285 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3286 .removeRegistrationCallbackForSubscription(c, subId);
3287 } catch (ImsException e) {
3288 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3289 + "is inactive, ignoring unregister.");
3290 // If the subscription is no longer active, just return, since the callback
3291 // will already have been removed internally.
3292 } finally {
3293 Binder.restoreCallingIdentity(token);
3294 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003295 }
3296
Brad Ebinger774ba362019-10-22 17:36:18 -07003297 /**
3298 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3299 */
3300 @Override
3301 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3302 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3303 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3304 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3305 "IMS not available on device.");
3306 }
3307 final long token = Binder.clearCallingIdentity();
3308 try {
3309 Phone phone = getPhone(subId);
3310 if (phone == null) {
3311 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3312 + subId + "'");
3313 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3314 }
3315 phone.getImsRegistrationState(regState -> {
3316 try {
3317 consumer.accept((regState == null)
3318 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3319 } catch (RemoteException e) {
3320 // Ignore if the remote process is no longer available to call back.
3321 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3322 }
3323 });
3324 } finally {
3325 Binder.restoreCallingIdentity(token);
3326 }
3327 }
3328
3329 /**
3330 * Get the transport type for the IMS service registration state.
3331 */
3332 @Override
3333 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003334 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3335 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003336 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3337 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3338 "IMS not available on device.");
3339 }
3340 final long token = Binder.clearCallingIdentity();
3341 try {
3342 Phone phone = getPhone(subId);
3343 if (phone == null) {
3344 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3345 + subId + "'");
3346 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3347 }
3348 phone.getImsRegistrationTech(regTech -> {
3349 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3350 int regTechConverted = (regTech == null)
3351 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3352 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3353 regTechConverted);
3354 try {
3355 consumer.accept(regTechConverted);
3356 } catch (RemoteException e) {
3357 // Ignore if the remote process is no longer available to call back.
3358 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3359 }
3360 });
3361 } finally {
3362 Binder.restoreCallingIdentity(token);
3363 }
3364 }
3365
shilu366312e2019-12-17 09:28:10 -08003366 /**
3367 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3368 * @param subId The subscription to use to check the configuration.
3369 * @param c The callback that will be used to send the result.
3370 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003371 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003372 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3373 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003374 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3375 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003376 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3377 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3378 "IMS not available on device.");
3379 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003380 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3381 final long token = Binder.clearCallingIdentity();
3382 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003383 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003384 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003385 } catch (ImsException e) {
3386 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003387 } finally {
3388 Binder.restoreCallingIdentity(token);
3389 }
3390 }
3391
shilu366312e2019-12-17 09:28:10 -08003392 /**
3393 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3394 * @param subId The subscription to use to check the configuration.
3395 * @param c The callback that will be used to send the result.
3396 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003397 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003398 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003399 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3400 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003401 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3402 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3403 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003404
3405 final long token = Binder.clearCallingIdentity();
3406 try {
3407 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3408 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003409 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003410 } catch (ImsException e) {
3411 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3412 + "is inactive, ignoring unregister.");
3413 // If the subscription is no longer active, just return, since the callback
3414 // will already have been removed internally.
3415 } finally {
3416 Binder.restoreCallingIdentity(token);
3417 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003418 }
3419
3420 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003421 public boolean isCapable(int subId, int capability, int regTech) {
3422 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003423 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3424 final long token = Binder.clearCallingIdentity();
3425 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003426 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003427 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003428 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003429 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3430 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003431 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003432 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3433 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003434 } finally {
3435 Binder.restoreCallingIdentity(token);
3436 }
3437 }
3438
3439 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003440 public boolean isAvailable(int subId, int capability, int regTech) {
3441 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003442 final long token = Binder.clearCallingIdentity();
3443 try {
3444 Phone phone = getPhone(subId);
3445 if (phone == null) return false;
3446 return phone.isImsCapabilityAvailable(capability, regTech);
3447 } finally {
3448 Binder.restoreCallingIdentity(token);
3449 }
3450 }
3451
Brad Ebinger77b832e2019-10-17 17:03:22 -07003452 /**
3453 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3454 * subscription.
3455 * @param subId The subscription to use to check the configuration.
3456 * @param callback The callback that will be used to send the result.
3457 * @param capability The MmTelFeature capability that will be used to send the result.
3458 * @param transportType The transport type of the MmTelFeature capability.
3459 */
3460 @Override
3461 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3462 int transportType) {
3463 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3464 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3465 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3466 "IMS not available on device.");
3467 }
3468 final long token = Binder.clearCallingIdentity();
3469 try {
3470 int slotId = getSlotIndex(subId);
3471 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3472 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3473 + subId + "'");
3474 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3475 }
3476 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3477 transportType, aBoolean -> {
3478 try {
3479 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3480 } catch (RemoteException e) {
3481 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3482 + "running. Ignore");
3483 }
3484 });
3485 } finally {
3486 Binder.restoreCallingIdentity(token);
3487 }
3488 }
3489
shilu366312e2019-12-17 09:28:10 -08003490 /**
3491 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3492 * @param subId The subscription to use to check the configuration.
3493 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003494 @Override
3495 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003496 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3497 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003498
Brad Ebinger35c841c2018-10-01 10:40:55 -07003499 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3500 final long token = Binder.clearCallingIdentity();
3501 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003502 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003503 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003504 } catch (ImsException e) {
3505 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003506 } finally {
3507 Binder.restoreCallingIdentity(token);
3508 }
3509 }
3510
3511 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003512 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003514 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003515 final long identity = Binder.clearCallingIdentity();
3516 try {
3517 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003518 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003519 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003520 } catch (ImsException e) {
3521 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003522 } finally {
3523 Binder.restoreCallingIdentity(identity);
3524 }
3525 }
3526
shilu366312e2019-12-17 09:28:10 -08003527 /**
3528 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3529 * @param subId The subscription to use to check the configuration.
3530 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003531 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003532 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003533 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3534 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003538 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3539 } catch (ImsException e) {
3540 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003541 } finally {
3542 Binder.restoreCallingIdentity(identity);
3543 }
3544 }
3545
3546 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003547 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003549 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003553 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003554 } catch (ImsException e) {
3555 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003556 } finally {
3557 Binder.restoreCallingIdentity(identity);
3558 }
3559 }
3560
shilu366312e2019-12-17 09:28:10 -08003561 /**
3562 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3563 * @param subId The subscription to use to check the configuration.
3564 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003565 @Override
3566 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003567 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3568 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003572 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003573 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003574 } catch (ImsException e) {
3575 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003576 } finally {
3577 Binder.restoreCallingIdentity(identity);
3578 }
3579 }
3580
3581 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003582 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003584 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 final long identity = Binder.clearCallingIdentity();
3586 try {
3587 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003588 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003589 } catch (ImsException e) {
3590 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003591 } finally {
3592 Binder.restoreCallingIdentity(identity);
3593 }
3594 }
3595
shilu366312e2019-12-17 09:28:10 -08003596 /**
3597 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3598 * @param subId The subscription to use to check the configuration.
3599 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003600 @Override
3601 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003602 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3603 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003607 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003608 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003609 } catch (ImsException e) {
3610 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003611 } finally {
3612 Binder.restoreCallingIdentity(identity);
3613 }
3614 }
3615
3616 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003617 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003619 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003623 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003624 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003625 } catch (ImsException e) {
3626 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003627 } finally {
3628 Binder.restoreCallingIdentity(identity);
3629 }
3630 }
3631
3632 @Override
3633 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3635 "setVoWiFiNonPersistent");
3636 final long identity = Binder.clearCallingIdentity();
3637 try {
3638 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003639 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003640 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003641 } catch (ImsException e) {
3642 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003643 } finally {
3644 Binder.restoreCallingIdentity(identity);
3645 }
3646 }
3647
shilu366312e2019-12-17 09:28:10 -08003648 /**
3649 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3650 * @param subId The subscription to use to check the configuration.
3651 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003652 @Override
3653 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003654 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3655 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003656 final long identity = Binder.clearCallingIdentity();
3657 try {
3658 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003659 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003660 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003661 } catch (ImsException e) {
3662 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
3666 }
3667
3668 @Override
3669 public void setVoWiFiModeSetting(int subId, int mode) {
3670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3671 "setVoWiFiModeSetting");
3672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003675 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003676 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003677 } catch (ImsException e) {
3678 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003679 } finally {
3680 Binder.restoreCallingIdentity(identity);
3681 }
3682 }
3683
3684 @Override
3685 public int getVoWiFiRoamingModeSetting(int subId) {
3686 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003690 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003691 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003692 } catch (ImsException e) {
3693 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003694 } finally {
3695 Binder.restoreCallingIdentity(identity);
3696 }
3697 }
3698
3699 @Override
3700 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3702 "setVoWiFiRoamingModeSetting");
3703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003706 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003708 } catch (ImsException e) {
3709 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
3713 }
3714
3715 @Override
3716 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3718 "setRttCapabilityEnabled");
3719 final long identity = Binder.clearCallingIdentity();
3720 try {
3721 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003722 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3723 } catch (ImsException e) {
3724 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 } finally {
3726 Binder.restoreCallingIdentity(identity);
3727 }
3728 }
3729
shilu366312e2019-12-17 09:28:10 -08003730 /**
3731 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3732 * @param subId The subscription to use to check the configuration.
3733 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003734 @Override
3735 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003736 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3737 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003738 final long identity = Binder.clearCallingIdentity();
3739 try {
3740 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003741 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003742 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003743 } catch (ImsException e) {
3744 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003745 } finally {
3746 Binder.restoreCallingIdentity(identity);
3747 }
3748 }
3749
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003750 @Override
3751 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3752 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3753 final long identity = Binder.clearCallingIdentity();
3754 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003755 if (!isImsAvailableOnDevice()) {
3756 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3757 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003758 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003759 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003760 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003761 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003762 } catch (ImsException e) {
3763 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003764 } finally {
3765 Binder.restoreCallingIdentity(identity);
3766 }
3767 }
3768
3769 @Override
3770 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3771 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3772 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003773 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3774 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3775 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003776 try {
3777 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003778 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003779 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003780 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003781 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3782 + "is inactive, ignoring unregister.");
3783 // If the subscription is no longer active, just return, since the callback will already
3784 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003785 } finally {
3786 Binder.restoreCallingIdentity(identity);
3787 }
3788 }
3789
allenwtsu99c623b2020-01-03 18:24:23 +08003790
3791 private void checkModifyPhoneStatePermission(int subId, String message) {
3792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3793 message);
3794 }
3795
3796 private boolean isImsProvisioningRequired(int subId, int capability,
3797 boolean isMmtelCapability) {
3798 Phone phone = getPhone(subId);
3799 if (phone == null) {
3800 loge("phone instance null for subid " + subId);
3801 return false;
3802 }
3803 if (isMmtelCapability) {
3804 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3805 return false;
3806 }
3807 } else {
3808 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3809 return false;
3810 }
3811 }
3812 return true;
3813 }
3814
3815 @Override
3816 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3817 boolean isProvisioned) {
3818 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3819
3820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3823 if (!isImsProvisioningRequired(subId, capability, false)) {
3824 return;
3825 }
3826
3827 // this capability requires provisioning, route to the correct API.
3828 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3829 switch (capability) {
3830 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3831 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3832 ims.setEabProvisioned(isProvisioned);
3833 break;
3834 default: {
3835 throw new IllegalArgumentException("Tried to set provisioning for "
3836 + "rcs capability '" + capability + "', which does not require "
3837 + "provisioning.");
3838 }
3839 }
3840 } finally {
3841 Binder.restoreCallingIdentity(identity);
3842 }
3843
3844 }
3845
3846
3847 @Override
3848 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3849 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3850 final long identity = Binder.clearCallingIdentity();
3851 try {
3852 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3853 if (!isImsProvisioningRequired(subId, capability, false)) {
3854 return true;
3855 }
3856
3857 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3858 switch (capability) {
3859 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3860 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3861 return ims.isEabProvisionedOnDevice();
3862
3863 default: {
3864 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3865 + "capability '" + capability + "', which does not require "
3866 + "provisioning.");
3867 }
3868 }
3869
3870 } finally {
3871 Binder.restoreCallingIdentity(identity);
3872 }
3873 }
3874
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003875 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003876 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3877 boolean isProvisioned) {
3878 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3879 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3880 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3881 }
allenwtsu99c623b2020-01-03 18:24:23 +08003882 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003883 final long identity = Binder.clearCallingIdentity();
3884 try {
3885 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003886 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003887 return;
3888 }
3889
3890 // this capability requires provisioning, route to the correct API.
3891 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3892 switch (capability) {
3893 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3894 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3895 ims.setVolteProvisioned(isProvisioned);
3896 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3897 ims.setWfcProvisioned(isProvisioned);
3898 }
3899 break;
3900 }
3901 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3902 // There is currently no difference in VT provisioning type.
3903 ims.setVtProvisioned(isProvisioned);
3904 break;
3905 }
3906 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3907 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3908 // change the capability of the feature instead if needed.
3909 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3910 == isProvisioned) {
3911 // No change in provisioning.
3912 return;
3913 }
3914 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3915 try {
3916 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003917 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003918 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3919 + ", Exception" + e.getMessage());
3920 }
3921 break;
3922 }
3923 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003924 throw new IllegalArgumentException("Tried to set provisioning for "
3925 + "MmTel capability '" + capability + "', which does not require "
3926 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003927 }
3928 }
3929
3930 } finally {
3931 Binder.restoreCallingIdentity(identity);
3932 }
3933 }
3934
3935 @Override
3936 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3937 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3938 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3939 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3940 }
3941 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003945 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003946 return true;
3947 }
3948
3949 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3950 switch (capability) {
3951 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3952 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3953 return ims.isVolteProvisionedOnDevice();
3954 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3955 return ims.isWfcProvisionedOnDevice();
3956 }
3957 // This should never happen, since we are checking tech above to make sure it
3958 // is either LTE or IWLAN.
3959 throw new IllegalArgumentException("Invalid radio technology for voice "
3960 + "capability.");
3961 }
3962 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3963 // There is currently no difference in VT provisioning type.
3964 return ims.isVtProvisionedOnDevice();
3965 }
3966 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3967 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3968 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3969 }
3970 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003971 throw new IllegalArgumentException(
3972 "Tried to get provisioning for MmTel capability '" + capability
3973 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003974 }
3975 }
3976
3977 } finally {
3978 Binder.restoreCallingIdentity(identity);
3979 }
3980 }
3981
3982 @Override
3983 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3984 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3985 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3986 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3987 }
3988 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3989 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3990 return (provisionedBits & capability) > 0;
3991 }
3992
3993 @Override
3994 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3995 boolean isProvisioned) {
3996 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3997 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3998 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3999 }
4000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4001 "setProvisioningStatusForCapability");
4002 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4003 // If the current provisioning status for capability already matches isProvisioned,
4004 // do nothing.
4005 if (((provisionedBits & capability) > 0) == isProvisioned) {
4006 return;
4007 }
4008 if (isProvisioned) {
4009 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4010 } else {
4011 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4012 }
4013 }
4014
4015 /**
4016 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4017 * technology. The bitfield should mirror the bitfield defined by
4018 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4019 */
4020 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4021 String key = getMmTelProvisioningKey(subId, tech);
4022 // Default is no capabilities are provisioned.
4023 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4024 }
4025
4026 /**
4027 * Sets the MmTel capability provisioning bitfield (defined by
4028 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4029 * technology specified.
4030 *
4031 * Note: This is a synchronous command and should not be called on UI thread.
4032 */
4033 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4034 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4035 String key = getMmTelProvisioningKey(subId, tech);
4036 editor.putInt(key, newField);
4037 editor.commit();
4038 }
4039
4040 private static String getMmTelProvisioningKey(int subId, int tech) {
4041 // resulting key is provision_ims_mmtel_{subId}_{tech}
4042 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4043 }
4044
4045 /**
4046 * Query CarrierConfig to see if the specified capability requires provisioning for the
4047 * carrier associated with the subscription id.
4048 */
4049 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4050 int capability) {
4051 CarrierConfigManager configManager = new CarrierConfigManager(context);
4052 PersistableBundle c = configManager.getConfigForSubId(subId);
4053 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004054 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004055 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4056 false);
4057 boolean requireVoiceVtProvisioning = c.getBoolean(
4058 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4059
4060 // First check to make sure that the capability requires provisioning.
4061 switch (capability) {
4062 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4063 // intentional fallthrough
4064 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4065 if (requireVoiceVtProvisioning) {
4066 // Voice and Video requires provisioning
4067 return true;
4068 }
4069 break;
4070 }
4071 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4072 if (requireUtProvisioning) {
4073 // UT requires provisioning
4074 return true;
4075 }
4076 break;
4077 }
4078 }
4079 return false;
4080 }
4081
allenwtsu99c623b2020-01-03 18:24:23 +08004082 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4083 int capability) {
4084 CarrierConfigManager configManager = new CarrierConfigManager(context);
4085 PersistableBundle c = configManager.getConfigForSubId(subId);
4086
4087 boolean requireRcsProvisioning = c.getBoolean(
4088 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4089
4090 // First check to make sure that the capability requires provisioning.
4091 switch (capability) {
4092 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4093 // intentional fallthrough
4094 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4095 if (requireRcsProvisioning) {
4096 // OPTION or PRESENCE requires provisioning
4097 return true;
4098 }
4099 break;
4100 }
4101 }
4102 return false;
4103 }
4104
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004105 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004106 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004107 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4108 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4109 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004110 enforceReadPrivilegedPermission("getImsProvisioningInt");
4111 final long identity = Binder.clearCallingIdentity();
4112 try {
4113 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004114 int slotId = getSlotIndex(subId);
4115 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4116 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4117 + subId + "' for key:" + key);
4118 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4119 }
4120 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004121 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004122 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4123 + subId + "' for key:" + key);
4124 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004125 } finally {
4126 Binder.restoreCallingIdentity(identity);
4127 }
4128 }
4129
4130 @Override
4131 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004132 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4133 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4134 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004135 enforceReadPrivilegedPermission("getImsProvisioningString");
4136 final long identity = Binder.clearCallingIdentity();
4137 try {
4138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004139 int slotId = getSlotIndex(subId);
4140 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4141 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4142 + subId + "' for key:" + key);
4143 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4144 }
4145 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004146 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004147 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4148 + subId + "' for key:" + key);
4149 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004150 } finally {
4151 Binder.restoreCallingIdentity(identity);
4152 }
4153 }
4154
4155 @Override
4156 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004157 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4158 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4159 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4161 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004162 final long identity = Binder.clearCallingIdentity();
4163 try {
4164 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004165 int slotId = getSlotIndex(subId);
4166 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4167 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4168 + subId + "' for key:" + key);
4169 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4170 }
4171 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004172 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004173 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4174 + "' for key:" + key);
4175 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004176 } finally {
4177 Binder.restoreCallingIdentity(identity);
4178 }
4179 }
4180
4181 @Override
4182 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004183 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4184 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4185 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4187 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004188 final long identity = Binder.clearCallingIdentity();
4189 try {
4190 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004191 int slotId = getSlotIndex(subId);
4192 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4193 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4194 + subId + "' for key:" + key);
4195 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4196 }
4197 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004198 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004199 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4200 + "' for key:" + key);
4201 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004202 } finally {
4203 Binder.restoreCallingIdentity(identity);
4204 }
4205 }
4206
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004207 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 int slotId = SubscriptionManager.getSlotIndex(subId);
4209 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004210 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4211 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 }
4213 return slotId;
4214 }
4215
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004216 private int getSlotIndex(int subId) {
4217 int slotId = SubscriptionManager.getSlotIndex(subId);
4218 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4219 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4220 }
4221 return slotId;
4222 }
4223
Wink Saville36469e72014-06-11 15:17:00 -07004224 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004225 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004226 */
4227 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004228 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4229 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004230 final int targetSdk = getTargetSdk(callingPackage);
4231 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004232 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004233 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004234 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004235 mApp, subId, callingPackage, callingFeatureId,
4236 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004237 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4238 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240 final long identity = Binder.clearCallingIdentity();
4241 try {
4242 final Phone phone = getPhone(subId);
4243 if (phone != null) {
4244 return phone.getServiceState().getDataNetworkType();
4245 } else {
4246 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4247 }
4248 } finally {
4249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004251 }
4252
4253 /**
4254 * Returns the data network type
4255 */
4256 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004257 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4258 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4259 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004260 }
4261
4262 /**
4263 * Returns the data network type for a subId
4264 */
4265 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004266 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4267 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004268 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004269 mApp, subId, callingPackage, callingFeatureId,
4270 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004271 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4272 }
4273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004274 final long identity = Binder.clearCallingIdentity();
4275 try {
4276 final Phone phone = getPhone(subId);
4277 if (phone != null) {
4278 return phone.getServiceState().getDataNetworkType();
4279 } else {
4280 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4281 }
4282 } finally {
4283 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004285 }
4286
4287 /**
Wink Saville36469e72014-06-11 15:17:00 -07004288 * Returns the Voice network type for a subId
4289 */
4290 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004291 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4292 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004294 mApp, subId, callingPackage, callingFeatureId,
4295 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004296 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4297 }
4298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004299 final long identity = Binder.clearCallingIdentity();
4300 try {
4301 final Phone phone = getPhone(subId);
4302 if (phone != null) {
4303 return phone.getServiceState().getVoiceNetworkType();
4304 } else {
4305 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4306 }
4307 } finally {
4308 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004310 }
4311
4312 /**
4313 * @return true if a ICC card is present
4314 */
4315 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004316 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004317 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4318 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004319 }
4320
4321 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004322 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004323 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004324 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004325 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004326 final long identity = Binder.clearCallingIdentity();
4327 try {
4328 final Phone phone = PhoneFactory.getPhone(slotIndex);
4329 if (phone != null) {
4330 return phone.getIccCard().hasIccCard();
4331 } else {
4332 return false;
4333 }
4334 } finally {
4335 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004336 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004337 }
4338
4339 /**
4340 * Return if the current radio is LTE on CDMA. This
4341 * is a tri-state return value as for a period of time
4342 * the mode may be unknown.
4343 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004344 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004345 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004346 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004347 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004348 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004349 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4350 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4351 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004352 }
4353
Sanket Padawe356d7632015-06-22 14:03:32 -07004354 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004355 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4356 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004357 try {
4358 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4359 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004360 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4361 }
4362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004363 final long identity = Binder.clearCallingIdentity();
4364 try {
4365 final Phone phone = getPhone(subId);
4366 if (phone == null) {
4367 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4368 } else {
4369 return phone.getLteOnCdmaMode();
4370 }
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004373 }
Wink Saville36469e72014-06-11 15:17:00 -07004374 }
4375
Wink Saville36469e72014-06-11 15:17:00 -07004376 /**
4377 * {@hide}
4378 * Returns Default subId, 0 in the case of single standby.
4379 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004380 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004381 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004382 }
4383
Shishir Agrawala9f32182016-04-12 12:00:16 -07004384 private int getSlotForDefaultSubscription() {
4385 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4386 }
4387
Wink Savilleb564aae2014-10-23 10:18:09 -07004388 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004389 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004390 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004391
Pengquan Menge92a50d2018-09-21 15:54:48 -07004392 private boolean isActiveSubscription(int subId) {
4393 return mSubscriptionController.isActiveSubId(subId);
4394 }
4395
Ihab Awadf2177b72013-11-25 13:33:23 -08004396 /**
4397 * @see android.telephony.TelephonyManager.WifiCallingChoices
4398 */
4399 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004400 final long identity = Binder.clearCallingIdentity();
4401 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004402 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4404 getWhenToMakeWifiCallsDefaultPreference());
4405 } finally {
4406 Binder.restoreCallingIdentity(identity);
4407 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004408 }
4409
4410 /**
4411 * @see android.telephony.TelephonyManager.WifiCallingChoices
4412 */
4413 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004414 final long identity = Binder.clearCallingIdentity();
4415 try {
4416 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004417 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004418 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4419 } finally {
4420 Binder.restoreCallingIdentity(identity);
4421 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004422 }
4423
Sailesh Nepald1e68152013-12-12 19:08:02 -08004424 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004425 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004426 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004427 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004428
Jordan Liu4c733742019-02-28 12:03:40 -08004429 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4430 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4431 if (phoneId == -1) {
4432 throw new IllegalArgumentException("Given slot index: " + slotIndex
4433 + " does not correspond to an active phone");
4434 }
4435 return PhoneFactory.getPhone(phoneId);
4436 }
4437
Shishir Agrawal566b7612013-10-28 14:41:00 -07004438 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004439 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4440 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4442 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004444 if (DBG) {
4445 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4446 }
4447 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4448 p2);
4449 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004450
Jordan Liu4c733742019-02-28 12:03:40 -08004451
4452 @Override
4453 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4454 int slotIndex, String callingPackage, String aid, int p2) {
4455 enforceModifyPermission();
4456 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4457 if (DBG) {
4458 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4459 }
4460 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4461 callingPackage, aid, p2);
4462 }
4463
4464 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4465 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004466 final long identity = Binder.clearCallingIdentity();
4467 try {
4468 if (TextUtils.equals(ISDR_AID, aid)) {
4469 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004470 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4471 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 if (bestComponent == null
4473 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4474 loge("The calling package is not allowed to access ISD-R.");
4475 throw new SecurityException(
4476 "The calling package is not allowed to access ISD-R.");
4477 }
Derek Tan740e1672017-06-27 14:56:27 -07004478 }
Derek Tan740e1672017-06-27 14:56:27 -07004479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004481 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4482 null /* workSource */);
4483 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004484 return response;
4485 } finally {
4486 Binder.restoreCallingIdentity(identity);
4487 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004488 }
4489
4490 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004491 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4493 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004494 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4495 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4496 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004497
Jordan Liu4c733742019-02-28 12:03:40 -08004498 @Override
4499 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4500 enforceModifyPermission();
4501 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4502 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4503 channel);
4504 }
4505
4506 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004507 final long identity = Binder.clearCallingIdentity();
4508 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004509 if (channel < 0) {
4510 return false;
4511 }
Jordan Liu4c733742019-02-28 12:03:40 -08004512 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4513 null /* workSource */);
4514 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004515 return success;
4516 } finally {
4517 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004518 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004519 }
4520
4521 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004522 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004523 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4525 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004526 if (DBG) {
4527 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4528 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4529 + p3 + " data=" + data);
4530 }
4531 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4532 command, p1, p2, p3, data);
4533 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004534
Jordan Liu4c733742019-02-28 12:03:40 -08004535 @Override
4536 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4537 int command, int p1, int p2, int p3, String data) {
4538 enforceModifyPermission();
4539 if (DBG) {
4540 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4541 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4542 + p3 + " data=" + data);
4543 }
4544 return iccTransmitApduLogicalChannelWithPermission(
4545 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4546 data);
4547 }
4548
4549 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4550 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004551 final long identity = Binder.clearCallingIdentity();
4552 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004553 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 return "";
4555 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004557 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004558 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4559 null /* workSource */);
4560 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004562 // Append the returned status code to the end of the response payload.
4563 String s = Integer.toHexString(
4564 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4565 if (response.payload != null) {
4566 s = IccUtils.bytesToHexString(response.payload) + s;
4567 }
4568 return s;
4569 } finally {
4570 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004571 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004572 }
Jake Hambye994d462014-02-03 13:10:13 -08004573
Evan Charltonc66da362014-05-16 14:06:40 -07004574 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004575 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4576 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4578 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004579 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004580 if (DBG) {
4581 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4582 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4583 }
4584 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4585 cla, command, p1, p2, p3, data);
4586 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004587
Jordan Liu4c733742019-02-28 12:03:40 -08004588 @Override
4589 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4590 int command, int p1, int p2, int p3, String data) {
4591 enforceModifyPermission();
4592 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4593 if (DBG) {
4594 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4595 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4596 + " data=" + data);
4597 }
4598
4599 return iccTransmitApduBasicChannelWithPermission(
4600 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4601 p2, p3, data);
4602 }
4603
4604 // open APDU basic channel assuming the caller has sufficient permissions
4605 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4606 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004607 final long identity = Binder.clearCallingIdentity();
4608 try {
4609 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4610 && TextUtils.equals(ISDR_AID, data)) {
4611 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004612 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4613 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004614 if (bestComponent == null
4615 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4616 loge("The calling package is not allowed to select ISD-R.");
4617 throw new SecurityException(
4618 "The calling package is not allowed to select ISD-R.");
4619 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004620 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004622 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004623 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4624 null /* workSource */);
4625 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004627 // Append the returned status code to the end of the response payload.
4628 String s = Integer.toHexString(
4629 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4630 if (response.payload != null) {
4631 s = IccUtils.bytesToHexString(response.payload) + s;
4632 }
4633 return s;
4634 } finally {
4635 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004636 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004637 }
4638
4639 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004640 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004641 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4643 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004645 final long identity = Binder.clearCallingIdentity();
4646 try {
4647 if (DBG) {
4648 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4649 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4650 }
4651
4652 IccIoResult response =
4653 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4654 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4655 subId);
4656
4657 if (DBG) {
4658 log("Exchange SIM_IO [R]" + response);
4659 }
4660
4661 byte[] result = null;
4662 int length = 2;
4663 if (response.payload != null) {
4664 length = 2 + response.payload.length;
4665 result = new byte[length];
4666 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4667 } else {
4668 result = new byte[length];
4669 }
4670
4671 result[length - 1] = (byte) response.sw2;
4672 result[length - 2] = (byte) response.sw1;
4673 return result;
4674 } finally {
4675 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004676 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004677 }
4678
Nathan Haroldb3014052017-01-25 15:57:32 -08004679 /**
4680 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4681 * on a particular subscription
4682 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004683 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4684 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004686 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004687 return null;
4688 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689
4690 final long identity = Binder.clearCallingIdentity();
4691 try {
4692 if (appType != TelephonyManager.APPTYPE_USIM
4693 && appType != TelephonyManager.APPTYPE_SIM) {
4694 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4695 return null;
4696 }
4697 Object response = sendRequest(
4698 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4699 if (response instanceof String[]) {
4700 return (String[]) response;
4701 }
yincheng zhaod698b842019-09-06 17:06:54 -07004702 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004703 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004704 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 } finally {
4706 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004707 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004708 }
4709
yincheng zhaod698b842019-09-06 17:06:54 -07004710 /**
4711 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4712 * subscription.
4713 *
4714 * @param subId the id of the subscription.
4715 * @param appType the uicc app type, must be USIM or SIM.
4716 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4717 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004718 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004719 * @return number of fplmns that is successfully written to the SIM.
4720 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004721 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4722 String callingFeatureId) {
4723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4724 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004725 if (DBG) logv("no permissions for setForbiddenplmns");
4726 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4727 }
4728 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4729 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4730 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4731 }
4732 if (fplmns == null) {
4733 throw new IllegalArgumentException("Fplmn List provided is null");
4734 }
4735 for (String fplmn : fplmns) {
4736 if (!CellIdentity.isValidPlmn(fplmn)) {
4737 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4738 }
4739 }
4740 final long identity = Binder.clearCallingIdentity();
4741 try {
4742 Object response = sendRequest(
4743 CMD_SET_FORBIDDEN_PLMNS,
4744 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4745 subId);
4746 return (int) response;
4747 } finally {
4748 Binder.restoreCallingIdentity(identity);
4749 }
4750 }
4751
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004752 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004753 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4755 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004757 final long identity = Binder.clearCallingIdentity();
4758 try {
4759 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4760 if (response.payload == null) {
4761 return "";
4762 }
Evan Charltonc66da362014-05-16 14:06:40 -07004763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004764 // Append the returned status code to the end of the response payload.
4765 String s = Integer.toHexString(
4766 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4767 s = IccUtils.bytesToHexString(response.payload) + s;
4768 return s;
4769 } finally {
4770 Binder.restoreCallingIdentity(identity);
4771 }
Evan Charltonc66da362014-05-16 14:06:40 -07004772 }
4773
Jake Hambye994d462014-02-03 13:10:13 -08004774 /**
4775 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4776 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4777 *
4778 * @param itemID the ID of the item to read
4779 * @return the NV item as a String, or null on error.
4780 */
4781 @Override
4782 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004783 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4785 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004786
4787 final long identity = Binder.clearCallingIdentity();
4788 try {
4789 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004790 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004791 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4792 return value;
4793 } finally {
4794 Binder.restoreCallingIdentity(identity);
4795 }
Jake Hambye994d462014-02-03 13:10:13 -08004796 }
4797
4798 /**
4799 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4800 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4801 *
4802 * @param itemID the ID of the item to read
4803 * @param itemValue the value to write, as a String
4804 * @return true on success; false on any failure
4805 */
4806 @Override
4807 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004808 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4810 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004811
4812 final long identity = Binder.clearCallingIdentity();
4813 try {
4814 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4815 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004816 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4818 return success;
4819 } finally {
4820 Binder.restoreCallingIdentity(identity);
4821 }
Jake Hambye994d462014-02-03 13:10:13 -08004822 }
4823
4824 /**
4825 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4826 * Used for device configuration by some CDMA operators.
4827 *
4828 * @param preferredRoamingList byte array containing the new PRL
4829 * @return true on success; false on any failure
4830 */
4831 @Override
4832 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4834 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004835
4836 final long identity = Binder.clearCallingIdentity();
4837 try {
4838 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4839 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4840 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4841 return success;
4842 } finally {
4843 Binder.restoreCallingIdentity(identity);
4844 }
Jake Hambye994d462014-02-03 13:10:13 -08004845 }
4846
4847 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004848 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004849 * Used for device configuration by some CDMA operators.
4850 *
chen xu6dac5ab2018-10-26 17:39:23 -07004851 * @param slotIndex - device slot.
4852 *
Jake Hambye994d462014-02-03 13:10:13 -08004853 * @return true on success; false on any failure
4854 */
4855 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004856 public boolean resetModemConfig(int slotIndex) {
4857 Phone phone = PhoneFactory.getPhone(slotIndex);
4858 if (phone != null) {
4859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4860 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004861
chen xu6dac5ab2018-10-26 17:39:23 -07004862 final long identity = Binder.clearCallingIdentity();
4863 try {
4864 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4865 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4866 return success;
4867 } finally {
4868 Binder.restoreCallingIdentity(identity);
4869 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004870 }
chen xu6dac5ab2018-10-26 17:39:23 -07004871 return false;
4872 }
4873
4874 /**
4875 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4876 *
4877 * @param slotIndex - device slot.
4878 *
4879 * @return true on success; false on any failure
4880 */
4881 @Override
4882 public boolean rebootModem(int slotIndex) {
4883 Phone phone = PhoneFactory.getPhone(slotIndex);
4884 if (phone != null) {
4885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4886 mApp, phone.getSubId(), "rebootModem");
4887
4888 final long identity = Binder.clearCallingIdentity();
4889 try {
4890 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4891 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4892 return success;
4893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
4896 }
4897 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004898 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004899
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004900 public String[] getPcscfAddress(String apnType, String callingPackage,
4901 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004902 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4904 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004905 return new String[0];
4906 }
4907
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908 final long identity = Binder.clearCallingIdentity();
4909 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004910 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004911 } finally {
4912 Binder.restoreCallingIdentity(identity);
4913 }
Wink Saville36469e72014-06-11 15:17:00 -07004914 }
4915
Brad Ebinger51f743a2017-01-23 13:50:20 -08004916 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004917 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4918 * {@link #disableIms(int)}.
4919 * @param slotIndex device slot.
4920 */
4921 public void resetIms(int slotIndex) {
4922 enforceModifyPermission();
4923
4924 final long identity = Binder.clearCallingIdentity();
4925 try {
4926 if (mImsResolver == null) {
4927 // may happen if the does not support IMS.
4928 return;
4929 }
4930 mImsResolver.disableIms(slotIndex);
4931 mImsResolver.enableIms(slotIndex);
4932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
4935 }
4936
4937 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004938 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4939 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004940 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004941 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004942 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943
4944 final long identity = Binder.clearCallingIdentity();
4945 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004946 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004947 // may happen if the device does not support IMS.
4948 return;
4949 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004950 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 } finally {
4952 Binder.restoreCallingIdentity(identity);
4953 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004954 }
4955
4956 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004957 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4958 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004959 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004960 public void disableIms(int slotId) {
4961 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962
4963 final long identity = Binder.clearCallingIdentity();
4964 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004965 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004966 // may happen if the device does not support IMS.
4967 return;
4968 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004969 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 } finally {
4971 Binder.restoreCallingIdentity(identity);
4972 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004973 }
4974
4975 /**
4976 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4977 * feature or {@link null} if the service is not available. If the feature is available, the
4978 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4979 */
4980 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004981 IImsServiceFeatureCallback callback) {
4982 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983
4984 final long identity = Binder.clearCallingIdentity();
4985 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004986 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004987 // may happen if the device does not support IMS.
4988 return null;
4989 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004990 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004994 }
4995
4996 /**
4997 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4998 * feature during emergency calling or {@link null} if the service is not available. If the
4999 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5000 * listener for feature updates.
5001 */
5002 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5003 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004
5005 final long identity = Binder.clearCallingIdentity();
5006 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005007 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005008 // may happen if the device does not support IMS.
5009 return null;
5010 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005011 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005015 }
5016
Brad Ebinger5f64b052017-12-14 14:26:15 -08005017 /**
5018 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005019 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005020 */
5021 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5022 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023
5024 final long identity = Binder.clearCallingIdentity();
5025 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005026 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005027 // may happen if the device does not support IMS.
5028 return null;
5029 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005030 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031 } finally {
5032 Binder.restoreCallingIdentity(identity);
5033 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005034 }
5035
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005036 /**
5037 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005038 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005039 */
5040 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5041 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042
5043 final long identity = Binder.clearCallingIdentity();
5044 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005045 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005046 // may happen if the device does not support IMS.
5047 return null;
5048 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005049 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050 } finally {
5051 Binder.restoreCallingIdentity(identity);
5052 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005053 }
5054
Brad Ebinger884c07b2018-02-15 16:17:40 -08005055 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005056 * Sets the ImsService Package Name that Telephony will bind to.
5057 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005058 * @param slotIndex the slot ID that the ImsService should bind for.
5059 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005060 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005061 * @param featureTypes An integer array of feature types associated with a packageName.
5062 * @param packageName The name of the package that the current configuration will be replaced
5063 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005064 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005065 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005066 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5067 int[] featureTypes, String packageName) {
5068 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5069 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5071 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005072 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074 final long identity = Binder.clearCallingIdentity();
5075 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005076 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005077 // may happen if the device does not support IMS.
5078 return false;
5079 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005080 Map<Integer, String> featureConfig = new HashMap<>();
5081 for (int featureType : featureTypes) {
5082 featureConfig.put(featureType, packageName);
5083 }
5084 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5085 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 } finally {
5087 Binder.restoreCallingIdentity(identity);
5088 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005089 }
5090
5091 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005092 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005093 *
5094 * @param slotId The slot that the ImsService is associated with.
5095 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5096 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005097 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005098 * @return the package name of the ImsService configuration.
5099 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005100 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5101 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005102 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005103 TelephonyPermissions
5104 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5105 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5106 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005107
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005108 final long identity = Binder.clearCallingIdentity();
5109 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005110 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005111 // may happen if the device does not support IMS.
5112 return "";
5113 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005114 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005115 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5116 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117 } finally {
5118 Binder.restoreCallingIdentity(identity);
5119 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005120 }
5121
Brad Ebinger77b832e2019-10-17 17:03:22 -07005122 /**
5123 * Get the MmTelFeature state associated with the requested subscription id.
5124 * @param subId The subscription that the MmTelFeature is associated with.
5125 * @param callback A callback with an integer containing the
5126 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5127 */
5128 @Override
5129 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5130 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5131 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5132 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5133 "IMS not available on device.");
5134 }
5135 final long token = Binder.clearCallingIdentity();
5136 try {
5137 int slotId = getSlotIndex(subId);
5138 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5139 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5140 + subId + "'");
5141 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5142 }
5143 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5144 try {
5145 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5146 } catch (RemoteException e) {
5147 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5148 + "Ignore");
5149 }
5150 });
5151 } finally {
5152 Binder.restoreCallingIdentity(token);
5153 }
5154 }
5155
Wink Saville36469e72014-06-11 15:17:00 -07005156 public void setImsRegistrationState(boolean registered) {
5157 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158
5159 final long identity = Binder.clearCallingIdentity();
5160 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005161 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 } finally {
5163 Binder.restoreCallingIdentity(identity);
5164 }
Wink Saville36469e72014-06-11 15:17:00 -07005165 }
5166
5167 /**
Stuart Scott54788802015-03-30 13:18:01 -07005168 * Set the network selection mode to automatic.
5169 *
5170 */
5171 @Override
5172 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5174 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005175
5176 final long identity = Binder.clearCallingIdentity();
5177 try {
shilufc958392020-01-20 11:36:01 -08005178 if (!isActiveSubscription(subId)) {
5179 return;
5180 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005181 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5182 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5183 } finally {
5184 Binder.restoreCallingIdentity(identity);
5185 }
Stuart Scott54788802015-03-30 13:18:01 -07005186 }
5187
Pengquan Mengea84e042018-09-20 14:57:26 -07005188 /**
5189 * Ask the radio to connect to the input network and change selection mode to manual.
5190 *
5191 * @param subId the id of the subscription.
5192 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5193 * the operator to attach to.
5194 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5195 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5196 * normal network selection next time.
5197 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005198 */
5199 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005200 public boolean setNetworkSelectionModeManual(
5201 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5203 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005204
5205 if (!isActiveSubscription(subId)) {
5206 return false;
5207 }
5208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005209 final long identity = Binder.clearCallingIdentity();
5210 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005211 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005213 if (DBG) {
5214 log("setNetworkSelectionModeManual: subId: " + subId
5215 + " operator: " + operatorInfo);
5216 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005221 }
5222
5223 /**
5224 * Scans for available networks.
5225 */
5226 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005227 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5228 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5230 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005231 LocationAccessPolicy.LocationPermissionResult locationResult =
5232 LocationAccessPolicy.checkLocationPermission(mApp,
5233 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5234 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005235 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005236 .setCallingPid(Binder.getCallingPid())
5237 .setCallingUid(Binder.getCallingUid())
5238 .setMethod("getCellNetworkScanResults")
5239 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5240 .build());
5241 switch (locationResult) {
5242 case DENIED_HARD:
5243 throw new SecurityException("Not allowed to access scan results -- location");
5244 case DENIED_SOFT:
5245 return null;
5246 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247
Pengquan Menga1bb6272018-09-06 09:59:22 -07005248 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005249 try {
5250 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005251 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005253 } finally {
5254 Binder.restoreCallingIdentity(identity);
5255 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005256 }
5257
5258 /**
sqian80370722020-01-29 15:02:51 -08005259 * Get the call forwarding info, given the call forwarding reason.
5260 */
5261 @Override
5262 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5263 enforceReadPrivilegedPermission("getCallForwarding");
5264 long identity = Binder.clearCallingIdentity();
5265 try {
5266 if (DBG) {
5267 log("getCallForwarding: subId " + subId
5268 + " callForwardingReason" + callForwardingReason);
5269 }
5270 return (CallForwardingInfo) sendRequest(
5271 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5272 } finally {
5273 Binder.restoreCallingIdentity(identity);
5274 }
5275 }
5276
5277 /**
5278 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5279 * reason, the number to forward, and the timeout before the forwarding is attempted.
5280 */
5281 @Override
5282 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5283 enforceModifyPermission();
5284 long identity = Binder.clearCallingIdentity();
5285 try {
5286 if (DBG) {
5287 log("setCallForwarding: subId " + subId
5288 + " callForwardingInfo" + callForwardingInfo);
5289 }
5290 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5291 } finally {
5292 Binder.restoreCallingIdentity(identity);
5293 }
5294 }
5295
5296 /**
5297 * Get the call forwarding info, given the call forwarding reason.
5298 */
5299 @Override
5300 public int getCallWaitingStatus(int subId) {
5301 enforceReadPrivilegedPermission("getCallForwarding");
5302 long identity = Binder.clearCallingIdentity();
5303 try {
5304 if (DBG) log("getCallWaitingStatus: subId " + subId);
5305 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5306 } finally {
5307 Binder.restoreCallingIdentity(identity);
5308 }
5309 }
5310
5311 /**
5312 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5313 * reason, the number to forward, and the timeout before the forwarding is attempted.
5314 */
5315 @Override
5316 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5317 enforceModifyPermission();
5318 long identity = Binder.clearCallingIdentity();
5319 try {
5320 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5321 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5322 } finally {
5323 Binder.restoreCallingIdentity(identity);
5324 }
5325 }
5326
5327 /**
yinxub1bed742017-04-17 11:45:04 -07005328 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005329 *
yinxub1bed742017-04-17 11:45:04 -07005330 * @param subId id of the subscription
5331 * @param request contains the radio access networks with bands/channels to scan
5332 * @param messenger callback messenger for scan results or errors
5333 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005334 * @return the id of the requested scan which can be used to stop the scan.
5335 */
5336 @Override
5337 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005338 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5340 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005341 LocationAccessPolicy.LocationPermissionResult locationResult =
5342 LocationAccessPolicy.checkLocationPermission(mApp,
5343 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5344 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005345 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005346 .setCallingPid(Binder.getCallingPid())
5347 .setCallingUid(Binder.getCallingUid())
5348 .setMethod("requestNetworkScan")
5349 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5350 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005351 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005352 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005353 if (e != null) {
5354 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5355 throw e;
5356 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005357 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005358 return TelephonyScanManager.INVALID_SCAN_ID;
5359 }
5360 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 }
Hall Liu912dfd32019-04-25 14:02:26 -07005362 int callingUid = Binder.getCallingUid();
5363 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005364 final long identity = Binder.clearCallingIdentity();
5365 try {
5366 return mNetworkScanRequestTracker.startNetworkScan(
5367 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005368 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005369 } finally {
5370 Binder.restoreCallingIdentity(identity);
5371 }
yinxu504e1392017-04-12 16:03:22 -07005372 }
5373
Hall Liub2ac8ef2019-02-28 15:56:23 -08005374 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005375 NetworkScanRequest request, int subId) {
5376 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5377 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5378 boolean hasNetworkScanPermission =
5379 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5380 == PERMISSION_GRANTED;
5381
5382 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5383 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5384 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005385 }
5386
5387 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5388 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005389 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5390 return new SecurityException("Specific channels must not be"
5391 + " scanned without location access.");
5392 }
5393 }
5394 }
5395
Hall Liub2ac8ef2019-02-28 15:56:23 -08005396 return null;
5397 }
5398
yinxu504e1392017-04-12 16:03:22 -07005399 /**
5400 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005401 *
5402 * @param subId id of the subscription
5403 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005404 */
5405 @Override
5406 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5408 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005409
Hall Liu912dfd32019-04-25 14:02:26 -07005410 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 final long identity = Binder.clearCallingIdentity();
5412 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005413 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414 } finally {
5415 Binder.restoreCallingIdentity(identity);
5416 }
yinxu504e1392017-04-12 16:03:22 -07005417 }
5418
5419 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005420 * Get the calculated preferred network type.
5421 * Used for debugging incorrect network type.
5422 *
5423 * @return the preferred network type, defined in RILConstants.java.
5424 */
5425 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005426 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005427 final Phone defaultPhone = getDefaultPhone();
5428 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005429 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005430 return RILConstants.PREFERRED_NETWORK_MODE;
5431 }
5432
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433 final long identity = Binder.clearCallingIdentity();
5434 try {
5435 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005436 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 } finally {
5438 Binder.restoreCallingIdentity(identity);
5439 }
Junda Liu84d15a22014-07-02 11:21:04 -07005440 }
5441
5442 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005443 * Get the preferred network type.
5444 * Used for device configuration by some CDMA operators.
5445 *
5446 * @return the preferred network type, defined in RILConstants.java.
5447 */
5448 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005449 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005450 TelephonyPermissions
5451 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5452 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005453
5454 final long identity = Binder.clearCallingIdentity();
5455 try {
5456 if (DBG) log("getPreferredNetworkType");
5457 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5458 int networkType = (result != null ? result[0] : -1);
5459 if (DBG) log("getPreferredNetworkType: " + networkType);
5460 return networkType;
5461 } finally {
5462 Binder.restoreCallingIdentity(identity);
5463 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005464 }
5465
5466 /**
5467 * Set the preferred network type.
5468 * Used for device configuration by some CDMA operators.
5469 *
5470 * @param networkType the preferred network type, defined in RILConstants.java.
5471 * @return true on success; false on any failure.
5472 */
5473 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005474 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5476 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477
5478 final long identity = Binder.clearCallingIdentity();
5479 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005480 Settings.Global.putInt(mApp.getContentResolver(),
5481 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5482 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 } finally {
5484 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005485 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005486 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005487
5488 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005489 * Get the allowed network types that store in the telephony provider.
5490 *
5491 * @param subId the id of the subscription.
5492 * @return allowedNetworkTypes the allowed network types.
5493 */
5494 @Override
5495 public long getAllowedNetworkTypes(int subId) {
5496 TelephonyPermissions
5497 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5498 mApp, subId, "getAllowedNetworkTypes");
5499
5500 final long identity = Binder.clearCallingIdentity();
5501 try {
5502 return SubscriptionManager.getLongSubscriptionProperty(
5503 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5504 } finally {
5505 Binder.restoreCallingIdentity(identity);
5506 }
5507 }
5508
5509 /**
5510 * Set the allowed network types.
5511 *
5512 * @param subId the id of the subscription.
5513 * @param allowedNetworkTypes the allowed network types.
5514 * @return true on success; false on any failure.
5515 */
5516 @Override
5517 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5518 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5519 mApp, subId, "setAllowedNetworkTypes");
5520 final long identity = Binder.clearCallingIdentity();
5521 try {
5522 SubscriptionManager.setSubscriptionProperty(subId,
5523 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5524 String.valueOf(allowedNetworkTypes));
5525 return setPreferredNetworkTypesInternal(subId);
5526 } finally {
5527 Binder.restoreCallingIdentity(identity);
5528 }
5529 }
5530
5531 private boolean setPreferredNetworkTypesInternal(int subId) {
5532 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5533 Settings.Global.getInt(mApp.getContentResolver(),
5534 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5535 RILConstants.PREFERRED_NETWORK_MODE));
5536 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5537 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5538 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5539 (int) (networkTypeBitMask & allowedNetworkTypes));
5540
5541 if (DBG) {
5542 log("setPreferredNetworkTypesInternal: subId " + subId
5543 + " networkTypes " + networkTypeBitMask
5544 + " allowedNetworkTypes " + allowedNetworkTypes
5545 + " networkMode " + networkMode);
5546 }
5547
5548 Boolean success = (Boolean) sendRequest(
5549 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5550 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5551 return success;
5552 }
5553
5554 /**
Miaoa84611c2019-03-15 09:21:10 +08005555 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005556 *
Miaoa84611c2019-03-15 09:21:10 +08005557 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005558 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005559 * @hide
5560 */
5561 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005562 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005563 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005565 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566 try {
Miaoa84611c2019-03-15 09:21:10 +08005567 if (phone != null) {
5568 return phone.hasMatchedTetherApnSetting();
5569 } else {
5570 return false;
5571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005572 } finally {
5573 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005574 }
Junda Liu475951f2014-11-07 16:45:03 -08005575 }
5576
5577 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005578 * Set mobile data enabled
5579 * Used by the user through settings etc to turn on/off mobile data
5580 *
5581 * @param enable {@code true} turn turn data on, else {@code false}
5582 */
5583 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005584 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5586 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587
5588 final long identity = Binder.clearCallingIdentity();
5589 try {
5590 int phoneId = mSubscriptionController.getPhoneId(subId);
5591 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5592 Phone phone = PhoneFactory.getPhone(phoneId);
5593 if (phone != null) {
5594 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005595 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005597 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598 }
5599 } finally {
5600 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005601 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005602 }
5603
5604 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005605 * Enable or disable always reporting signal strength changes from radio.
5606 *
5607 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5608 */
5609 @Override
5610 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5611 enforceModifyPermission();
5612 enforceSystemCaller();
5613
5614 final long identity = Binder.clearCallingIdentity();
5615 final Phone phone = getPhone(subId);
5616 try {
5617 if (phone != null) {
5618 if (DBG) {
5619 log("setAlwaysReportSignalStrength: subId=" + subId
5620 + " isEnable=" + isEnable);
5621 }
5622 phone.setAlwaysReportSignalStrength(isEnable);
5623 } else {
5624 loge("setAlwaysReportSignalStrength: no phone found for subId="
5625 + subId);
5626 }
5627 } finally {
5628 Binder.restoreCallingIdentity(identity);
5629 }
5630 }
5631
5632 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005633 * Get the user enabled state of Mobile Data.
5634 *
5635 * TODO: remove and use isUserDataEnabled.
5636 * This can't be removed now because some vendor codes
5637 * calls through ITelephony directly while they should
5638 * use TelephonyManager.
5639 *
5640 * @return true on enabled
5641 */
5642 @Override
5643 public boolean getDataEnabled(int subId) {
5644 return isUserDataEnabled(subId);
5645 }
5646
5647 /**
5648 * Get whether mobile data is enabled per user setting.
5649 *
5650 * There are other factors deciding whether mobile data is actually enabled, but they are
5651 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005652 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005653 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005654 *
5655 * @return {@code true} if data is enabled else {@code false}
5656 */
5657 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005658 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005659 try {
5660 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5661 null);
5662 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5664 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005665 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666
5667 final long identity = Binder.clearCallingIdentity();
5668 try {
5669 int phoneId = mSubscriptionController.getPhoneId(subId);
5670 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5671 Phone phone = PhoneFactory.getPhone(phoneId);
5672 if (phone != null) {
5673 boolean retVal = phone.isUserDataEnabled();
5674 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5675 return retVal;
5676 } else {
5677 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5678 return false;
5679 }
5680 } finally {
5681 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005682 }
5683 }
5684
5685 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005686 * Checks if the device is capable of mobile data by considering whether whether the
5687 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5688 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005689 *
Shuo Qian985d1232020-01-08 14:30:06 -08005690 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005691 */
5692 @Override
5693 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005694 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695
5696 final long identity = Binder.clearCallingIdentity();
5697 try {
5698 int phoneId = mSubscriptionController.getPhoneId(subId);
5699 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5700 Phone phone = PhoneFactory.getPhone(phoneId);
5701 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005702 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5704 return retVal;
5705 } else {
5706 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5707 return false;
5708 }
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005711 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005712 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005713
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005714 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5715 Phone phone) {
5716 //load access rules from carrier configs, and check those as well: b/139133814
5717 SubscriptionController subController = SubscriptionController.getInstance();
5718 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5719 || subController == null) return privilegeFromSim;
5720
5721 int uid = Binder.getCallingUid();
5722 PackageManager pkgMgr = phone.getContext().getPackageManager();
5723 String[] packages = pkgMgr.getPackagesForUid(uid);
5724
5725 final long identity = Binder.clearCallingIdentity();
5726 try {
5727 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5728 SubscriptionManager subManager = (SubscriptionManager)
5729 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5730 for (String pkg : packages) {
5731 if (subManager.canManageSubscription(subInfo, pkg)) {
5732 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5733 }
5734 }
5735 return privilegeFromSim;
5736 } finally {
5737 Binder.restoreCallingIdentity(identity);
5738 }
5739 }
5740
5741 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5742 String pkgName) {
5743 //load access rules from carrier configs, and check those as well: b/139133814
5744 SubscriptionController subController = SubscriptionController.getInstance();
5745 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5746 || subController == null) return privilegeFromSim;
5747
5748 final long identity = Binder.clearCallingIdentity();
5749 try {
5750 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5751 SubscriptionManager subManager = (SubscriptionManager)
5752 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5753 return subManager.canManageSubscription(subInfo, pkgName)
5754 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5755 } finally {
5756 Binder.restoreCallingIdentity(identity);
5757 }
5758 }
5759
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005760 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005761 public int getCarrierPrivilegeStatus(int subId) {
5762 final Phone phone = getPhone(subId);
5763 if (phone == null) {
5764 loge("getCarrierPrivilegeStatus: Invalid subId");
5765 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5766 }
5767 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005768 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005769 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005770 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5771 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005772
5773 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5774 card.getCarrierPrivilegeStatusForCurrentTransaction(
5775 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005776 }
Junda Liu29340342014-07-10 15:23:27 -07005777
5778 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005779 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005780 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005781 final Phone phone = getPhone(subId);
5782 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005783 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005784 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5785 }
5786 UiccProfile profile =
5787 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5788 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005789 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005790 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5791 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005792 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005793 profile.getCarrierPrivilegeStatusForUid(
5794 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005795 }
5796
5797 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005798 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5799 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005800 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005801 }
5802
5803 int phoneId = SubscriptionManager.getPhoneId(subId);
5804 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005805 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005806 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005807 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5808 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005809 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5810 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5811 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005812 }
5813
5814 @Override
5815 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005816 if (TextUtils.isEmpty(pkgName))
5817 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005818 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5819 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5820 UiccCard card = UiccController.getInstance().getUiccCard(i);
5821 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005822 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005823 continue;
5824 }
5825
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005826 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5827 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5828 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005829 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5830 break;
5831 }
5832 }
5833
5834 return result;
Junda Liu29340342014-07-10 15:23:27 -07005835 }
Derek Tan89e89d42014-07-08 17:00:10 -07005836
5837 @Override
Junda Liue64de782015-04-16 17:19:16 -07005838 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5839 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5840 loge("phoneId " + phoneId + " is not valid.");
5841 return null;
5842 }
5843 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005844 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005845 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005846 return null ;
5847 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005848 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005849 }
5850
Amith Yamasani6e118872016-02-19 12:53:51 -08005851 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005852 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005853 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005854 List<String> privilegedPackages = new ArrayList<>();
5855 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005856 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5857 // has UICC in that slot.
5858 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005859 if (card.hasCarrierPrivilegeRules()) {
5860 if (packages == null) {
5861 // Only check packages in user 0 for now
5862 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005863 PackageManager.MATCH_DISABLED_COMPONENTS
5864 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005865 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005866 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005867 }
5868 for (int p = packages.size() - 1; p >= 0; p--) {
5869 PackageInfo pkgInfo = packages.get(p);
5870 if (pkgInfo != null && pkgInfo.packageName != null
5871 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005872 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005873 privilegedPackages.add(pkgInfo.packageName);
5874 }
5875 }
5876 }
5877 }
5878 return privilegedPackages;
5879 }
5880
chen xuf7e9fe82019-05-09 19:31:02 -07005881 @Override
5882 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005883 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5884
5885 final long identity = Binder.clearCallingIdentity();
5886
chen xuf7e9fe82019-05-09 19:31:02 -07005887 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005888 try {
5889 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5890 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5891 }
5892 } finally {
5893 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005894 }
5895 return privilegedPackages;
5896 }
5897
Wink Savilleb564aae2014-10-23 10:18:09 -07005898 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005899 final Phone phone = getPhone(subId);
5900 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005901 if (card == null) {
5902 loge("getIccId: No UICC");
5903 return null;
5904 }
5905 String iccId = card.getIccId();
5906 if (TextUtils.isEmpty(iccId)) {
5907 loge("getIccId: ICC ID is null or empty.");
5908 return null;
5909 }
5910 return iccId;
5911 }
5912
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005913 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005914 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5915 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005916 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005917 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005918
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919 final long identity = Binder.clearCallingIdentity();
5920 try {
5921 final String iccId = getIccId(subId);
5922 final Phone phone = getPhone(subId);
5923 if (phone == null) {
5924 return false;
5925 }
5926 final String subscriberId = phone.getSubscriberId();
5927
5928 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005929 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005930 + subscriberId + " to " + number);
5931 }
5932
5933 if (TextUtils.isEmpty(iccId)) {
5934 return false;
5935 }
5936
5937 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5938
5939 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5940 if (alphaTag == null) {
5941 editor.remove(alphaTagPrefKey);
5942 } else {
5943 editor.putString(alphaTagPrefKey, alphaTag);
5944 }
5945
5946 // Record both the line number and IMSI for this ICCID, since we need to
5947 // track all merged IMSIs based on line number
5948 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5949 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5950 if (number == null) {
5951 editor.remove(numberPrefKey);
5952 editor.remove(subscriberPrefKey);
5953 } else {
5954 editor.putString(numberPrefKey, number);
5955 editor.putString(subscriberPrefKey, subscriberId);
5956 }
5957
5958 editor.commit();
5959 return true;
5960 } finally {
5961 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005962 }
Derek Tan7226c842014-07-02 17:42:23 -07005963 }
5964
5965 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005966 public String getLine1NumberForDisplay(int subId, String callingPackage,
5967 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005968 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005970 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005971 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005972 return null;
5973 }
Derek Tan97ebb422014-09-05 16:55:38 -07005974
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975 final long identity = Binder.clearCallingIdentity();
5976 try {
5977 String iccId = getIccId(subId);
5978 if (iccId != null) {
5979 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5980 if (DBG_MERGE) {
5981 log("getLine1NumberForDisplay returning "
5982 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5983 }
5984 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5987 return null;
5988 } finally {
5989 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005990 }
Derek Tan7226c842014-07-02 17:42:23 -07005991 }
5992
5993 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005994 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5995 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005996 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005997 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005998 return null;
5999 }
Derek Tan97ebb422014-09-05 16:55:38 -07006000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 final long identity = Binder.clearCallingIdentity();
6002 try {
6003 String iccId = getIccId(subId);
6004 if (iccId != null) {
6005 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6006 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6007 }
6008 return null;
6009 } finally {
6010 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006011 }
Derek Tan7226c842014-07-02 17:42:23 -07006012 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006013
6014 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006015 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6016 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006017 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6018 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006019 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006020 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006021 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006022 return null;
6023 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006024
Jordan Liub49b04b2019-05-06 14:45:15 -07006025 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6026 // the process, where TelephonyManager was instantiated.
6027 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006028 final long identity = Binder.clearCallingIdentity();
6029 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006030 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 final TelephonyManager tele = TelephonyManager.from(context);
6032 final SubscriptionManager sub = SubscriptionManager.from(context);
6033
6034 // Figure out what subscribers are currently active
6035 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036
Jordan Liub49b04b2019-05-06 14:45:15 -07006037 // Only consider subs which match the current subId
6038 // This logic can be simplified. See b/131189269 for progress.
6039 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006040 activeSubscriberIds.add(tele.getSubscriberId(subId));
6041 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042
6043 // First pass, find a number override for an active subscriber
6044 String mergeNumber = null;
6045 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6046 for (String key : prefs.keySet()) {
6047 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6048 final String subscriberId = (String) prefs.get(key);
6049 if (activeSubscriberIds.contains(subscriberId)) {
6050 final String iccId = key.substring(
6051 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6052 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6053 mergeNumber = (String) prefs.get(numberKey);
6054 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006055 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056 + " for active subscriber " + subscriberId);
6057 }
6058 if (!TextUtils.isEmpty(mergeNumber)) {
6059 break;
6060 }
6061 }
6062 }
6063 }
6064
6065 // Shortcut when no active merged subscribers
6066 if (TextUtils.isEmpty(mergeNumber)) {
6067 return null;
6068 }
6069
6070 // Second pass, find all subscribers under that line override
6071 final ArraySet<String> result = new ArraySet<>();
6072 for (String key : prefs.keySet()) {
6073 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6074 final String number = (String) prefs.get(key);
6075 if (mergeNumber.equals(number)) {
6076 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6077 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6078 final String subscriberId = (String) prefs.get(subscriberKey);
6079 if (!TextUtils.isEmpty(subscriberId)) {
6080 result.add(subscriberId);
6081 }
6082 }
6083 }
6084 }
6085
6086 final String[] resultArray = result.toArray(new String[result.size()]);
6087 Arrays.sort(resultArray);
6088 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006089 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6091 }
6092 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006093 } finally {
6094 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006095 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006096 }
6097
6098 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006099 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6100 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6101
6102 final long identity = Binder.clearCallingIdentity();
6103 try {
6104 final TelephonyManager telephonyManager = mApp.getSystemService(
6105 TelephonyManager.class);
6106 String subscriberId = telephonyManager.getSubscriberId(subId);
6107 if (subscriberId == null) {
6108 if (DBG) {
6109 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6110 + subId);
6111 }
6112 return null;
6113 }
6114
6115 final SubscriptionInfo info = SubscriptionController.getInstance()
6116 .getSubscriptionInfo(subId);
6117 final ParcelUuid groupUuid = info.getGroupUuid();
6118 // If it doesn't belong to any group, return just subscriberId of itself.
6119 if (groupUuid == null) {
6120 return new String[]{subscriberId};
6121 }
6122
6123 // Get all subscriberIds from the group.
6124 final List<String> mergedSubscriberIds = new ArrayList<>();
6125 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006126 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6127 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006128 for (SubscriptionInfo subInfo : groupInfos) {
6129 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6130 if (subscriberId != null) {
6131 mergedSubscriberIds.add(subscriberId);
6132 }
6133 }
6134
6135 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138
6139 }
6140 }
6141
6142 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006143 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006144 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006145 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006146
6147 final long identity = Binder.clearCallingIdentity();
6148 try {
6149 final Phone phone = getPhone(subId);
6150 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6151 } finally {
6152 Binder.restoreCallingIdentity(identity);
6153 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006154 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006155
6156 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006157 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006158 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6159 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006160 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6161 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162
6163 final long identity = Binder.clearCallingIdentity();
6164 try {
6165 final Phone phone = getPhone(subId);
6166 if (phone == null) {
6167 return false;
6168 }
6169 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6170 cdmaNonRoamingList);
6171 } finally {
6172 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006173 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006174 }
6175
6176 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006177 @Deprecated
6178 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6179 enforceModifyPermission();
6180
6181 int returnValue = 0;
6182 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006183 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006184 if(result.exception == null) {
6185 if (result.result != null) {
6186 byte[] responseData = (byte[])(result.result);
6187 if(responseData.length > oemResp.length) {
6188 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6189 responseData.length + "bytes. Buffer Size is " +
6190 oemResp.length + "bytes.");
6191 }
6192 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6193 returnValue = responseData.length;
6194 }
6195 } else {
6196 CommandException ex = (CommandException) result.exception;
6197 returnValue = ex.getCommandError().ordinal();
6198 if(returnValue > 0) returnValue *= -1;
6199 }
6200 } catch (RuntimeException e) {
6201 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6202 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6203 if(returnValue > 0) returnValue *= -1;
6204 }
6205
6206 return returnValue;
6207 }
6208
6209 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006210 public void setRadioCapability(RadioAccessFamily[] rafs) {
6211 try {
6212 ProxyController.getInstance().setRadioCapability(rafs);
6213 } catch (RuntimeException e) {
6214 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6215 }
6216 }
6217
6218 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006219 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006220 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006221 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006222 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006223 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006224 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006225 final long identity = Binder.clearCallingIdentity();
6226 try {
chen xub97461a2018-10-26 14:17:57 -07006227 TelephonyPermissions
6228 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6229 mApp, phone.getSubId(), "getRadioAccessFamily");
6230 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231 } finally {
6232 Binder.restoreCallingIdentity(identity);
6233 }
chen xub97461a2018-10-26 14:17:57 -07006234 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006235 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006236
6237 @Override
6238 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006239 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006240 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241
6242 final long identity = Binder.clearCallingIdentity();
6243 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006244 ImsManager.getInstance(defaultPhone.getContext(),
6245 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006246 } finally {
6247 Binder.restoreCallingIdentity(identity);
6248 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006249 }
6250
6251 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006252 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006253 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006254 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6255 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006256 return false;
6257 }
Svet Ganovb320e182015-04-16 12:30:10 -07006258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 final long identity = Binder.clearCallingIdentity();
6260 try {
6261 // Check the user preference and the system-level IMS setting. Even if the user has
6262 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6263 // In the long run, we may instead need to check if there exists a connection service
6264 // which can support video calling.
6265 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006266 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 return imsManager.isVtEnabledByPlatform()
6268 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6269 && imsManager.isVtEnabledByUser();
6270 } finally {
6271 Binder.restoreCallingIdentity(identity);
6272 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006273 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006274
Andrew Leea1239f22015-03-02 17:44:07 -08006275 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006276 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6277 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006279 mApp, subId, callingPackage, callingFeatureId,
6280 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006281 return false;
6282 }
6283
6284 final long identity = Binder.clearCallingIdentity();
6285 try {
6286 CarrierConfigManager configManager =
6287 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006288 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6290 } finally {
6291 Binder.restoreCallingIdentity(identity);
6292 }
Andrew Leea1239f22015-03-02 17:44:07 -08006293 }
6294
6295 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006296 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006298 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 return false;
6300 }
6301
6302 final long identity = Binder.clearCallingIdentity();
6303 try {
6304 CarrierConfigManager configManager =
6305 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006306 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006307 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6308 } finally {
6309 Binder.restoreCallingIdentity(identity);
6310 }
Andrew Leea1239f22015-03-02 17:44:07 -08006311 }
6312
Andrew Lee9431b832015-03-09 18:46:45 -07006313 @Override
6314 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006315 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006316 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006317 }
6318
6319 @Override
6320 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321 final long identity = Binder.clearCallingIdentity();
6322 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006323 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324 } finally {
6325 Binder.restoreCallingIdentity(identity);
6326 }
Andrew Lee9431b832015-03-09 18:46:45 -07006327 }
6328
Hall Liuf6668912018-10-31 17:05:23 -07006329 /**
6330 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6331 * support for the feature and device firmware support.
6332 *
6333 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6334 */
6335 @Override
6336 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006338 final Phone phone = getPhone(subscriptionId);
6339 if (phone == null) {
6340 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6341 return false;
6342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006344 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6346 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006347 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006348 return isCarrierSupported && isDeviceSupported;
6349 } finally {
6350 Binder.restoreCallingIdentity(identity);
6351 }
Hall Liu98187582018-01-22 19:15:32 -08006352 }
6353
Hall Liuf6668912018-10-31 17:05:23 -07006354 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006355 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6356 * RTT setting, will return true if the device and carrier both support RTT.
6357 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006358 */
6359 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360 final long identity = Binder.clearCallingIdentity();
6361 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006362 boolean isRttSupported = isRttSupported(subscriptionId);
6363 boolean isUserRttSettingOn = Settings.Secure.getInt(
6364 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6365 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6366 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6367 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 } finally {
6369 Binder.restoreCallingIdentity(identity);
6370 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006371 }
6372
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006373 @Deprecated
6374 @Override
6375 public String getDeviceId(String callingPackage) {
6376 return getDeviceIdWithFeature(callingPackage, null);
6377 }
6378
Sanket Padawe7310cc72015-01-14 09:53:20 -08006379 /**
6380 * Returns the unique device ID of phone, for example, the IMEI for
6381 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6382 *
6383 * <p>Requires Permission:
6384 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6385 */
6386 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006387 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006388 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006389 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006390 return null;
6391 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006392 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006393 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006394 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006395 return null;
6396 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397
6398 final long identity = Binder.clearCallingIdentity();
6399 try {
6400 return phone.getDeviceId();
6401 } finally {
6402 Binder.restoreCallingIdentity(identity);
6403 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006404 }
6405
Ping Sunc67b7c22016-03-02 19:16:45 +08006406 /**
6407 * {@hide}
6408 * Returns the IMS Registration Status on a particular subid
6409 *
6410 * @param subId
6411 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006412 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006413 Phone phone = getPhone(subId);
6414 if (phone != null) {
6415 return phone.isImsRegistered();
6416 } else {
6417 return false;
6418 }
6419 }
6420
Santos Cordon7a1885b2015-02-03 11:15:19 -08006421 @Override
6422 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006423 final long identity = Binder.clearCallingIdentity();
6424 try {
6425 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6426 } finally {
6427 Binder.restoreCallingIdentity(identity);
6428 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006429 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006430
Tyler Gunnf70ed162019-04-03 15:28:53 -07006431 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006432 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006433 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006434 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006435 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006436 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6437 }
6438 final long identity = Binder.clearCallingIdentity();
6439 try {
6440 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6441 } finally {
6442 Binder.restoreCallingIdentity(identity);
6443 }
6444 }
6445
6446 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006447 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6448 final long identity = Binder.clearCallingIdentity();
6449 try {
6450 Phone phone = getPhone(subscriptionId);
6451 if (phone == null) {
6452 return null;
6453 }
6454 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6455 } finally {
6456 Binder.restoreCallingIdentity(identity);
6457 }
6458 }
6459
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006460 /**
6461 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006462 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006463 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006464 final long identity = Binder.clearCallingIdentity();
6465 try {
6466 Phone phone = getPhone(subId);
6467 if (phone != null) {
6468 return phone.isWifiCallingEnabled();
6469 } else {
6470 return false;
6471 }
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006474 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006475 }
6476
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006477 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006478 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006479 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006480 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481 final long identity = Binder.clearCallingIdentity();
6482 try {
6483 Phone phone = getPhone(subId);
6484 if (phone != null) {
6485 return phone.isVideoEnabled();
6486 } else {
6487 return false;
6488 }
6489 } finally {
6490 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006491 }
6492 }
6493
6494 /**
6495 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6496 * defined in {@link ImsRegistrationImplBase}.
6497 */
6498 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006499 final long identity = Binder.clearCallingIdentity();
6500 try {
6501 Phone phone = getPhone(subId);
6502 if (phone != null) {
6503 return phone.getImsRegistrationTech();
6504 } else {
6505 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6506 }
6507 } finally {
6508 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006509 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006510 }
6511
Stuart Scott8eef64f2015-04-08 15:13:54 -07006512 @Override
6513 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006514 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006515 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6516 return;
6517 }
6518
Svet Ganovcc087f82015-05-12 20:35:54 -07006519 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006520
Svet Ganovcc087f82015-05-12 20:35:54 -07006521 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006522 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6523 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006524 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006525 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006526 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006527 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6528 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006529 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006530 // There has been issues when Sms raw table somehow stores orphan
6531 // fragments. They lead to garbled message when new fragments come
6532 // in and combined with those stale ones. In case this happens again,
6533 // user can reset all network settings which will clean up this table.
6534 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006535 // Clean up IMS settings as well here.
6536 int slotId = getSlotIndex(subId);
6537 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6538 ImsManager.getInstance(mApp, slotId).factoryReset();
6539 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006540
6541 // Erase modem config if erase modem on network setting is enabled.
6542 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6543 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6544 if (configValue != null && Boolean.parseBoolean(configValue)) {
6545 sendEraseModemConfig(getDefaultPhone());
6546 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006547 } finally {
6548 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006549 }
6550 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006551
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006552 private void cleanUpSmsRawTable(Context context) {
6553 ContentResolver resolver = context.getContentResolver();
6554 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6555 resolver.delete(uri, null, null);
6556 }
6557
Narayan Kamath1c496c22015-04-16 14:40:19 +01006558 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006559 public String getSimLocaleForSubscriber(int subId) {
6560 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6561 final Phone phone = getPhone(subId);
6562 if (phone == null) {
6563 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006564 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006565 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006566 final long identity = Binder.clearCallingIdentity();
6567 try {
chen xu5d3637b2019-01-21 23:31:38 -08006568 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006569 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006570 if (info == null) {
6571 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6572 return null;
6573 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574 // Try and fetch the locale from the carrier properties or from the SIM language
6575 // preferences (EF-PL and EF-LI)...
6576 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006577 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006578 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6579 if (localeFromDefaultSim != null) {
6580 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6581 if (DBG) log("Using locale from subId: " + subId + " locale: "
6582 + localeFromDefaultSim);
6583 return localeFromDefaultSim.toLanguageTag();
6584 } else {
6585 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586 }
6587 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589 // The SIM language preferences only store a language (e.g. fr = French), not an
6590 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6591 // the SIM and carrier preferences does not include a country we add the country
6592 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006593 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006594 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006595 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006596 return mccLocale.toLanguageTag();
6597 }
6598
6599 if (DBG) log("No locale found - returning null");
6600 return null;
6601 } finally {
6602 Binder.restoreCallingIdentity(identity);
6603 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006604 }
6605
6606 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006607 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6608 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006609 }
6610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006611 /**
6612 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6613 */
6614 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006615 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6616 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006617 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006618
Chenjie Yu1ba97252018-01-11 18:16:20 -08006619 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006620 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006621
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006622 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006623 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6624 * representing the state of the modem.
6625 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006626 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6627 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006628 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006629 */
6630 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006631 public void requestModemActivityInfo(ResultReceiver result) {
6632 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006633 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634
6635 final long identity = Binder.clearCallingIdentity();
6636 try {
sqian1a1be542020-03-05 11:37:28 -08006637 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006638 } finally {
6639 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006640 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006641 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006642
Siddharth Rayb8114062018-06-17 15:02:38 -07006643 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6644 // less than total activity duration.
6645 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6646 if (info == null) {
6647 return false;
6648 }
6649 int activityDurationMs =
6650 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6651 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006652 int[] txTimeMs = info.getTransmitTimeMillis();
6653 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6654 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006655 }
6656 return (info.isValid()
6657 && (info.getSleepTimeMillis() <= activityDurationMs)
6658 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006659 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006660 && (totalTxTimeMs <= activityDurationMs));
6661 }
6662
Jack Yu85bd38a2015-11-09 11:34:32 -08006663 /**
6664 * {@hide}
6665 * Returns the service state information on specified subscription.
6666 */
6667 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006668 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6669 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006670 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006671 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006672 return null;
6673 }
6674
Hall Liuf19c44f2018-11-27 14:38:17 -08006675 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6676 LocationAccessPolicy.checkLocationPermission(mApp,
6677 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6678 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006679 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006680 .setCallingPid(Binder.getCallingPid())
6681 .setCallingUid(Binder.getCallingUid())
6682 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006683 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006684 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6685 .build());
6686
6687 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6688 LocationAccessPolicy.checkLocationPermission(mApp,
6689 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6690 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006691 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006692 .setCallingPid(Binder.getCallingPid())
6693 .setCallingUid(Binder.getCallingUid())
6694 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006695 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006696 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6697 .build());
6698 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6699 boolean hasFinePermission =
6700 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6701 boolean hasCoarsePermission =
6702 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6703
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006704 final long identity = Binder.clearCallingIdentity();
6705 try {
6706 final Phone phone = getPhone(subId);
6707 if (phone == null) {
6708 return null;
6709 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006710
Hall Liuf19c44f2018-11-27 14:38:17 -08006711 ServiceState ss = phone.getServiceState();
6712
6713 // Scrub out the location info in ServiceState depending on what level of access
6714 // the caller has.
6715 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006716 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6717 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718 } finally {
6719 Binder.restoreCallingIdentity(identity);
6720 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006721 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006722
6723 /**
6724 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6725 *
6726 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6727 * voicemail ringtone.
6728 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6729 * PhoneAccount.
6730 */
6731 @Override
6732 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733 final long identity = Binder.clearCallingIdentity();
6734 try {
6735 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6736 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006737 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6741 } finally {
6742 Binder.restoreCallingIdentity(identity);
6743 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006744 }
6745
6746 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006747 * Sets the per-account voicemail ringtone.
6748 *
6749 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6750 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6751 *
6752 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6753 * voicemail ringtone.
6754 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6755 * PhoneAccount.
6756 */
6757 @Override
6758 public void setVoicemailRingtoneUri(String callingPackage,
6759 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006760 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006761 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006762 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6763 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6765 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6766 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006768
6769 final long identity = Binder.clearCallingIdentity();
6770 try {
6771 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6772 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006773 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006774 }
6775 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6776 } finally {
6777 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006778 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006779 }
6780
6781 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006782 * Returns whether vibration is set for voicemail notification in Phone settings.
6783 *
6784 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6785 * voicemail vibration setting.
6786 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6787 */
6788 @Override
6789 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006790 final long identity = Binder.clearCallingIdentity();
6791 try {
6792 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6793 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006794 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006795 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006797 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6798 } finally {
6799 Binder.restoreCallingIdentity(identity);
6800 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006801 }
6802
Youhan Wange64578a2016-05-02 15:32:42 -07006803 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006804 * Sets the per-account voicemail vibration.
6805 *
6806 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6807 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6808 *
6809 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6810 * voicemail vibration setting.
6811 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6812 * specific PhoneAccount.
6813 */
6814 @Override
6815 public void setVoicemailVibrationEnabled(String callingPackage,
6816 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006817 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006818 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006819 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6820 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6822 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6823 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006824 }
6825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006826 final long identity = Binder.clearCallingIdentity();
6827 try {
6828 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6829 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006830 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831 }
6832 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6833 } finally {
6834 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006835 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006836 }
6837
6838 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006839 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6840 *
6841 * @throws SecurityException if the caller does not have the required permission
6842 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006843 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006844 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006845 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006846 }
6847
6848 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006849 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6850 * permission.
6851 *
6852 * @throws SecurityException if the caller does not have the required permission
6853 */
6854 private void enforceSendSmsPermission() {
6855 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6856 }
6857
6858 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006859 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006860 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006861 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006862 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006863 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006864 final long identity = Binder.clearCallingIdentity();
6865 try {
6866 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006867 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868 if (componentName == null) {
6869 throw new SecurityException(
6870 "Caller not current active visual voicemail package[null]");
6871 }
6872 String vvmPackage = componentName.getPackageName();
6873 if (!callingPackage.equals(vvmPackage)) {
6874 throw new SecurityException("Caller not current active visual voicemail package["
6875 + vvmPackage + "]");
6876 }
6877 } finally {
6878 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006879 }
6880 }
6881
6882 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006883 * Return the application ID for the app type.
6884 *
6885 * @param subId the subscription ID that this request applies to.
6886 * @param appType the uicc app type.
6887 * @return Application ID for specificied app type, or null if no uicc.
6888 */
6889 @Override
6890 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006891 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006892 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006893
6894 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006895 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006896 if (phone == null) {
6897 return null;
6898 }
6899 String aid = null;
6900 try {
6901 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6902 .getApplicationByType(appType).getAid();
6903 } catch (Exception e) {
6904 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6905 }
6906 return aid;
6907 } finally {
6908 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006909 }
Youhan Wange64578a2016-05-02 15:32:42 -07006910 }
6911
Youhan Wang4001d252016-05-11 10:29:41 -07006912 /**
6913 * Return the Electronic Serial Number.
6914 *
6915 * @param subId the subscription ID that this request applies to.
6916 * @return ESN or null if error.
6917 */
6918 @Override
6919 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006920 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006921 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006922
6923 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006924 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006925 if (phone == null) {
6926 return null;
6927 }
6928 String esn = null;
6929 try {
6930 esn = phone.getEsn();
6931 } catch (Exception e) {
6932 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6933 }
6934 return esn;
6935 } finally {
6936 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006937 }
Youhan Wang4001d252016-05-11 10:29:41 -07006938 }
6939
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006940 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006941 * Return the Preferred Roaming List Version.
6942 *
6943 * @param subId the subscription ID that this request applies to.
6944 * @return PRLVersion or null if error.
6945 */
6946 @Override
6947 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006948 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006949 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950
6951 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006952 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006953 if (phone == null) {
6954 return null;
6955 }
6956 String cdmaPrlVersion = null;
6957 try {
6958 cdmaPrlVersion = phone.getCdmaPrlVersion();
6959 } catch (Exception e) {
6960 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6961 }
6962 return cdmaPrlVersion;
6963 } finally {
6964 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006965 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006966 }
6967
6968 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006969 * Get snapshot of Telephony histograms
6970 * @return List of Telephony histograms
6971 * @hide
6972 */
6973 @Override
6974 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6976 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006977
6978 final long identity = Binder.clearCallingIdentity();
6979 try {
6980 return RIL.getTelephonyRILTimingHistograms();
6981 } finally {
6982 Binder.restoreCallingIdentity(identity);
6983 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006984 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006985
6986 /**
6987 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006988 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6989 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006990 * Require system privileges. In the future we may add this to carrier APIs.
6991 *
Michele Berionne482f8202018-11-27 18:57:59 -08006992 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006993 */
6994 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006995 @TelephonyManager.SetCarrierRestrictionResult
6996 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006997 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006998 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006999
Michele Berionne482f8202018-11-27 18:57:59 -08007000 if (carrierRestrictionRules == null) {
7001 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007002 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004 final long identity = Binder.clearCallingIdentity();
7005 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007006 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007007 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 } finally {
7009 Binder.restoreCallingIdentity(identity);
7010 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007011 }
7012
7013 /**
7014 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007015 * Get the allowed carrier list and the excluded carrier list, including the priority between
7016 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007017 * Require system privileges. In the future we may add this to carrier APIs.
7018 *
Michele Berionne482f8202018-11-27 18:57:59 -08007019 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007020 */
7021 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007022 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007023 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007024 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007025
7026 final long identity = Binder.clearCallingIdentity();
7027 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007028 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7029 if (response instanceof CarrierRestrictionRules) {
7030 return (CarrierRestrictionRules) response;
7031 }
7032 // Response is an Exception of some kind,
7033 // which is signalled to the user as a NULL retval
7034 return null;
7035 } catch (Exception e) {
7036 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7037 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007038 } finally {
7039 Binder.restoreCallingIdentity(identity);
7040 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007041 }
7042
fionaxu59545b42016-05-25 15:53:37 -07007043 /**
7044 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7045 * @param subId the subscription ID that this action applies to.
7046 * @param enabled control enable or disable metered apns.
7047 * {@hide}
7048 */
7049 @Override
7050 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7051 enforceModifyPermission();
7052 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053
7054 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007055 if (phone == null) {
7056 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7057 return;
7058 }
7059 try {
7060 phone.carrierActionSetMeteredApnsEnabled(enabled);
7061 } catch (Exception e) {
7062 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007063 } finally {
7064 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007065 }
7066 }
7067
7068 /**
7069 * Action set from carrier signalling broadcast receivers to enable/disable radio
7070 * @param subId the subscription ID that this action applies to.
7071 * @param enabled control enable or disable radio.
7072 * {@hide}
7073 */
7074 @Override
7075 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7076 enforceModifyPermission();
7077 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007078
7079 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007080 if (phone == null) {
7081 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7082 return;
7083 }
7084 try {
7085 phone.carrierActionSetRadioEnabled(enabled);
7086 } catch (Exception e) {
7087 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007088 } finally {
7089 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007090 }
7091 }
7092
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007093 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007094 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7095 * network status based on which carrier apps could apply actions accordingly,
7096 * enable/disable default url handler for example.
7097 *
7098 * @param subId the subscription ID that this action applies to.
7099 * @param report control start/stop reporting the default network status.
7100 * {@hide}
7101 */
7102 @Override
7103 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7104 enforceModifyPermission();
7105 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106
7107 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007108 if (phone == null) {
7109 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7110 return;
7111 }
7112 try {
7113 phone.carrierActionReportDefaultNetworkStatus(report);
7114 } catch (Exception e) {
7115 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116 } finally {
7117 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007118 }
7119 }
7120
7121 /**
fionaxud9622282017-07-17 17:51:30 -07007122 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7123 * @param subId the subscription ID that this action applies to.
7124 * {@hide}
7125 */
7126 @Override
7127 public void carrierActionResetAll(int subId) {
7128 enforceModifyPermission();
7129 final Phone phone = getPhone(subId);
7130 if (phone == null) {
7131 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7132 return;
7133 }
7134 try {
7135 phone.carrierActionResetAll();
7136 } catch (Exception e) {
7137 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7138 }
7139 }
7140
7141 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007142 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7143 * bug report is being generated.
7144 */
7145 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007146 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007147 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7148 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007149 writer.println("Permission Denial: can't dump Phone from pid="
7150 + Binder.getCallingPid()
7151 + ", uid=" + Binder.getCallingUid()
7152 + "without permission "
7153 + android.Manifest.permission.DUMP);
7154 return;
7155 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007156 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007157 }
Jack Yueb89b242016-06-22 13:27:47 -07007158
Brad Ebingerdac2f002018-04-03 15:17:52 -07007159 @Override
7160 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7161 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7162 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007163 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7164 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007165 }
7166
Jack Yueb89b242016-06-22 13:27:47 -07007167 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007168 * Policy control of data connection. Usually used when data limit is passed.
7169 * @param enabled True if enabling the data, otherwise disabling.
7170 * @param subId Subscription index
7171 * {@hide}
7172 */
7173 @Override
7174 public void setPolicyDataEnabled(boolean enabled, int subId) {
7175 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007176
7177 final long identity = Binder.clearCallingIdentity();
7178 try {
7179 Phone phone = getPhone(subId);
7180 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007181 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007182 }
7183 } finally {
7184 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007185 }
7186 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007187
7188 /**
7189 * Get Client request stats
7190 * @return List of Client Request Stats
7191 * @hide
7192 */
7193 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007194 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7195 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007197 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007198 return null;
7199 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007200 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202 final long identity = Binder.clearCallingIdentity();
7203 try {
7204 if (phone != null) {
7205 return phone.getClientRequestStats();
7206 }
7207
7208 return null;
7209 } finally {
7210 Binder.restoreCallingIdentity(identity);
7211 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007212 }
7213
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007214 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007215 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007216 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007217 }
Jack Yueb4124c2017-02-16 15:32:43 -08007218
7219 /**
Grace Chen70990072017-03-24 17:21:30 -07007220 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007221 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007222 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007223 * @param state State of SIM (power down, power up, pass through)
7224 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7225 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7226 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007227 *
7228 **/
7229 @Override
Grace Chen70990072017-03-24 17:21:30 -07007230 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007231 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007232 Phone phone = PhoneFactory.getPhone(slotIndex);
7233
vagdeviaf9a5b92018-08-15 16:01:53 -07007234 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 final long identity = Binder.clearCallingIdentity();
7237 try {
7238 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007239 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007240 }
7241 } finally {
7242 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007243 }
7244 }
Shuo Qiandd210312017-04-12 22:11:33 +00007245
Tyler Gunn65d45c22017-06-05 11:22:26 -07007246 private boolean isUssdApiAllowed(int subId) {
7247 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007248 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007249 if (configManager == null) {
7250 return false;
7251 }
7252 PersistableBundle pb = configManager.getConfigForSubId(subId);
7253 if (pb == null) {
7254 return false;
7255 }
7256 return pb.getBoolean(
7257 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7258 }
7259
Shuo Qiandd210312017-04-12 22:11:33 +00007260 /**
7261 * Check if phone is in emergency callback mode
7262 * @return true if phone is in emergency callback mode
7263 * @param subId sub id
7264 */
goneil9c5f4872017-12-05 14:07:56 -08007265 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007266 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007267 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007268 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007269
7270 final long identity = Binder.clearCallingIdentity();
7271 try {
7272 if (phone != null) {
7273 return phone.isInEcm();
7274 } else {
7275 return false;
7276 }
7277 } finally {
7278 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007279 }
7280 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007281
7282 /**
7283 * Get the current signal strength information for the given subscription.
7284 * Because this information is not updated when the device is in a low power state
7285 * it should not be relied-upon to be current.
7286 * @param subId Subscription index
7287 * @return the most recent cached signal strength info from the modem
7288 */
7289 @Override
7290 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007291 final long identity = Binder.clearCallingIdentity();
7292 try {
7293 Phone p = getPhone(subId);
7294 if (p == null) {
7295 return null;
7296 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007298 return p.getSignalStrength();
7299 } finally {
7300 Binder.restoreCallingIdentity(identity);
7301 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007302 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007303
Pengquan Meng77b7f132018-08-22 14:49:57 -07007304 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007305 * Get the current modem radio state for the given slot.
7306 * @param slotIndex slot index.
7307 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007308 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007309 * @return the current radio power state from the modem
7310 */
7311 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007312 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007313 Phone phone = PhoneFactory.getPhone(slotIndex);
7314 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7316 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007317 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7318 }
7319
7320 final long identity = Binder.clearCallingIdentity();
7321 try {
7322 return phone.getRadioPowerState();
7323 } finally {
7324 Binder.restoreCallingIdentity(identity);
7325 }
7326 }
7327 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7328 }
7329
7330 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007331 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7332 *
7333 * <p>Requires one of the following permissions:
7334 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7335 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7336 * privileges.
7337 *
7338 * @param subId subscription id
7339 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7340 * {@code false}.
7341 */
7342 @Override
7343 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007344 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7345 null /* message */);
7346
Pengquan Menga1bb6272018-09-06 09:59:22 -07007347 boolean isEnabled = false;
7348 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007349 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007350 Phone phone = getPhone(subId);
7351 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007352 } catch (Exception e) {
7353 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7354 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007355 } finally {
7356 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007357 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007358 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007359 }
7360
7361
7362 /**
7363 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7364 *
7365 * <p> Requires permission:
7366 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7367 * privileges.
7368 *
7369 * @param subId subscription id
7370 * @param isEnabled {@code true} means enable, {@code false} means disable.
7371 */
7372 @Override
7373 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7375 mApp, subId, "setDataRoamingEnabled");
7376
Pengquan Menga1bb6272018-09-06 09:59:22 -07007377 final long identity = Binder.clearCallingIdentity();
7378 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007379 Phone phone = getPhone(subId);
7380 if (phone != null) {
7381 phone.setDataRoamingEnabled(isEnabled);
7382 }
7383 } finally {
7384 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007385 }
7386 }
7387
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007388 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007389 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007390 TelephonyPermissions
7391 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007392 mApp, subId, "isManualNetworkSelectionAllowed");
7393
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007394 boolean isAllowed = true;
7395 final long identity = Binder.clearCallingIdentity();
7396 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007397 Phone phone = getPhone(subId);
7398 if (phone != null) {
7399 isAllowed = phone.isCspPlmnEnabled();
7400 }
7401 } finally {
7402 Binder.restoreCallingIdentity(identity);
7403 }
7404 return isAllowed;
7405 }
7406
7407 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007408 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007409 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007410 try {
7411 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007412 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007413 } catch (SecurityException e) {
7414 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7415 // has carrier privileges on an active UICC
7416 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7417 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007418 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007419 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007420 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007421
7422 final long identity = Binder.clearCallingIdentity();
7423 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007424 UiccController uiccController = UiccController.getInstance();
7425 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007426 if (hasReadPermission) {
7427 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007428 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007429
7430 // Remove private info if the caller doesn't have access
7431 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7432 for (UiccCardInfo cardInfo : cardInfos) {
7433 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7434 // is available
7435 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7436 if (card == null || card.getUiccProfile() == null) {
7437 // assume no access if the card or profile is unavailable
7438 filteredInfos.add(cardInfo.getUnprivileged());
7439 continue;
7440 }
7441 UiccProfile profile = card.getUiccProfile();
7442 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7443 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7444 filteredInfos.add(cardInfo);
7445 } else {
7446 filteredInfos.add(cardInfo.getUnprivileged());
7447 }
7448 }
7449 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007450 } finally {
7451 Binder.restoreCallingIdentity(identity);
7452 }
7453 }
7454
7455 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007456 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007457 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007458
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459 final long identity = Binder.clearCallingIdentity();
7460 try {
7461 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7462 if (slots == null) {
7463 Rlog.i(LOG_TAG, "slots is null.");
7464 return null;
7465 }
7466
7467 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7468 for (int i = 0; i < slots.length; i++) {
7469 UiccSlot slot = slots[i];
7470 if (slot == null) {
7471 continue;
7472 }
7473
Jordan Liu7be7e652019-05-06 18:55:02 +00007474 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007475 UiccCard card = slot.getUiccCard();
7476 if (card != null) {
7477 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007478 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007479 cardId = slot.getEid();
7480 if (TextUtils.isEmpty(cardId)) {
7481 cardId = slot.getIccId();
7482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 }
7484
Jordan Liu857451f2019-05-09 16:35:35 -07007485 if (cardId != null) {
7486 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7487 // if cardId is an EID, it's all digits so this is fine
7488 cardId = IccUtils.stripTrailingFs(cardId);
7489 }
7490
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491 int cardState = 0;
7492 switch (slot.getCardState()) {
7493 case CARDSTATE_ABSENT:
7494 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7495 break;
7496 case CARDSTATE_PRESENT:
7497 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7498 break;
7499 case CARDSTATE_ERROR:
7500 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7501 break;
7502 case CARDSTATE_RESTRICTED:
7503 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7504 break;
7505 default:
7506 break;
7507
7508 }
7509
7510 infos[i] = new UiccSlotInfo(
7511 slot.isActive(),
7512 slot.isEuicc(),
7513 cardId,
7514 cardState,
7515 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007516 slot.isExtendedApduSupported(),
7517 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 }
7519 return infos;
7520 } finally {
7521 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007522 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007523 }
7524
7525 @Override
7526 public boolean switchSlots(int[] physicalSlots) {
7527 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528
7529 final long identity = Binder.clearCallingIdentity();
7530 try {
7531 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7532 } finally {
7533 Binder.restoreCallingIdentity(identity);
7534 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007535 }
Jack Yu4c988042018-02-27 15:30:01 -08007536
7537 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007538 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007539 final long identity = Binder.clearCallingIdentity();
7540 try {
7541 return UiccController.getInstance().getCardIdForDefaultEuicc();
7542 } finally {
7543 Binder.restoreCallingIdentity(identity);
7544 }
7545 }
7546
7547 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007548 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7549 enforceModifyPermission();
7550 final Phone phone = getPhone(subId);
7551 if (phone == null) {
7552 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7553 return;
7554 }
7555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556 final long identity = Binder.clearCallingIdentity();
7557 try {
7558 phone.setRadioIndicationUpdateMode(filters, mode);
7559 } finally {
7560 Binder.restoreCallingIdentity(identity);
7561 }
Jack Yu4c988042018-02-27 15:30:01 -08007562 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007563
7564 /**
goneil47ffb6e2018-04-06 15:40:58 -07007565 * A test API to reload the UICC profile.
7566 *
7567 * <p>Requires that the calling app has permission
7568 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7569 * @hide
7570 */
7571 @Override
7572 public void refreshUiccProfile(int subId) {
7573 enforceModifyPermission();
7574
7575 final long identity = Binder.clearCallingIdentity();
7576 try {
7577 Phone phone = getPhone(subId);
7578 if (phone == null) {
7579 return;
7580 }
7581 UiccCard uiccCard = phone.getUiccCard();
7582 if (uiccCard == null) {
7583 return;
7584 }
7585 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7586 if (uiccProfile == null) {
7587 return;
7588 }
7589 uiccProfile.refresh();
7590 } finally {
7591 Binder.restoreCallingIdentity(identity);
7592 }
7593 }
7594
7595 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007596 * Returns false if the mobile data is disabled by default, otherwise return true.
7597 */
7598 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007599 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007600 }
7601
7602 /**
7603 * Returns true if the data roaming is enabled by default, i.e the system property
7604 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7605 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7606 */
7607 private boolean getDefaultDataRoamingEnabled(int subId) {
7608 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007609 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007610 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007611 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7612 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7613 return isDataRoamingEnabled;
7614 }
7615
7616 /**
7617 * Returns the default network type for the given {@code subId}, if the default network type is
7618 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7619 */
7620 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007621 List<Integer> list = TelephonyProperties.default_network();
7622 int phoneId = mSubscriptionController.getPhoneId(subId);
7623 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7624 return list.get(phoneId);
7625 }
7626 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007627 }
fionaxua13278b2018-03-21 00:08:13 -07007628
7629 @Override
7630 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007631 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007632 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007633
7634 final long identity = Binder.clearCallingIdentity();
7635 try {
7636 final Phone phone = getPhone(subId);
7637 if (phone == null) {
7638 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7639 return;
7640 }
chen xueaba88a2019-03-15 13:15:10 -07007641 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7642 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643 } finally {
7644 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007645 }
fionaxua13278b2018-03-21 00:08:13 -07007646 }
7647
7648 @Override
7649 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007650 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007651
7652 final long identity = Binder.clearCallingIdentity();
7653 try {
7654 final Phone phone = getPhone(subId);
7655 if (phone == null) {
7656 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7657 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7658 }
7659 return phone.getCarrierIdListVersion();
7660 } finally {
7661 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007662 }
fionaxua13278b2018-03-21 00:08:13 -07007663 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007664
7665 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007666 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7667 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007668 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007669 mApp, subId, callingPackage, callingFeatureId,
7670 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007671 return -1;
7672 }
7673
7674 final long identity = Binder.clearCallingIdentity();
7675 try {
7676 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7677 } finally {
7678 Binder.restoreCallingIdentity(identity);
7679 }
7680 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007681
7682 @Override
7683 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007684 TelephonyPermissions
7685 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007686 mApp, subId, "getCdmaRoamingMode");
7687
7688 final long identity = Binder.clearCallingIdentity();
7689 try {
7690 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7691 } finally {
7692 Binder.restoreCallingIdentity(identity);
7693 }
7694 }
7695
7696 @Override
7697 public boolean setCdmaRoamingMode(int subId, int mode) {
7698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7699 mApp, subId, "setCdmaRoamingMode");
7700
7701 final long identity = Binder.clearCallingIdentity();
7702 try {
7703 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7704 } finally {
7705 Binder.restoreCallingIdentity(identity);
7706 }
7707 }
7708
7709 @Override
7710 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7712 mApp, subId, "setCdmaSubscriptionMode");
7713
7714 final long identity = Binder.clearCallingIdentity();
7715 try {
7716 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7717 } finally {
7718 Binder.restoreCallingIdentity(identity);
7719 }
7720 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007721
sqianc5eccab2018-10-19 18:46:41 -07007722 @Override
sqian8c685422019-02-22 15:55:18 -08007723 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007724 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007726 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7727 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007728 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7729 }
7730 final long identity = Binder.clearCallingIdentity();
7731 try {
sqian854d44b2018-12-12 16:48:18 -08007732 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7733 for (Phone phone: PhoneFactory.getPhones()) {
7734 if (phone.getEmergencyNumberTracker() != null
7735 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7736 emergencyNumberListInternal.put(
7737 phone.getSubId(),
7738 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7739 }
sqian11b7a0e2018-12-05 18:48:28 -08007740 }
sqian854d44b2018-12-12 16:48:18 -08007741 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007742 } finally {
7743 Binder.restoreCallingIdentity(identity);
7744 }
sqianc5eccab2018-10-19 18:46:41 -07007745 }
7746
7747 @Override
sqian8c685422019-02-22 15:55:18 -08007748 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007749 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007750 if (!exactMatch) {
7751 TelephonyPermissions
7752 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007753 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007754 }
7755 final long identity = Binder.clearCallingIdentity();
7756 try {
sqian854d44b2018-12-12 16:48:18 -08007757 for (Phone phone: PhoneFactory.getPhones()) {
7758 if (phone.getEmergencyNumberTracker() != null
7759 && phone.getEmergencyNumberTracker() != null) {
7760 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7761 number, exactMatch)) {
7762 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007763 }
7764 }
sqian11b7a0e2018-12-05 18:48:28 -08007765 }
7766 return false;
7767 } finally {
7768 Binder.restoreCallingIdentity(identity);
7769 }
7770 }
7771
sqianf4ca7ed2019-01-15 18:32:07 -08007772 /**
7773 * Update emergency number list for test mode.
7774 */
7775 @Override
7776 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7777 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7778 "updateEmergencyNumberListTestMode");
7779
7780 final long identity = Binder.clearCallingIdentity();
7781 try {
7782 for (Phone phone: PhoneFactory.getPhones()) {
7783 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7784 if (tracker != null) {
7785 tracker.executeEmergencyNumberTestModeCommand(action, num);
7786 }
7787 }
7788 } finally {
7789 Binder.restoreCallingIdentity(identity);
7790 }
7791 }
7792
7793 /**
7794 * Get the full emergency number list for test mode.
7795 */
7796 @Override
7797 public List<String> getEmergencyNumberListTestMode() {
7798 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7799 "getEmergencyNumberListTestMode");
7800
7801 final long identity = Binder.clearCallingIdentity();
7802 try {
7803 Set<String> emergencyNumbers = new HashSet<>();
7804 for (Phone phone: PhoneFactory.getPhones()) {
7805 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7806 if (tracker != null) {
7807 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7808 emergencyNumbers.add(num.getNumber());
7809 }
7810 }
7811 }
7812 return new ArrayList<>(emergencyNumbers);
7813 } finally {
7814 Binder.restoreCallingIdentity(identity);
7815 }
7816 }
7817
chen xud6b45bd2018-10-30 22:27:10 -07007818 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007819 public int getEmergencyNumberDbVersion(int subId) {
7820 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7821
7822 final long identity = Binder.clearCallingIdentity();
7823 try {
7824 final Phone phone = getPhone(subId);
7825 if (phone == null) {
7826 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7827 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7828 }
7829 return phone.getEmergencyNumberDbVersion();
7830 } finally {
7831 Binder.restoreCallingIdentity(identity);
7832 }
7833 }
7834
7835 @Override
7836 public void notifyOtaEmergencyNumberDbInstalled() {
7837 enforceModifyPermission();
7838
7839 final long identity = Binder.clearCallingIdentity();
7840 try {
7841 for (Phone phone: PhoneFactory.getPhones()) {
7842 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7843 if (tracker != null) {
7844 tracker.updateOtaEmergencyNumberDatabase();
7845 }
7846 }
7847 } finally {
7848 Binder.restoreCallingIdentity(identity);
7849 }
7850 }
7851
7852 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08007853 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08007854 enforceActiveEmergencySessionPermission();
7855
7856 final long identity = Binder.clearCallingIdentity();
7857 try {
7858 for (Phone phone: PhoneFactory.getPhones()) {
7859 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7860 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08007861 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7862 }
7863 }
7864 } finally {
7865 Binder.restoreCallingIdentity(identity);
7866 }
7867 }
7868
7869 @Override
7870 public void resetOtaEmergencyNumberDbFilePath() {
7871 enforceActiveEmergencySessionPermission();
7872
7873 final long identity = Binder.clearCallingIdentity();
7874 try {
7875 for (Phone phone: PhoneFactory.getPhones()) {
7876 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7877 if (tracker != null) {
7878 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08007879 }
7880 }
7881 } finally {
7882 Binder.restoreCallingIdentity(identity);
7883 }
7884 }
7885
7886 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007887 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7888 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7889 Phone phone = getPhone(subId);
7890 if (phone == null) {
7891 return null;
7892 }
7893 final long identity = Binder.clearCallingIdentity();
7894 try {
7895 UiccProfile profile = UiccController.getInstance()
7896 .getUiccProfileForPhone(phone.getPhoneId());
7897 if (profile != null) {
7898 return profile.getCertsFromCarrierPrivilegeAccessRules();
7899 }
7900 } finally {
7901 Binder.restoreCallingIdentity(identity);
7902 }
7903 return null;
7904 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007905
7906 /**
7907 * Enable or disable a modem stack.
7908 */
7909 @Override
7910 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7911 enforceModifyPermission();
7912
7913 final long identity = Binder.clearCallingIdentity();
7914 try {
7915 Phone phone = PhoneFactory.getPhone(slotIndex);
7916 if (phone == null) {
7917 return false;
7918 } else {
7919 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7920 }
7921 } finally {
7922 Binder.restoreCallingIdentity(identity);
7923 }
7924 }
Michelecea4cf22018-12-21 15:00:11 -08007925
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007926 /**
7927 * Whether a modem stack is enabled or not.
7928 */
7929 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007930 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7931 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007932 Phone phone = PhoneFactory.getPhone(slotIndex);
7933 if (phone == null) return false;
7934
7935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007936 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7937 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007938 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7939 }
7940
7941 final long identity = Binder.clearCallingIdentity();
7942 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007943 try {
7944 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7945 } catch (NoSuchElementException ex) {
7946 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7947 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007948 } finally {
7949 Binder.restoreCallingIdentity(identity);
7950 }
7951 }
7952
Michelecea4cf22018-12-21 15:00:11 -08007953 @Override
Michele0ea7d782019-03-19 14:58:42 -07007954 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007955 enforceModifyPermission();
7956
7957 final long identity = Binder.clearCallingIdentity();
7958 try {
7959 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007960 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007961 .commit();
7962 } finally {
7963 Binder.restoreCallingIdentity(identity);
7964 }
7965 }
7966
7967 @Override
Michele0ea7d782019-03-19 14:58:42 -07007968 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007969 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007970 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007971 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7972 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007973 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007974 }
Michelecea4cf22018-12-21 15:00:11 -08007975
7976 final long identity = Binder.clearCallingIdentity();
7977 try {
Michele0ea7d782019-03-19 14:58:42 -07007978 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007979 } finally {
7980 Binder.restoreCallingIdentity(identity);
7981 }
7982 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007983
Michele0ea7d782019-03-19 14:58:42 -07007984 @TelephonyManager.IsMultiSimSupportedResult
7985 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007986 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7987 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7988 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007989 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7990 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007991 }
7992 // Check if the hardware supports multisim functionality. If usage of multisim is not
7993 // supported by the modem, indicate that it is restricted.
7994 PhoneCapability staticCapability =
7995 mPhoneConfigurationManager.getStaticPhoneCapability();
7996 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007997 loge("isMultiSimSupportedInternal: no static configuration available");
7998 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007999 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008000 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008001 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8002 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008003 }
8004 // Check if support of multiple SIMs is restricted by carrier
8005 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008006 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008007 }
8008
Michele0ea7d782019-03-19 14:58:42 -07008009 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008010 }
8011
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008012 /**
8013 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008014 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8015 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8016 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008017 * @param numOfSims number of active sims we want to switch to
8018 */
8019 @Override
8020 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008021 if (numOfSims == 1) {
8022 enforceModifyPermission();
8023 } else {
8024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8025 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8026 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008027 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008028
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008029 try {
Michele30b57b22019-03-01 12:01:14 -08008030 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008031 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008032 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8033 return;
8034 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008035 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8036 } finally {
8037 Binder.restoreCallingIdentity(identity);
8038 }
8039 }
8040
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008041 @Override
8042 public boolean isApplicationOnUicc(int subId, int appType) {
8043 enforceReadPrivilegedPermission("isApplicationOnUicc");
8044 Phone phone = getPhone(subId);
8045 if (phone == null) {
8046 return false;
8047 }
8048 final long identity = Binder.clearCallingIdentity();
8049 try {
8050 UiccCard uiccCard = phone.getUiccCard();
8051 if (uiccCard == null) {
8052 return false;
8053 }
8054 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8055 if (uiccProfile == null) {
8056 return false;
8057 }
8058 if (TelephonyManager.APPTYPE_SIM <= appType
8059 && appType <= TelephonyManager.APPTYPE_ISIM) {
8060 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8061 }
8062 return false;
8063 } finally {
8064 Binder.restoreCallingIdentity(identity);
8065 }
8066 }
8067
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008068 /**
chen xub4baa772019-04-03 10:23:41 -07008069 * Get whether making changes to modem configurations will trigger reboot.
8070 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008071 */
8072 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008073 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8074 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008075 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008076 mApp, subId, callingPackage, callingFeatureId,
8077 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008078 return false;
8079 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008080 final long identity = Binder.clearCallingIdentity();
8081 try {
8082 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8083 } finally {
8084 Binder.restoreCallingIdentity(identity);
8085 }
8086 }
8087
Nathan Harold29f5f052019-02-15 13:41:57 -08008088 private void updateModemStateMetrics() {
8089 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8090 // TODO: check the state for each modem if the api is ready.
8091 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8092 }
8093
Pengquan Meng3889a572019-01-23 11:16:29 -08008094 @Override
8095 public int[] getSlotsMapping() {
8096 enforceReadPrivilegedPermission("getSlotsMapping");
8097
8098 final long identity = Binder.clearCallingIdentity();
8099 try {
8100 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8101 // All logical slots should have a mapping to a physical slot.
8102 int[] logicalSlotsMapping = new int[phoneCount];
8103 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8104 for (int i = 0; i < slotInfos.length; i++) {
8105 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8106 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8107 }
8108 }
8109 return logicalSlotsMapping;
8110 } finally {
8111 Binder.restoreCallingIdentity(identity);
8112 }
8113 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008114
8115 /**
8116 * Get the IRadio HAL Version
8117 */
8118 @Override
8119 public int getRadioHalVersion() {
8120 Phone phone = getDefaultPhone();
8121 if (phone == null) return -1;
8122 HalVersion hv = phone.getHalVersion();
8123 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8124 return hv.major * 100 + hv.minor;
8125 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008126
8127 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008128 * Get the current calling package name.
8129 * @return the current calling package name
8130 */
8131 @Override
8132 public String getCurrentPackageName() {
8133 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8134 }
8135
8136 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008137 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8138 * corresponding network requests on a subId.
8139 *
8140 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008141 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008142 * 2) APN is un-metered for this subscription, or
8143 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008144 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008145 *
8146 * @return whether data is allowed for a apn type.
8147 *
8148 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008149 */
8150 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008151 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008152 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8153 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008154
8155 // Now that all security checks passes, perform the operation as ourselves.
8156 final long identity = Binder.clearCallingIdentity();
8157 try {
8158 Phone phone = getPhone(subId);
8159 if (phone == null) return false;
8160
Jack Yu41407ee2019-05-13 16:54:09 -07008161 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008162 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8163 } finally {
8164 Binder.restoreCallingIdentity(identity);
8165 }
8166 }
8167
8168 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008169 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008170 enforceReadPrivilegedPermission("isApnMetered");
8171
8172 // Now that all security checks passes, perform the operation as ourselves.
8173 final long identity = Binder.clearCallingIdentity();
8174 try {
8175 Phone phone = getPhone(subId);
8176 if (phone == null) return true; // By default return true.
8177
Jack Yu41407ee2019-05-13 16:54:09 -07008178 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008179 } finally {
8180 Binder.restoreCallingIdentity(identity);
8181 }
8182 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008183
8184 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008185 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8186 int subscriptionId, IBooleanConsumer resultCallback) {
8187 enforceModifyPermission();
8188 long token = Binder.clearCallingIdentity();
8189 try {
8190 Phone phone = getPhone(subscriptionId);
8191 if (phone == null) {
8192 try {
8193 if (resultCallback != null) {
8194 resultCallback.accept(false);
8195 }
8196 } catch (RemoteException e) {
8197 // ignore
8198 }
8199 return;
8200 }
8201 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8202 Pair.create(specifiers, (x) -> {
8203 try {
8204 if (resultCallback != null) {
8205 resultCallback.accept(x);
8206 }
8207 } catch (RemoteException e) {
8208 // ignore
8209 }
8210 });
8211 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8212 } finally {
8213 Binder.restoreCallingIdentity(token);
8214 }
8215 }
8216
8217 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008218 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8219 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8220 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8221 if (iccRecords == null) {
8222 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8223 return false;
8224 }
8225 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8226 }
8227
8228 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008229 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008230 if (callingPackage == null) {
8231 callingPackage = getCurrentPackageName();
8232 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008233 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8234 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8235 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8236 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8237 }
8238 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8239 Intent intent = new Intent();
8240 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8241 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8242 // Bring up choose default SMS subscription dialog right now
8243 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8244 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8245 mApp.startActivity(intent);
8246 }
chen xud5ca2d52019-05-28 15:20:57 -07008247
8248 @Override
8249 public String getMmsUAProfUrl(int subId) {
8250 //TODO investigate if this API should require proper permission check in R b/133791609
8251 final long identity = Binder.clearCallingIdentity();
8252 try {
8253 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8254 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8255 } finally {
8256 Binder.restoreCallingIdentity(identity);
8257 }
8258 }
8259
8260 @Override
8261 public String getMmsUserAgent(int subId) {
8262 //TODO investigate if this API should require proper permission check in R b/133791609
8263 final long identity = Binder.clearCallingIdentity();
8264 try {
8265 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8266 .getString(com.android.internal.R.string.config_mms_user_agent);
8267 } finally {
8268 Binder.restoreCallingIdentity(identity);
8269 }
8270 }
Jack Yub07d4972019-05-28 16:12:25 -07008271
8272 @Override
8273 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8274 enforceModifyPermission();
8275
8276 // Now that all security checks passes, perform the operation as ourselves.
8277 final long identity = Binder.clearCallingIdentity();
8278 try {
8279 Phone phone = getPhone(subId);
8280 if (phone == null) return false;
8281
8282 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8283 } finally {
8284 Binder.restoreCallingIdentity(identity);
8285 }
8286 }
8287
8288 @Override
8289 public boolean isDataAllowedInVoiceCall(int subId) {
8290 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8291
8292 // Now that all security checks passes, perform the operation as ourselves.
8293 final long identity = Binder.clearCallingIdentity();
8294 try {
8295 Phone phone = getPhone(subId);
8296 if (phone == null) return false;
8297
8298 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8299 } finally {
8300 Binder.restoreCallingIdentity(identity);
8301 }
8302 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008303
changbetty97defcf2019-12-24 15:40:37 +08008304 @Override
8305 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8306 enforceModifyPermission();
8307
8308 // Now that all security checks passes, perform the operation as ourselves.
8309 final long identity = Binder.clearCallingIdentity();
8310 try {
8311 Phone phone = getPhone(subId);
8312 if (phone == null) return false;
8313
8314 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8315 } finally {
8316 Binder.restoreCallingIdentity(identity);
8317 }
8318 }
8319
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008320 /**
8321 * Updates whether conference event pacakge handling is enabled.
8322 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8323 * otherwise.
8324 */
8325 @Override
8326 public void setCepEnabled(boolean isCepEnabled) {
8327 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8328
8329 final long identity = Binder.clearCallingIdentity();
8330 try {
8331 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8332 for (Phone phone : PhoneFactory.getPhones()) {
8333 Phone defaultPhone = phone.getImsPhone();
8334 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8335 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8336 ImsPhoneCallTracker imsPhoneCallTracker =
8337 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8338 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8339 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8340 + imsPhone.getMsisdn());
8341 }
8342 }
8343 } finally {
8344 Binder.restoreCallingIdentity(identity);
8345 }
8346 }
allenwtsu46dcc572020-01-08 18:24:03 +08008347
8348 /**
8349 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8350 *
8351 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8352 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8353 * before being read.
8354 */
8355 @Override
8356 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8357 isCompressed) {
8358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8359 mApp, subId, "notifyRcsAutoConfigurationReceived");
8360 try {
8361 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8362 if (configBinder == null) {
8363 Rlog.e(LOG_TAG, "null result for getImsConfig");
8364 } else {
8365 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8366 }
8367 } catch (RemoteException e) {
8368 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8369 }
8370 }
zoey chenf95ca592019-12-30 16:11:23 +08008371
8372 @Override
8373 public boolean isIccLockEnabled(int subId) {
8374 enforceReadPrivilegedPermission("isIccLockEnabled");
8375
8376 // Now that all security checks passes, perform the operation as ourselves.
8377 final long identity = Binder.clearCallingIdentity();
8378 try {
8379 Phone phone = getPhone(subId);
8380 if (phone != null && phone.getIccCard() != null) {
8381 return phone.getIccCard().getIccLockEnabled();
8382 } else {
8383 return false;
8384 }
8385 } finally {
8386 Binder.restoreCallingIdentity(identity);
8387 }
8388 }
8389
8390 /**
8391 * Set the ICC pin lock enabled or disabled..
8392 *
8393 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8394 * 0 or a positive integer as the attempts remaining value.
8395 *
8396 */
8397 @Override
8398 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8399 enforceModifyPermission();
8400
8401 Phone phone = getPhone(subId);
8402 if (phone == null) {
8403 return 0;
8404 }
8405 // Now that all security checks passes, perform the operation as ourselves.
8406 final long identity = Binder.clearCallingIdentity();
8407 try {
8408 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8409 new Pair<Boolean, String>(enabled, password), phone, null);
8410 return attemptsRemaining;
8411
8412 } catch (Exception e) {
8413 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8414 } finally {
8415 Binder.restoreCallingIdentity(identity);
8416 }
8417 return 0;
8418 }
8419
8420 /**
8421 * Change the ICC password used in ICC pin lock.
8422 *
8423 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8424 * 0 or a positive integer as the attempts remaining value.
8425 *
8426 */
8427 @Override
8428 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8429 enforceModifyPermission();
8430
8431 Phone phone = getPhone(subId);
8432 if (phone == null) {
8433 return 0;
8434 }
8435 // Now that all security checks passes, perform the operation as ourselves.
8436 final long identity = Binder.clearCallingIdentity();
8437 try {
8438 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8439 new Pair<String, String>(oldPassword, newPassword), phone, null);
8440 return attemptsRemaining;
8441
8442 } catch (Exception e) {
8443 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8444 } finally {
8445 Binder.restoreCallingIdentity(identity);
8446 }
8447 return 0;
8448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008449}