blob: aeda70cf264b199dd6af4fba5fb5cff8257542e4 [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;
Jordan Liua39e6c12020-03-04 13:59:23 -0800124import com.android.internal.annotations.VisibleForTesting;
sqian80370722020-01-29 15:02:51 -0800125import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700126import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700127import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700128import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800129import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700130import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700131import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800132import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800134import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800135import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700136import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800137import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800139import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700140import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700141import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700142import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700144import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800145import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700146import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700147import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700148import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700149import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700150import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700151import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700152import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700153import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800154import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700156import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800157import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700158import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800159import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700160import com.android.internal.telephony.imsphone.ImsPhone;
161import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800162import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900163import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800165import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800167import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700168import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800169import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800171import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000172import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800173import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700174import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800175import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700176import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800178import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700179import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700180import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800181import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800182
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700183import java.io.FileDescriptor;
184import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800187import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800189import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100190import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800191import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700192import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800193import java.util.Set;
Hall Liud0d1dc92020-01-20 13:42:00 -0800194import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195
196/**
197 * Implementation of the ITelephony interface.
198 */
Santos Cordon117fee72014-05-16 17:56:12 -0700199public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200 private static final String LOG_TAG = "PhoneInterfaceManager";
201 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
202 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800203 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204
205 // Message codes used with mMainThreadHandler
206 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700207 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
208 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700209 private static final int CMD_OPEN_CHANNEL = 9;
210 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
211 private static final int CMD_CLOSE_CHANNEL = 11;
212 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800213 private static final int CMD_NV_READ_ITEM = 13;
214 private static final int EVENT_NV_READ_ITEM_DONE = 14;
215 private static final int CMD_NV_WRITE_ITEM = 15;
216 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
217 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
218 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700219 private static final int CMD_RESET_MODEM_CONFIG = 19;
220 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800221 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
222 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
223 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
224 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800225 private static final int CMD_SEND_ENVELOPE = 25;
226 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000227 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
228 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700229 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
230 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
231 private static final int CMD_EXCHANGE_SIM_IO = 31;
232 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800233 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
234 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700235 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
236 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700237 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
238 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700239 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
240 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
241 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
242 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700243 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
244 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
245 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
246 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700247 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800248 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
249 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000250 private static final int CMD_SWITCH_SLOTS = 50;
251 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700252 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
253 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
254 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
255 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
256 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
257 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
258 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
259 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700260 private static final int CMD_GET_ALL_CELL_INFO = 60;
261 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
262 private static final int CMD_GET_CELL_LOCATION = 62;
263 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700264 private static final int CMD_MODEM_REBOOT = 64;
265 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700266 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
267 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800268 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
269 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700270 private static final int CMD_GET_MODEM_STATUS = 70;
271 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700272 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
273 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700274 private static final int CMD_ERASE_MODEM_CONFIG = 74;
275 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800276 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
277 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
278 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
279 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800280 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
281 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
sqian80370722020-01-29 15:02:51 -0800282 private static final int CMD_GET_CALL_FORWARDING = 83;
283 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
284 private static final int CMD_SET_CALL_FORWARDING = 85;
285 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
286 private static final int CMD_GET_CALL_WAITING = 87;
287 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
288 private static final int CMD_SET_CALL_WAITING = 89;
289 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800291 // Parameters of select command.
292 private static final int SELECT_COMMAND = 0xA4;
293 private static final int SELECT_P1 = 0x04;
294 private static final int SELECT_P2 = 0;
295 private static final int SELECT_P3 = 0x10;
296
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297 /** The singleton instance. */
298 private static PhoneInterfaceManager sInstance;
299
Wink Saville3ab207e2014-11-20 13:07:20 -0800300 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800301 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800302 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700303 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800304 private AppOpsManager mAppOps;
305 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800306 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800307 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700308 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700309
Derek Tan97ebb422014-09-05 16:55:38 -0700310 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
311 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800312 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800313 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700314
Michelecea4cf22018-12-21 15:00:11 -0800315 // String to store multi SIM allowed
316 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
317
Derek Tan740e1672017-06-27 14:56:27 -0700318 // The AID of ISD-R.
319 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
320
yinxub1bed742017-04-17 11:45:04 -0700321 private NetworkScanRequestTracker mNetworkScanRequestTracker;
322
David Kelly5e06a7f2018-03-12 14:10:59 +0000323 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
324 private static final int MANUFACTURER_CODE_LENGTH = 8;
325
Derek Tan89e89d42014-07-08 17:00:10 -0700326 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700327 * Experiment flag to enable erase modem config on reset network, default value is false
328 */
329 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
330 "reset_network_erase_modem_config_enabled";
331
332 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700333 * A request object to use for transmitting data to an ICC.
334 */
335 private static final class IccAPDUArgument {
336 public int channel, cla, command, p1, p2, p3;
337 public String data;
338
339 public IccAPDUArgument(int channel, int cla, int command,
340 int p1, int p2, int p3, String data) {
341 this.channel = channel;
342 this.cla = cla;
343 this.command = command;
344 this.p1 = p1;
345 this.p2 = p2;
346 this.p3 = p3;
347 this.data = data;
348 }
349 }
350
351 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700352 * A request object to use for transmitting data to an ICC.
353 */
354 private static final class ManualNetworkSelectionArgument {
355 public OperatorInfo operatorInfo;
356 public boolean persistSelection;
357
358 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
359 this.operatorInfo = operatorInfo;
360 this.persistSelection = persistSelection;
361 }
362 }
363
364 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
366 * request after sending. The main thread will notify the request when it is complete.
367 */
368 private static final class MainThreadRequest {
369 /** The argument to use for the request */
370 public Object argument;
371 /** The result of the request that is run on the main thread */
372 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800373 // The subscriber id that this request applies to. Defaults to
374 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
375 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376
Nathan Harold92bed182018-10-12 18:16:49 -0700377 // In cases where subId is unavailable, the caller needs to specify the phone.
378 public Phone phone;
379
vagdeviaf9a5b92018-08-15 16:01:53 -0700380 public WorkSource workSource;
381
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 public MainThreadRequest(Object argument) {
383 this.argument = argument;
384 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800385
Nathan Harold92bed182018-10-12 18:16:49 -0700386 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
387 this.argument = argument;
388 if (phone != null) {
389 this.phone = phone;
390 }
391 this.workSource = workSource;
392 }
393
vagdeviaf9a5b92018-08-15 16:01:53 -0700394 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800395 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800396 if (subId != null) {
397 this.subId = subId;
398 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700399 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 }
402
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800403 private static final class IncomingThirdPartyCallArgs {
404 public final ComponentName component;
405 public final String callId;
406 public final String callerDisplayName;
407
408 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
409 String callerDisplayName) {
410 this.component = component;
411 this.callId = callId;
412 this.callerDisplayName = callerDisplayName;
413 }
414 }
415
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 /**
417 * A handler that processes messages on the main thread in the phone process. Since many
418 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
419 * inbound binder threads to the main thread in the phone process. The Binder thread
420 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
421 * on, which will be notified when the operation completes and will contain the result of the
422 * request.
423 *
424 * <p>If a MainThreadRequest object is provided in the msg.obj field,
425 * note that request.result must be set to something non-null for the calling thread to
426 * unblock.
427 */
428 private final class MainThreadHandler extends Handler {
429 @Override
430 public void handleMessage(Message msg) {
431 MainThreadRequest request;
432 Message onCompleted;
433 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800434 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700435 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800436 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437
438 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700439 case CMD_HANDLE_USSD_REQUEST: {
440 request = (MainThreadRequest) msg.obj;
441 final Phone phone = getPhoneFromRequest(request);
442 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
443 String ussdRequest = ussdObject.first;
444 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700445
Pengquan Menga1bb6272018-09-06 09:59:22 -0700446 if (!isUssdApiAllowed(request.subId)) {
447 // Carrier does not support use of this API, return failure.
448 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
449 UssdResponse response = new UssdResponse(ussdRequest, null);
450 Bundle returnData = new Bundle();
451 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
452 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700453
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 request.result = true;
455 notifyRequester(request);
456 return;
457 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700458
Pengquan Menga1bb6272018-09-06 09:59:22 -0700459 try {
460 request.result = phone != null
461 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
462 } catch (CallStateException cse) {
463 request.result = false;
464 }
465 // Wake up the requesting thread
466 notifyRequester(request);
467 break;
pkanwar32d516d2016-10-14 19:37:38 -0700468 }
469
Yorke Lee716f67e2015-06-17 15:39:16 -0700470 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700471 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700472 final Phone phone = getPhoneFromRequest(request);
473 request.result = phone != null ?
474 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
475 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700476 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700477 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700481 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700482 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800484 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700485 if (uiccCard == null) {
486 loge("iccTransmitApduLogicalChannel: No UICC");
487 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700488 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700489 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
491 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700492 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 iccArgument.channel, iccArgument.cla, iccArgument.command,
494 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700495 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700496 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 break;
498
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700500 ar = (AsyncResult) msg.obj;
501 request = (MainThreadRequest) ar.userObj;
502 if (ar.exception == null && ar.result != null) {
503 request.result = ar.result;
504 } else {
505 request.result = new IccIoResult(0x6F, 0, (byte[])null);
506 if (ar.result == null) {
507 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800508 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700509 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800510 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700511 } else {
512 loge("iccTransmitApduLogicalChannel: Unknown exception");
513 }
514 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700515 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700516 break;
517
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700518 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
519 request = (MainThreadRequest) msg.obj;
520 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800521 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700522 if (uiccCard == null) {
523 loge("iccTransmitApduBasicChannel: No UICC");
524 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700525 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 } else {
527 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
528 request);
529 uiccCard.iccTransmitApduBasicChannel(
530 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
531 iccArgument.p3, iccArgument.data, onCompleted);
532 }
533 break;
534
535 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
536 ar = (AsyncResult) msg.obj;
537 request = (MainThreadRequest) ar.userObj;
538 if (ar.exception == null && ar.result != null) {
539 request.result = ar.result;
540 } else {
541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
542 if (ar.result == null) {
543 loge("iccTransmitApduBasicChannel: Empty response");
544 } else if (ar.exception instanceof CommandException) {
545 loge("iccTransmitApduBasicChannel: CommandException: " +
546 ar.exception);
547 } else {
548 loge("iccTransmitApduBasicChannel: Unknown exception");
549 }
550 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 break;
553
554 case CMD_EXCHANGE_SIM_IO:
555 request = (MainThreadRequest) msg.obj;
556 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800557 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 if (uiccCard == null) {
559 loge("iccExchangeSimIO: No UICC");
560 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700561 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 } else {
563 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
564 request);
565 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
566 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
567 iccArgument.data, onCompleted);
568 }
569 break;
570
571 case EVENT_EXCHANGE_SIM_IO_DONE:
572 ar = (AsyncResult) msg.obj;
573 request = (MainThreadRequest) ar.userObj;
574 if (ar.exception == null && ar.result != null) {
575 request.result = ar.result;
576 } else {
577 request.result = new IccIoResult(0x6f, 0, (byte[])null);
578 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700580 break;
581
Derek Tan4d5e5c12014-02-04 11:54:58 -0800582 case CMD_SEND_ENVELOPE:
583 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800584 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700585 if (uiccCard == null) {
586 loge("sendEnvelopeWithStatus: No UICC");
587 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 } else {
590 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
591 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
592 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800593 break;
594
595 case EVENT_SEND_ENVELOPE_DONE:
596 ar = (AsyncResult) msg.obj;
597 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700598 if (ar.exception == null && ar.result != null) {
599 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800600 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700601 request.result = new IccIoResult(0x6F, 0, (byte[])null);
602 if (ar.result == null) {
603 loge("sendEnvelopeWithStatus: Empty response");
604 } else if (ar.exception instanceof CommandException) {
605 loge("sendEnvelopeWithStatus: CommandException: " +
606 ar.exception);
607 } else {
608 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
609 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800610 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700611 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800612 break;
613
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 case CMD_OPEN_CHANNEL:
615 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800616 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800617 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700618 if (uiccCard == null) {
619 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800620 request.result = new IccOpenLogicalChannelResponse(-1,
621 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700623 } else {
624 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800625 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
626 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700627 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 break;
629
630 case EVENT_OPEN_CHANNEL_DONE:
631 ar = (AsyncResult) msg.obj;
632 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 int[] result = (int[]) ar.result;
636 int channelId = result[0];
637 byte[] selectResponse = null;
638 if (result.length > 1) {
639 selectResponse = new byte[result.length - 1];
640 for (int i = 1; i < result.length; ++i) {
641 selectResponse[i - 1] = (byte) result[i];
642 }
643 }
644 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700645 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 if (ar.result == null) {
648 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 if (ar.exception != null) {
651 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
652 }
653
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700654 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700655 if (ar.exception instanceof CommandException) {
656 CommandException.Error error =
657 ((CommandException) (ar.exception)).getCommandError();
658 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700659 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700660 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700661 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 }
663 }
664 openChannelResp = new IccOpenLogicalChannelResponse(
665 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700667 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700668 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 break;
670
671 case CMD_CLOSE_CHANNEL:
672 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800673 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700674 if (uiccCard == null) {
675 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900676 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700678 } else {
679 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
680 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
681 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 break;
683
684 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800685 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
686 break;
687
688 case CMD_NV_READ_ITEM:
689 request = (MainThreadRequest) msg.obj;
690 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800691 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
692 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800693 break;
694
695 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 ar = (AsyncResult) msg.obj;
697 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800698 if (ar.exception == null && ar.result != null) {
699 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800701 request.result = "";
702 if (ar.result == null) {
703 loge("nvReadItem: Empty response");
704 } else if (ar.exception instanceof CommandException) {
705 loge("nvReadItem: CommandException: " +
706 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800708 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 }
710 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700711 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 break;
713
Jake Hambye994d462014-02-03 13:10:13 -0800714 case CMD_NV_WRITE_ITEM:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
717 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800718 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700719 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800720 break;
721
722 case EVENT_NV_WRITE_ITEM_DONE:
723 handleNullReturnEvent(msg, "nvWriteItem");
724 break;
725
726 case CMD_NV_WRITE_CDMA_PRL:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800729 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800730 break;
731
732 case EVENT_NV_WRITE_CDMA_PRL_DONE:
733 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
734 break;
735
chen xu6dac5ab2018-10-26 17:39:23 -0700736 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800737 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700738 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800739 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800740 break;
741
chen xu6dac5ab2018-10-26 17:39:23 -0700742 case EVENT_RESET_MODEM_CONFIG_DONE:
743 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800744 break;
745
Jake Hamby7c27be32014-03-03 13:25:59 -0800746 case CMD_GET_PREFERRED_NETWORK_TYPE:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700749 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800750 break;
751
752 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
753 ar = (AsyncResult) msg.obj;
754 request = (MainThreadRequest) ar.userObj;
755 if (ar.exception == null && ar.result != null) {
756 request.result = ar.result; // Integer
757 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800758 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800759 if (ar.result == null) {
760 loge("getPreferredNetworkType: Empty response");
761 } else if (ar.exception instanceof CommandException) {
762 loge("getPreferredNetworkType: CommandException: " +
763 ar.exception);
764 } else {
765 loge("getPreferredNetworkType: Unknown exception");
766 }
767 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700768 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800769 break;
770
771 case CMD_SET_PREFERRED_NETWORK_TYPE:
772 request = (MainThreadRequest) msg.obj;
773 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
774 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700775 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800776 break;
777
778 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
779 handleNullReturnEvent(msg, "setPreferredNetworkType");
780 break;
781
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000782 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
783 request = (MainThreadRequest)msg.obj;
784 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800785 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000786 break;
787
788 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
789 ar = (AsyncResult)msg.obj;
790 request = (MainThreadRequest)ar.userObj;
791 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700792 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000793 break;
794
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800795 case CMD_SET_VOICEMAIL_NUMBER:
796 request = (MainThreadRequest) msg.obj;
797 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
798 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800799 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
800 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800801 break;
802
803 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
804 handleNullReturnEvent(msg, "setVoicemailNumber");
805 break;
806
Stuart Scott54788802015-03-30 13:18:01 -0700807 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
808 request = (MainThreadRequest) msg.obj;
809 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
810 request);
811 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
812 break;
813
814 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
815 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
816 break;
817
Shishir Agrawal302c8692015-06-19 13:49:39 -0700818 case CMD_PERFORM_NETWORK_SCAN:
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
821 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
822 break;
823
sqian80370722020-01-29 15:02:51 -0800824 case CMD_GET_CALL_FORWARDING:
825 request = (MainThreadRequest) msg.obj;
826 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
827 int callForwardingReason = (Integer) request.argument;
828 getPhoneFromRequest(request).getCallForwardingOption(
829 callForwardingReason, onCompleted);
830 break;
831
832 case EVENT_GET_CALL_FORWARDING_DONE:
833 ar = (AsyncResult) msg.obj;
834 request = (MainThreadRequest) ar.userObj;
835 CallForwardingInfo callForwardingInfo = null;
836 if (ar.exception == null && ar.result != null) {
837 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
838 for (CallForwardInfo callForwardInfo : callForwardInfos) {
839 // Service Class is a bit mask per 3gpp 27.007. Search for
840 // any service for voice call.
841 if ((callForwardInfo.serviceClass
842 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
843 callForwardingInfo = new CallForwardingInfo(
844 callForwardInfo.serviceClass, callForwardInfo.reason,
845 callForwardInfo.number,
846 callForwardInfo.timeSeconds);
847 break;
848 }
849 }
850 // Didn't find a call forward info for voice call.
851 if (callForwardingInfo == null) {
852 callForwardingInfo = new CallForwardingInfo(
853 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
854 0 /* reason */, null /* number */, 0 /* timeout */);
855 }
856 } else {
857 if (ar.result == null) {
858 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
859 }
860 if (ar.exception != null) {
861 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
862 }
863 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
864 if (ar.exception instanceof CommandException) {
865 CommandException.Error error =
866 ((CommandException) (ar.exception)).getCommandError();
867 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
868 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
869 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
870 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
871 }
872 }
873 callForwardingInfo = new CallForwardingInfo(
874 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
875 }
876 request.result = callForwardingInfo;
877 notifyRequester(request);
878 break;
879
880 case CMD_SET_CALL_FORWARDING:
881 request = (MainThreadRequest) msg.obj;
882 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
883 CallForwardingInfo callForwardingInfoToSet =
884 (CallForwardingInfo) request.argument;
885 getPhoneFromRequest(request).setCallForwardingOption(
886 callForwardingInfoToSet.getStatus(),
887 callForwardingInfoToSet.getReason(),
888 callForwardingInfoToSet.getNumber(),
889 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
890 break;
891
892 case EVENT_SET_CALL_FORWARDING_DONE:
893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
895 if (ar.exception == null) {
896 request.result = true;
897 } else {
898 request.result = false;
899 loge("setCallForwarding exception: " + ar.exception);
900 }
901 notifyRequester(request);
902 break;
903
904 case CMD_GET_CALL_WAITING:
905 request = (MainThreadRequest) msg.obj;
906 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
907 getPhoneFromRequest(request).getCallWaiting(onCompleted);
908 break;
909
910 case EVENT_GET_CALL_WAITING_DONE:
911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
913 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
914 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800915 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -0800916 // Service Class is a bit mask per 3gpp 27.007.
917 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800918 if (callForwardResults.length > 1
919 && ((callForwardResults[1]
920 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
921 callForwardingStatus = callForwardResults[0] == 0
sqian80370722020-01-29 15:02:51 -0800922 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
923 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
924 } else {
925 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
926 }
927 } else {
928 if (ar.result == null) {
929 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
930 }
931 if (ar.exception != null) {
932 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
933 }
934 if (ar.exception instanceof CommandException) {
935 CommandException.Error error =
936 ((CommandException) (ar.exception)).getCommandError();
937 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
938 callForwardingStatus =
939 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
940 }
941 }
942 }
943 request.result = callForwardingStatus;
944 notifyRequester(request);
945 break;
946
947 case CMD_SET_CALL_WAITING:
948 request = (MainThreadRequest) msg.obj;
949 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
950 boolean isEnable = (Boolean) request.argument;
951 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
952 break;
953
954 case EVENT_SET_CALL_WAITING_DONE:
955 ar = (AsyncResult) msg.obj;
956 request = (MainThreadRequest) ar.userObj;
957 if (ar.exception == null) {
958 request.result = true;
959 } else {
960 request.result = false;
961 loge("setCallWaiting exception: " + ar.exception);
962 }
963 notifyRequester(request);
964 break;
965
Shishir Agrawal302c8692015-06-19 13:49:39 -0700966 case EVENT_PERFORM_NETWORK_SCAN_DONE:
967 ar = (AsyncResult) msg.obj;
968 request = (MainThreadRequest) ar.userObj;
969 CellNetworkScanResult cellScanResult;
970 if (ar.exception == null && ar.result != null) {
971 cellScanResult = new CellNetworkScanResult(
972 CellNetworkScanResult.STATUS_SUCCESS,
973 (List<OperatorInfo>) ar.result);
974 } else {
975 if (ar.result == null) {
976 loge("getCellNetworkScanResults: Empty response");
977 }
978 if (ar.exception != null) {
979 loge("getCellNetworkScanResults: Exception: " + ar.exception);
980 }
981 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
982 if (ar.exception instanceof CommandException) {
983 CommandException.Error error =
984 ((CommandException) (ar.exception)).getCommandError();
985 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
986 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
987 } else if (error == CommandException.Error.GENERIC_FAILURE) {
988 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
989 }
990 }
991 cellScanResult = new CellNetworkScanResult(errorCode, null);
992 }
993 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700994 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700995 break;
996
997 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
998 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700999 ManualNetworkSelectionArgument selArg =
1000 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001001 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1002 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001003 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1004 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001005 break;
1006
1007 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001008 ar = (AsyncResult) msg.obj;
1009 request = (MainThreadRequest) ar.userObj;
1010 if (ar.exception == null) {
1011 request.result = true;
1012 } else {
1013 request.result = false;
1014 loge("setNetworkSelectionModeManual " + ar.exception);
1015 }
1016 notifyRequester(request);
1017 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001018 break;
1019
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001020 case CMD_GET_MODEM_ACTIVITY_INFO:
1021 request = (MainThreadRequest) msg.obj;
1022 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001023 if (defaultPhone != null) {
1024 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001025 } else {
1026 ResultReceiver result = (ResultReceiver) request.argument;
1027 Bundle bundle = new Bundle();
1028 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1029 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1030 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001031 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001032 break;
1033
1034 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1035 ar = (AsyncResult) msg.obj;
1036 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001037 ResultReceiver result = (ResultReceiver) request.argument;
1038
1039 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001040 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001041 // Update the last modem activity info and the result of the request.
1042 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1043 if (isModemActivityInfoValid(info)) {
1044 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1045 int[] txTimeMs = info.getTransmitTimeMillis();
1046 int[] lastModemTxTimeMs = mLastModemActivityInfo
1047 .getTransmitTimeMillis();
1048 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1049 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1050 }
1051 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1052 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1053 + mLastModemActivityInfo.getSleepTimeMillis());
1054 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1055 + mLastModemActivityInfo.getIdleTimeMillis());
1056 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1057 mLastModemActivityInfo.setReceiveTimeMillis(
1058 info.getReceiveTimeMillis()
1059 + mLastModemActivityInfo.getReceiveTimeMillis());
1060 }
1061 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1062 mLastModemActivityInfo.getSleepTimeMillis(),
1063 mLastModemActivityInfo.getIdleTimeMillis(),
1064 mLastModemActivityInfo.getTransmitTimeMillis(),
1065 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001066 } else {
1067 if (ar.result == null) {
1068 loge("queryModemActivityInfo: Empty response");
1069 } else if (ar.exception instanceof CommandException) {
1070 loge("queryModemActivityInfo: CommandException: " +
1071 ar.exception);
1072 } else {
1073 loge("queryModemActivityInfo: Unknown exception");
1074 }
1075 }
sqian1a1be542020-03-05 11:37:28 -08001076 Bundle bundle = new Bundle();
1077 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1078 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001079 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001080 break;
1081
Meng Wang1a7c35a2016-05-05 20:56:15 -07001082 case CMD_SET_ALLOWED_CARRIERS:
1083 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001084 CarrierRestrictionRules argument =
1085 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001086 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001087 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001088 break;
1089
1090 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1091 ar = (AsyncResult) msg.obj;
1092 request = (MainThreadRequest) ar.userObj;
1093 if (ar.exception == null && ar.result != null) {
1094 request.result = ar.result;
1095 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001096 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1097 if (ar.exception instanceof CommandException) {
1098 loge("setAllowedCarriers: CommandException: " + ar.exception);
1099 CommandException.Error error =
1100 ((CommandException) (ar.exception)).getCommandError();
1101 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1102 request.result =
1103 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1104 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001105 } else {
1106 loge("setAllowedCarriers: Unknown exception");
1107 }
1108 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001109 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001110 break;
1111
1112 case CMD_GET_ALLOWED_CARRIERS:
1113 request = (MainThreadRequest) msg.obj;
1114 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001115 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001116 break;
1117
1118 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1119 ar = (AsyncResult) msg.obj;
1120 request = (MainThreadRequest) ar.userObj;
1121 if (ar.exception == null && ar.result != null) {
1122 request.result = ar.result;
1123 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001124 request.result = new IllegalStateException(
1125 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001126 if (ar.result == null) {
1127 loge("getAllowedCarriers: Empty response");
1128 } else if (ar.exception instanceof CommandException) {
1129 loge("getAllowedCarriers: CommandException: " +
1130 ar.exception);
1131 } else {
1132 loge("getAllowedCarriers: Unknown exception");
1133 }
1134 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001135 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001136 break;
1137
Nathan Haroldb3014052017-01-25 15:57:32 -08001138 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1139 ar = (AsyncResult) msg.obj;
1140 request = (MainThreadRequest) ar.userObj;
1141 if (ar.exception == null && ar.result != null) {
1142 request.result = ar.result;
1143 } else {
1144 request.result = new IllegalArgumentException(
1145 "Failed to retrieve Forbidden Plmns");
1146 if (ar.result == null) {
1147 loge("getForbiddenPlmns: Empty response");
1148 } else {
1149 loge("getForbiddenPlmns: Unknown exception");
1150 }
1151 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001152 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001153 break;
1154
1155 case CMD_GET_FORBIDDEN_PLMNS:
1156 request = (MainThreadRequest) msg.obj;
1157 uiccCard = getUiccCardFromRequest(request);
1158 if (uiccCard == null) {
1159 loge("getForbiddenPlmns() UiccCard is null");
1160 request.result = new IllegalArgumentException(
1161 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001162 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001163 break;
1164 }
1165 Integer appType = (Integer) request.argument;
1166 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1167 if (uiccApp == null) {
1168 loge("getForbiddenPlmns() no app with specified type -- "
1169 + appType);
1170 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001171 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001172 break;
1173 } else {
1174 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1175 + " specified type -- " + appType);
1176 }
1177 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1178 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1179 onCompleted);
1180 break;
1181
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001182 case CMD_SWITCH_SLOTS:
1183 request = (MainThreadRequest) msg.obj;
1184 int[] physicalSlots = (int[]) request.argument;
1185 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1186 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1187 break;
1188
1189 case EVENT_SWITCH_SLOTS_DONE:
1190 ar = (AsyncResult) msg.obj;
1191 request = (MainThreadRequest) ar.userObj;
1192 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001193 notifyRequester(request);
1194 break;
1195 case CMD_GET_NETWORK_SELECTION_MODE:
1196 request = (MainThreadRequest) msg.obj;
1197 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1198 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1199 break;
1200
1201 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1202 ar = (AsyncResult) msg.obj;
1203 request = (MainThreadRequest) ar.userObj;
1204 if (ar.exception != null) {
1205 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1206 } else {
1207 int mode = ((int[]) ar.result)[0];
1208 if (mode == 0) {
1209 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1210 } else {
1211 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1212 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001213 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001214 notifyRequester(request);
1215 break;
1216 case CMD_GET_CDMA_ROAMING_MODE:
1217 request = (MainThreadRequest) msg.obj;
1218 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1219 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1220 break;
1221 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1222 ar = (AsyncResult) msg.obj;
1223 request = (MainThreadRequest) ar.userObj;
1224 if (ar.exception != null) {
1225 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1226 } else {
1227 request.result = ((int[]) ar.result)[0];
1228 }
1229 notifyRequester(request);
1230 break;
1231 case CMD_SET_CDMA_ROAMING_MODE:
1232 request = (MainThreadRequest) msg.obj;
1233 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1234 int mode = (int) request.argument;
1235 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1236 break;
1237 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1238 ar = (AsyncResult) msg.obj;
1239 request = (MainThreadRequest) ar.userObj;
1240 request.result = ar.exception == null;
1241 notifyRequester(request);
1242 break;
1243 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1244 request = (MainThreadRequest) msg.obj;
1245 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1246 int subscriptionMode = (int) request.argument;
1247 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1248 break;
1249 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1250 ar = (AsyncResult) msg.obj;
1251 request = (MainThreadRequest) ar.userObj;
1252 request.result = ar.exception == null;
1253 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001254 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001255 case CMD_GET_ALL_CELL_INFO:
1256 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001257 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001258 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001259 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001260 case EVENT_GET_ALL_CELL_INFO_DONE:
1261 ar = (AsyncResult) msg.obj;
1262 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001263 // If a timeout occurs, the response will be null
1264 request.result = (ar.exception == null && ar.result != null)
1265 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001266 synchronized (request) {
1267 request.notifyAll();
1268 }
1269 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001270 case CMD_REQUEST_CELL_INFO_UPDATE:
1271 request = (MainThreadRequest) msg.obj;
1272 request.phone.requestCellInfoUpdate(request.workSource,
1273 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1274 break;
1275 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1276 ar = (AsyncResult) msg.obj;
1277 request = (MainThreadRequest) ar.userObj;
1278 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1279 try {
1280 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001281 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001282 cb.onError(
1283 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1284 ar.exception.getClass().getName(),
1285 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001286 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001287 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001288 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001289 } else {
1290 // use the result as returned
1291 cb.onCellInfo((List<CellInfo>) ar.result);
1292 }
1293 } catch (RemoteException re) {
1294 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1295 }
1296 break;
1297 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001298 request = (MainThreadRequest) msg.obj;
1299 WorkSource ws = (WorkSource) request.argument;
1300 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001301 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001302 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001303 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001304 ar = (AsyncResult) msg.obj;
1305 request = (MainThreadRequest) ar.userObj;
1306 if (ar.exception == null) {
1307 request.result = ar.result;
1308 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001309 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001310 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001311 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001312 }
1313
1314 synchronized (request) {
1315 request.notifyAll();
1316 }
1317 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001318 case CMD_MODEM_REBOOT:
1319 request = (MainThreadRequest) msg.obj;
1320 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001321 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001322 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001323 case EVENT_CMD_MODEM_REBOOT_DONE:
1324 handleNullReturnEvent(msg, "rebootModem");
1325 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001326 case CMD_REQUEST_ENABLE_MODEM:
1327 request = (MainThreadRequest) msg.obj;
1328 boolean enable = (boolean) request.argument;
1329 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001330 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001331 PhoneConfigurationManager.getInstance()
1332 .enablePhone(request.phone, enable, onCompleted);
1333 break;
1334 case EVENT_ENABLE_MODEM_DONE:
1335 ar = (AsyncResult) msg.obj;
1336 request = (MainThreadRequest) ar.userObj;
1337 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001338 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001339 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001340 if ((boolean) request.result) {
1341 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1342 updateModemStateMetrics();
1343 } else {
1344 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1345 + ar.exception);
1346 }
1347 notifyRequester(request);
1348 break;
1349 case CMD_GET_MODEM_STATUS:
1350 request = (MainThreadRequest) msg.obj;
1351 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1352 PhoneConfigurationManager.getInstance()
1353 .getPhoneStatusFromModem(request.phone, onCompleted);
1354 break;
1355 case EVENT_GET_MODEM_STATUS_DONE:
1356 ar = (AsyncResult) msg.obj;
1357 request = (MainThreadRequest) ar.userObj;
1358 int id = request.phone.getPhoneId();
1359 if (ar.exception == null && ar.result != null) {
1360 request.result = ar.result;
1361 //update the cache as modem status has changed
1362 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1363 (boolean) request.result);
1364 } else {
1365 // Return true if modem status cannot be retrieved. For most cases,
1366 // modem status is on. And for older version modems, GET_MODEM_STATUS
1367 // and disable modem are not supported. Modem is always on.
1368 // TODO: this should be fixed in R to support a third
1369 // status UNKNOWN b/131631629
1370 request.result = true;
1371 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1372 + ar.exception);
1373 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001374 notifyRequester(request);
1375 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001376 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1377 request = (MainThreadRequest) msg.obj;
1378 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1379 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1380 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1381 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1382 break;
1383 }
1384 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
1387 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1388 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1389 args.second.accept(ar.exception == null);
1390 notifyRequester(request);
1391 break;
1392 }
yincheng zhaod698b842019-09-06 17:06:54 -07001393 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1394 ar = (AsyncResult) msg.obj;
1395 request = (MainThreadRequest) ar.userObj;
1396 if (ar.exception == null && ar.result != null) {
1397 request.result = ar.result;
1398 } else {
1399 request.result = -1;
1400 loge("Failed to set Forbidden Plmns");
1401 if (ar.result == null) {
1402 loge("setForbidenPlmns: Empty response");
1403 } else if (ar.exception != null) {
1404 loge("setForbiddenPlmns: Exception: " + ar.exception);
1405 request.result = -1;
1406 } else {
1407 loge("setForbiddenPlmns: Unknown exception");
1408 }
1409 }
1410 notifyRequester(request);
1411 break;
1412 case CMD_SET_FORBIDDEN_PLMNS:
1413 request = (MainThreadRequest) msg.obj;
1414 uiccCard = getUiccCardFromRequest(request);
1415 if (uiccCard == null) {
1416 loge("setForbiddenPlmns: UiccCard is null");
1417 request.result = -1;
1418 notifyRequester(request);
1419 break;
1420 }
1421 Pair<Integer, List<String>> setFplmnsArgs =
1422 (Pair<Integer, List<String>>) request.argument;
1423 appType = setFplmnsArgs.first;
1424 List<String> fplmns = setFplmnsArgs.second;
1425 uiccApp = uiccCard.getApplicationByType(appType);
1426 if (uiccApp == null) {
1427 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1428 request.result = -1;
1429 loge("Failed to get UICC App");
1430 notifyRequester(request);
1431 } else {
1432 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1433 ((SIMRecords) uiccApp.getIccRecords())
1434 .setForbiddenPlmns(onCompleted, fplmns);
1435 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001436 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001437 case CMD_ERASE_MODEM_CONFIG:
1438 request = (MainThreadRequest) msg.obj;
1439 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1440 defaultPhone.eraseModemConfig(onCompleted);
1441 break;
1442 case EVENT_ERASE_MODEM_CONFIG_DONE:
1443 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001444 break;
zoey chenf95ca592019-12-30 16:11:23 +08001445
1446 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1447 request = (MainThreadRequest) msg.obj;
1448 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1449 Pair<String, String> changed = (Pair<String, String>) request.argument;
1450 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1451 changed.first, changed.second, onCompleted);
1452 break;
1453 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1454 ar = (AsyncResult) msg.obj;
1455 request = (MainThreadRequest) ar.userObj;
1456 if (ar.exception == null) {
1457 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1458 } else {
1459 request.result = msg.arg1;
1460 }
1461 notifyRequester(request);
1462 break;
1463
1464 case CMD_SET_ICC_LOCK_ENABLED:
1465 request = (MainThreadRequest) msg.obj;
1466 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1467 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1468 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1469 enabled.first, enabled.second, onCompleted);
1470 break;
1471 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1472 ar = (AsyncResult) msg.obj;
1473 request = (MainThreadRequest) ar.userObj;
1474 if (ar.exception == null) {
1475 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1476 } else {
1477 request.result = msg.arg1;
1478 }
1479 notifyRequester(request);
1480 break;
1481
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 default:
1483 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1484 break;
1485 }
1486 }
Jake Hambye994d462014-02-03 13:10:13 -08001487
Pengquan Menga1bb6272018-09-06 09:59:22 -07001488 private void notifyRequester(MainThreadRequest request) {
1489 synchronized (request) {
1490 request.notifyAll();
1491 }
1492 }
1493
Jake Hambye994d462014-02-03 13:10:13 -08001494 private void handleNullReturnEvent(Message msg, String command) {
1495 AsyncResult ar = (AsyncResult) msg.obj;
1496 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1497 if (ar.exception == null) {
1498 request.result = true;
1499 } else {
1500 request.result = false;
1501 if (ar.exception instanceof CommandException) {
1502 loge(command + ": CommandException: " + ar.exception);
1503 } else {
1504 loge(command + ": Unknown exception");
1505 }
1506 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001507 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 }
1510
1511 /**
1512 * Posts the specified command to be executed on the main thread,
1513 * waits for the request to complete, and returns the result.
1514 * @see #sendRequestAsync
1515 */
1516 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001517 return sendRequest(
1518 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001519 }
1520
1521 /**
1522 * Posts the specified command to be executed on the main thread,
1523 * waits for the request to complete, and returns the result.
1524 * @see #sendRequestAsync
1525 */
1526 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1527 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001528 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001529 }
1530
1531 /**
1532 * Posts the specified command to be executed on the main thread,
1533 * waits for the request to complete, and returns the result.
1534 * @see #sendRequestAsync
1535 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001536 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001537 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001538 }
1539
1540 /**
1541 * Posts the specified command to be executed on the main thread,
1542 * waits for the request to complete, and returns the result.
1543 * @see #sendRequestAsync
1544 */
Nathan Harold92bed182018-10-12 18:16:49 -07001545 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1546 return sendRequest(command, argument, subId, null, workSource);
1547 }
1548
1549 /**
1550 * Posts the specified command to be executed on the main thread,
1551 * waits for the request to complete, and returns the result.
1552 * @see #sendRequestAsync
1553 */
1554 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1555 return sendRequest(
1556 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1557 }
1558
1559 /**
1560 * Posts the specified command to be executed on the main thread,
1561 * waits for the request to complete, and returns the result.
1562 * @see #sendRequestAsync
1563 */
1564 private Object sendRequest(
1565 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1567 throw new RuntimeException("This method will deadlock if called from the main thread.");
1568 }
1569
Nathan Harold92bed182018-10-12 18:16:49 -07001570 MainThreadRequest request = null;
1571 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1572 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1573 } else if (phone != null) {
1574 request = new MainThreadRequest(argument, phone, workSource);
1575 } else {
1576 request = new MainThreadRequest(argument, subId, workSource);
1577 }
1578
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 Message msg = mMainThreadHandler.obtainMessage(command, request);
1580 msg.sendToTarget();
1581
1582 // Wait for the request to complete
1583 synchronized (request) {
1584 while (request.result == null) {
1585 try {
1586 request.wait();
1587 } catch (InterruptedException e) {
1588 // Do nothing, go back and wait until the request is complete
1589 }
1590 }
1591 }
1592 return request.result;
1593 }
1594
1595 /**
1596 * Asynchronous ("fire and forget") version of sendRequest():
1597 * Posts the specified command to be executed on the main thread, and
1598 * returns immediately.
1599 * @see #sendRequest
1600 */
1601 private void sendRequestAsync(int command) {
1602 mMainThreadHandler.sendEmptyMessage(command);
1603 }
1604
1605 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001606 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001607 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001608 */
1609 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001610 sendRequestAsync(command, argument, null, null);
1611 }
1612
1613 /**
1614 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1615 * @see {@link #sendRequest(int,Object)}
1616 */
1617 private void sendRequestAsync(
1618 int command, Object argument, Phone phone, WorkSource workSource) {
1619 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001620 Message msg = mMainThreadHandler.obtainMessage(command, request);
1621 msg.sendToTarget();
1622 }
1623
1624 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 * Initialize the singleton PhoneInterfaceManager instance.
1626 * This is only done once, at startup, from PhoneApp.onCreate().
1627 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001628 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 synchronized (PhoneInterfaceManager.class) {
1630 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001631 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001632 } else {
1633 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1634 }
1635 return sInstance;
1636 }
1637 }
1638
1639 /** Private constructor; @see init() */
Jordan Liua39e6c12020-03-04 13:59:23 -08001640 @VisibleForTesting
1641 /* package */ PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001644 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001645 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1647 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001648 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001649 mTelephonySharedPreferences =
1650 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001651 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001652 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001653
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 publish();
1655 }
1656
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001657 private Phone getDefaultPhone() {
1658 Phone thePhone = getPhone(getDefaultSubscription());
1659 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1660 }
1661
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 private void publish() {
1663 if (DBG) log("publish: " + this);
1664
1665 ServiceManager.addService("phone", this);
1666 }
1667
Stuart Scott584921c2015-01-15 17:10:34 -08001668 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001669 if (request.phone != null) {
1670 return request.phone;
1671 } else {
1672 return getPhoneFromSubId(request.subId);
1673 }
1674 }
1675
1676 private Phone getPhoneFromSubId(int subId) {
1677 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1678 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001679 }
1680
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001681 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1682 Phone phone = getPhoneFromRequest(request);
1683 return phone == null ? null :
1684 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1685 }
1686
Wink Saville36469e72014-06-11 15:17:00 -07001687 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001688 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001689 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001692 private void sendEraseModemConfig(Phone phone) {
1693 if (phone != null) {
1694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1695 mApp, phone.getSubId(), "eraseModemConfig");
1696 final long identity = Binder.clearCallingIdentity();
1697 try {
1698 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1699 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1700 } finally {
1701 Binder.restoreCallingIdentity(identity);
1702 }
1703 }
1704 }
1705
Peter Wang050bb052020-01-13 23:33:09 -08001706 private boolean isImsAvailableOnDevice() {
1707 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1708 if (pm == null) {
1709 // For some reason package manger is not available.. This will fail internally anyway,
1710 // so do not throw error and allow.
1711 return true;
1712 }
1713 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1714 }
1715
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001716 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001717 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001718 }
1719
Wink Savilleb564aae2014-10-23 10:18:09 -07001720 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001721 if (DBG) log("dial: " + number);
1722 // No permission check needed here: This is just a wrapper around the
1723 // ACTION_DIAL intent, which is available to any app since it puts up
1724 // the UI before it does anything.
1725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001726 final long identity = Binder.clearCallingIdentity();
1727 try {
1728 String url = createTelUrl(number);
1729 if (url == null) {
1730 return;
1731 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001733 // PENDING: should we just silently fail if phone is offhook or ringing?
1734 PhoneConstants.State state = mCM.getState(subId);
1735 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1736 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1737 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1738 mApp.startActivity(intent);
1739 }
1740 } finally {
1741 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 }
1743 }
1744
1745 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001746 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001747 }
1748
Wink Savilleb564aae2014-10-23 10:18:09 -07001749 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 if (DBG) log("call: " + number);
1751
1752 // This is just a wrapper around the ACTION_CALL intent, but we still
1753 // need to do a permission check since we're calling startActivity()
1754 // from the context of the phone app.
1755 enforceCallPermission();
1756
Jordan Liu1617b712019-07-10 15:06:26 -07001757 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 != AppOpsManager.MODE_ALLOWED) {
1759 return;
1760 }
1761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001762 final long identity = Binder.clearCallingIdentity();
1763 try {
1764 String url = createTelUrl(number);
1765 if (url == null) {
1766 return;
1767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001769 boolean isValid = false;
1770 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1771 if (slist != null) {
1772 for (SubscriptionInfo subInfoRecord : slist) {
1773 if (subInfoRecord.getSubscriptionId() == subId) {
1774 isValid = true;
1775 break;
1776 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001777 }
Wink Saville08874612014-08-31 19:19:58 -07001778 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001779 if (!isValid) {
1780 return;
1781 }
Wink Saville08874612014-08-31 19:19:58 -07001782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001783 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1784 intent.putExtra(SUBSCRIPTION_KEY, subId);
1785 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1786 mApp.startActivity(intent);
1787 } finally {
1788 Binder.restoreCallingIdentity(identity);
1789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 }
1791
Wink Savilleb564aae2014-10-23 10:18:09 -07001792 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001793 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001794 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1795 }
1796
Wink Savilleb564aae2014-10-23 10:18:09 -07001797 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001798 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001799 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1800 }
1801
Wink Savilleb564aae2014-10-23 10:18:09 -07001802 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001804
1805 final long identity = Binder.clearCallingIdentity();
1806 try {
1807 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1808 checkSimPin.start();
1809 return checkSimPin.unlockSim(null, pin);
1810 } finally {
1811 Binder.restoreCallingIdentity(identity);
1812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 }
1814
Wink Savilleb564aae2014-10-23 10:18:09 -07001815 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001817
1818 final long identity = Binder.clearCallingIdentity();
1819 try {
1820 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1821 checkSimPuk.start();
1822 return checkSimPuk.unlockSim(puk, pin);
1823 } finally {
1824 Binder.restoreCallingIdentity(identity);
1825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 }
1827
1828 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001829 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 * a synchronous one.
1831 */
1832 private static class UnlockSim extends Thread {
1833
1834 private final IccCard mSimCard;
1835
1836 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001837 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1838 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839
1840 // For replies from SimCard interface
1841 private Handler mHandler;
1842
1843 // For async handler to identify request type
1844 private static final int SUPPLY_PIN_COMPLETE = 100;
1845
1846 public UnlockSim(IccCard simCard) {
1847 mSimCard = simCard;
1848 }
1849
1850 @Override
1851 public void run() {
1852 Looper.prepare();
1853 synchronized (UnlockSim.this) {
1854 mHandler = new Handler() {
1855 @Override
1856 public void handleMessage(Message msg) {
1857 AsyncResult ar = (AsyncResult) msg.obj;
1858 switch (msg.what) {
1859 case SUPPLY_PIN_COMPLETE:
1860 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1861 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001862 mRetryCount = msg.arg1;
1863 if (ar.exception != null) {
1864 if (ar.exception instanceof CommandException &&
1865 ((CommandException)(ar.exception)).getCommandError()
1866 == CommandException.Error.PASSWORD_INCORRECT) {
1867 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001868 } //When UiccCardApp dispose,handle message and return exception
1869 else if (ar.exception instanceof CommandException &&
1870 ((CommandException) (ar.exception)).getCommandError()
1871 == CommandException.Error.ABORTED) {
1872 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001873 } else {
1874 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1875 }
1876 } else {
1877 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1878 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 mDone = true;
1880 UnlockSim.this.notifyAll();
1881 }
1882 break;
1883 }
1884 }
1885 };
1886 UnlockSim.this.notifyAll();
1887 }
1888 Looper.loop();
1889 }
1890
1891 /*
1892 * Use PIN or PUK to unlock SIM card
1893 *
1894 * If PUK is null, unlock SIM card with PIN
1895 *
1896 * If PUK is not null, unlock SIM card with PUK and set PIN code
1897 */
Wink Saville9de0f752013-10-22 19:04:03 -07001898 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899
1900 while (mHandler == null) {
1901 try {
1902 wait();
1903 } catch (InterruptedException e) {
1904 Thread.currentThread().interrupt();
1905 }
1906 }
1907 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1908
1909 if (puk == null) {
1910 mSimCard.supplyPin(pin, callback);
1911 } else {
1912 mSimCard.supplyPuk(puk, pin, callback);
1913 }
1914
1915 while (!mDone) {
1916 try {
1917 Log.d(LOG_TAG, "wait for done");
1918 wait();
1919 } catch (InterruptedException e) {
1920 // Restore the interrupted status
1921 Thread.currentThread().interrupt();
1922 }
1923 }
1924 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001925 int[] resultArray = new int[2];
1926 resultArray[0] = mResult;
1927 resultArray[1] = mRetryCount;
1928 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 }
1930 }
1931
1932 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001933 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001934
1935 }
1936
Nathan Harold1f889d82020-06-04 17:05:26 -07001937 @Override
1938 public void updateServiceLocationWithPackageName(String callingPackage) {
1939 mApp.getSystemService(AppOpsManager.class)
1940 .checkPackage(Binder.getCallingUid(), callingPackage);
1941
1942 final int targetSdk = getTargetSdk(callingPackage);
1943 if (targetSdk > android.os.Build.VERSION_CODES.R) {
1944 // Callers targeting S have no business invoking this method.
1945 return;
1946 }
1947
1948 LocationAccessPolicy.LocationPermissionResult locationResult =
1949 LocationAccessPolicy.checkLocationPermission(mApp,
1950 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1951 .setCallingPackage(callingPackage)
1952 .setCallingFeatureId(null)
1953 .setCallingPid(Binder.getCallingPid())
1954 .setCallingUid(Binder.getCallingUid())
1955 .setMethod("updateServiceLocation")
1956 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
1957 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1958 .build());
1959 // Apps that lack location permission have no business calling this method;
1960 // however, because no permission was declared in the public API, denials must
1961 // all be "soft".
1962 switch (locationResult) {
1963 case DENIED_HARD: /* fall through */
1964 case DENIED_SOFT:
1965 return;
1966 }
1967
1968 WorkSource workSource = getWorkSource(Binder.getCallingUid());
1969 final long identity = Binder.clearCallingIdentity();
1970 try {
1971 final Phone phone = getPhone(getDefaultSubscription());
1972 if (phone != null) {
1973 phone.updateServiceLocation(workSource);
1974 }
1975 } finally {
1976 Binder.restoreCallingIdentity(identity);
1977 }
1978 }
1979
Wink Savilleb564aae2014-10-23 10:18:09 -07001980 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 // No permission check needed here: this call is harmless, and it's
1982 // needed for the ServiceState.requestStateUpdate() call (which is
1983 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001984 final long identity = Binder.clearCallingIdentity();
1985 try {
1986 final Phone phone = getPhone(subId);
1987 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07001988 phone.updateServiceLocation(null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001989 }
1990 } finally {
1991 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001993 }
1994
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001995 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001996 @Override
1997 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001998 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001999 }
2000
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002001 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002002 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2003 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2004 callingFeatureId);
2005 }
2006
2007 @Deprecated
2008 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002009 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002010 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2011 }
2012
2013 @Override
2014 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2015 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002016 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002017 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002018 return false;
2019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020
2021 final long identity = Binder.clearCallingIdentity();
2022 try {
2023 return isRadioOnForSubscriber(subId);
2024 } finally {
2025 Binder.restoreCallingIdentity(identity);
2026 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002027 }
2028
2029 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002030 final long identity = Binder.clearCallingIdentity();
2031 try {
2032 final Phone phone = getPhone(subId);
2033 if (phone != null) {
2034 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2035 } else {
2036 return false;
2037 }
2038 } finally {
2039 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002040 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041 }
2042
2043 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002044 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 }
Wink Saville36469e72014-06-11 15:17:00 -07002046
Wink Savilleb564aae2014-10-23 10:18:09 -07002047 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002049
2050 final long identity = Binder.clearCallingIdentity();
2051 try {
2052 final Phone phone = getPhone(subId);
2053 if (phone != null) {
2054 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2055 }
2056 } finally {
2057 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002058 }
Wink Saville36469e72014-06-11 15:17:00 -07002059 }
2060
2061 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002062 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002063 }
2064
Wink Savilleb564aae2014-10-23 10:18:09 -07002065 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002066 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002067
2068 final long identity = Binder.clearCallingIdentity();
2069 try {
2070 final Phone phone = getPhone(subId);
2071 if (phone == null) {
2072 return false;
2073 }
2074 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2075 toggleRadioOnOffForSubscriber(subId);
2076 }
2077 return true;
2078 } finally {
2079 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 }
Wink Saville36469e72014-06-11 15:17:00 -07002082
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002083 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002084 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002085 /*
2086 * If any of the Radios are available, it will need to be
2087 * shutdown. So return true if any Radio is available.
2088 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002089 final long identity = Binder.clearCallingIdentity();
2090 try {
2091 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2092 Phone phone = PhoneFactory.getPhone(i);
2093 if (phone != null && phone.isRadioAvailable()) return true;
2094 }
2095 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2096 return false;
2097 } finally {
2098 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002099 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002100 }
2101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002102 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002103 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002104 enforceModifyPermission();
2105
2106 final long identity = Binder.clearCallingIdentity();
2107 try {
2108 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2109 logv("Shutting down Phone " + i);
2110 shutdownRadioUsingPhoneId(i);
2111 }
2112 } finally {
2113 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002114 }
2115 }
2116
2117 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002118 Phone phone = PhoneFactory.getPhone(phoneId);
2119 if (phone != null && phone.isRadioAvailable()) {
2120 phone.shutdownRadio();
2121 }
2122 }
2123
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002125 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002126
2127 final long identity = Binder.clearCallingIdentity();
2128 try {
2129 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2130 if (defaultPhone != null) {
2131 defaultPhone.setRadioPower(turnOn);
2132 return true;
2133 } else {
2134 loge("There's no default phone.");
2135 return false;
2136 }
2137 } finally {
2138 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002139 }
Wink Saville36469e72014-06-11 15:17:00 -07002140 }
2141
Wink Savilleb564aae2014-10-23 10:18:09 -07002142 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002144
2145 final long identity = Binder.clearCallingIdentity();
2146 try {
2147 final Phone phone = getPhone(subId);
2148 if (phone != null) {
2149 phone.setRadioPower(turnOn);
2150 return true;
2151 } else {
2152 return false;
2153 }
2154 } finally {
2155 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 }
2158
Wink Saville36469e72014-06-11 15:17:00 -07002159 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002160 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 public boolean enableDataConnectivity() {
2162 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002163
2164 final long identity = Binder.clearCallingIdentity();
2165 try {
2166 int subId = mSubscriptionController.getDefaultDataSubId();
2167 final Phone phone = getPhone(subId);
2168 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002169 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002170 return true;
2171 } else {
2172 return false;
2173 }
2174 } finally {
2175 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 }
2178
Wink Saville36469e72014-06-11 15:17:00 -07002179 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002180 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 public boolean disableDataConnectivity() {
2182 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002183
2184 final long identity = Binder.clearCallingIdentity();
2185 try {
2186 int subId = mSubscriptionController.getDefaultDataSubId();
2187 final Phone phone = getPhone(subId);
2188 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002189 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002190 return true;
2191 } else {
2192 return false;
2193 }
2194 } finally {
2195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 }
2198
Sanket Padawe356d7632015-06-22 14:03:32 -07002199 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002200 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002201 final long identity = Binder.clearCallingIdentity();
2202 try {
2203 final Phone phone = getPhone(subId);
2204 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002205 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002206 } else {
2207 return false;
2208 }
2209 } finally {
2210 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002211 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002212 }
2213
2214 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002215 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002216 }
2217
pkanwarae03a6b2016-11-06 20:37:09 -08002218 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002219 enforceCallPermission();
2220
2221 final long identity = Binder.clearCallingIdentity();
2222 try {
2223 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2224 return;
2225 }
2226 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2227 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2228 } finally {
2229 Binder.restoreCallingIdentity(identity);
2230 }
pkanwar32d516d2016-10-14 19:37:38 -07002231 };
2232
Wink Savilleb564aae2014-10-23 10:18:09 -07002233 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002235
2236 final long identity = Binder.clearCallingIdentity();
2237 try {
2238 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2239 return false;
2240 }
2241 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2242 } finally {
2243 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 }
2246
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002248 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002249 }
2250
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002251 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002252 final long identity = Binder.clearCallingIdentity();
2253 try {
2254 Phone phone = PhoneFactory.getPhone(slotIndex);
2255 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2256 PhoneConstantConversions.convertCallState(phone.getState());
2257 } finally {
2258 Binder.restoreCallingIdentity(identity);
2259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 }
2261
Sanket Padawe356d7632015-06-22 14:03:32 -07002262 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002263 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002264 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2265 }
2266
2267 @Override
2268 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002269 final long identity = Binder.clearCallingIdentity();
2270 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002271 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002272 if (phone != null) {
2273 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2274 } else {
2275 return PhoneConstantConversions.convertDataState(
2276 PhoneConstants.DataState.DISCONNECTED);
2277 }
2278 } finally {
2279 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 }
2282
Sanket Padawe356d7632015-06-22 14:03:32 -07002283 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002284 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002285 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2286 }
2287
2288 @Override
2289 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290 final long identity = Binder.clearCallingIdentity();
2291 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002292 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002293 if (phone != null) {
2294 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2295 } else {
2296 return TelephonyManager.DATA_ACTIVITY_NONE;
2297 }
2298 } finally {
2299 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
2303 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002304 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002305 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002306 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002307
2308 LocationAccessPolicy.LocationPermissionResult locationResult =
2309 LocationAccessPolicy.checkLocationPermission(mApp,
2310 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2311 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002312 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002313 .setCallingPid(Binder.getCallingPid())
2314 .setCallingUid(Binder.getCallingUid())
2315 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002316 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002317 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2318 .build());
2319 switch (locationResult) {
2320 case DENIED_HARD:
2321 throw new SecurityException("Not allowed to access cell location");
2322 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002323 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2324 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002325 }
2326
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002327 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002331 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002332 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002333 } finally {
2334 Binder.restoreCallingIdentity(identity);
2335 }
Svetoslav64fad262015-04-14 14:35:21 -07002336 }
2337
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 @Override
Jack Yu01425032020-02-22 19:38:58 -08002339 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002340 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2341 // registered cell info, so return a NULL country instead.
2342 final long identity = Binder.clearCallingIdentity();
2343 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002344 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2345 // Get default phone in this case.
2346 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2347 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002348 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002349 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002350 if (phone == null) return "";
2351 ServiceStateTracker sst = phone.getServiceStateTracker();
2352 if (sst == null) return "";
2353 LocaleTracker lt = sst.getLocaleTracker();
2354 if (lt == null) return "";
2355 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2356 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2357 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002358 } finally {
2359 Binder.restoreCallingIdentity(identity);
2360 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002361 }
2362
2363 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002365 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002366 }
2367
Sanket Padawe356d7632015-06-22 14:03:32 -07002368 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002369 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 mApp.enforceCallingOrSelfPermission(
2371 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002372
2373 final long identity = Binder.clearCallingIdentity();
2374 try {
2375 final Phone phone = getPhone(subId);
2376 if (phone != null) {
2377 phone.enableLocationUpdates();
2378 }
2379 } finally {
2380 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382 }
2383
2384 @Override
2385 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002386 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002387 }
2388
Sanket Padawe356d7632015-06-22 14:03:32 -07002389 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002390 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 mApp.enforceCallingOrSelfPermission(
2392 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002393
2394 final long identity = Binder.clearCallingIdentity();
2395 try {
2396 final Phone phone = getPhone(subId);
2397 if (phone != null) {
2398 phone.disableLocationUpdates();
2399 }
2400 } finally {
2401 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 }
2404
Nathan Harold31d7ff32018-10-15 20:20:30 -07002405 /**
2406 * Returns the target SDK version number for a given package name.
2407 *
Nathan Haroldec184742019-07-10 17:04:16 -07002408 * This call MUST be invoked before clearing the calling UID.
2409 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002410 * @return target SDK if the package is found or INT_MAX.
2411 */
2412 private int getTargetSdk(String packageName) {
2413 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002414 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002415 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002416 if (ai != null) return ai.targetSdkVersion;
2417 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002418 loge("Failed to get package info for pkg="
2419 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002420 }
2421 return Integer.MAX_VALUE;
2422 }
2423
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 @Override
2425 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002426 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2427 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002428 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002429 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2430 throw new SecurityException(
2431 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2432 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002433
Jordan Liu1617b712019-07-10 15:06:26 -07002434 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2436 return null;
2437 }
Svetoslav64fad262015-04-14 14:35:21 -07002438
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002439 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002441 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002442 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443
Nathan Haroldf180aac2018-06-01 18:43:55 -07002444 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2445 for (CellInfo ci : info) {
2446 if (ci instanceof CellInfoGsm) {
2447 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2448 } else if (ci instanceof CellInfoWcdma) {
2449 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002452 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 }
2454
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002455 private List<CellInfo> getCachedCellInfo() {
2456 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2457 for (Phone phone : PhoneFactory.getPhones()) {
2458 List<CellInfo> info = phone.getAllCellInfo();
2459 if (info != null) cellInfos.addAll(info);
2460 }
2461 return cellInfos;
2462 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463
2464 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002465 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002466 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002467 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002468
2469 LocationAccessPolicy.LocationPermissionResult locationResult =
2470 LocationAccessPolicy.checkLocationPermission(mApp,
2471 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2472 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002473 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002474 .setCallingPid(Binder.getCallingPid())
2475 .setCallingUid(Binder.getCallingUid())
2476 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002477 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002478 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2479 .build());
2480 switch (locationResult) {
2481 case DENIED_HARD:
2482 throw new SecurityException("Not allowed to access cell info");
2483 case DENIED_SOFT:
2484 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002487 final int targetSdk = getTargetSdk(callingPackage);
2488 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2489 return getCachedCellInfo();
2490 }
2491
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002492 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002493 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002494 final long identity = Binder.clearCallingIdentity();
2495 try {
2496 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2497 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002498 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002499 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500 if (info != null) cellInfos.addAll(info);
2501 }
2502 return cellInfos;
2503 } finally {
2504 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002505 }
2506 }
2507
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002508 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002509 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2510 String callingFeatureId) {
2511 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2512 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002513 }
2514
2515 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002516 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2517 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002518 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002519 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002520 }
2521
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002522 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2523 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002524 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002525 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002526
2527 LocationAccessPolicy.LocationPermissionResult locationResult =
2528 LocationAccessPolicy.checkLocationPermission(mApp,
2529 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2530 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002531 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002532 .setCallingPid(Binder.getCallingPid())
2533 .setCallingUid(Binder.getCallingUid())
2534 .setMethod("requestCellInfoUpdate")
2535 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2536 .build());
2537 switch (locationResult) {
2538 case DENIED_HARD:
2539 throw new SecurityException("Not allowed to access cell info");
2540 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002541 try {
2542 cb.onCellInfo(new ArrayList<CellInfo>());
2543 } catch (RemoteException re) {
2544 // Drop without consequences
2545 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002546 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002547 }
2548
Nathan Harolda939a962019-05-09 10:13:47 -07002549
2550 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002551 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2552
2553 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2554 }
2555
2556 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002558 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002559 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002560
2561 final long identity = Binder.clearCallingIdentity();
2562 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002563 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564 } finally {
2565 Binder.restoreCallingIdentity(identity);
2566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 }
2568
Shishir Agrawala9f32182016-04-12 12:00:16 -07002569 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002570 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002571 Phone phone = PhoneFactory.getPhone(slotIndex);
2572 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002573 return null;
2574 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002575 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002576 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002577 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002578 return null;
2579 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002580
2581 final long identity = Binder.clearCallingIdentity();
2582 try {
2583 return phone.getImei();
2584 } finally {
2585 Binder.restoreCallingIdentity(identity);
2586 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002587 }
2588
2589 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002590 public String getTypeAllocationCodeForSlot(int slotIndex) {
2591 Phone phone = PhoneFactory.getPhone(slotIndex);
2592 String tac = null;
2593 if (phone != null) {
2594 String imei = phone.getImei();
2595 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2596 }
2597 return tac;
2598 }
2599
2600 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002601 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002602 Phone phone = PhoneFactory.getPhone(slotIndex);
2603 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002604 return null;
2605 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002606
Jeff Davidson913390f2018-02-23 17:11:49 -08002607 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002608 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002609 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002610 return null;
2611 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612
2613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 return phone.getMeid();
2616 } finally {
2617 Binder.restoreCallingIdentity(identity);
2618 }
Jack Yu2af8d712017-03-15 17:14:14 -07002619 }
2620
2621 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002622 public String getManufacturerCodeForSlot(int slotIndex) {
2623 Phone phone = PhoneFactory.getPhone(slotIndex);
2624 String manufacturerCode = null;
2625 if (phone != null) {
2626 String meid = phone.getMeid();
2627 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2628 }
2629 return manufacturerCode;
2630 }
2631
2632 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002633 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2634 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002635 Phone phone = PhoneFactory.getPhone(slotIndex);
2636 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002637 return null;
2638 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002639 int subId = phone.getSubId();
2640 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002641 mApp, subId, callingPackage, callingFeatureId,
2642 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002643 return null;
2644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002645
2646 final long identity = Binder.clearCallingIdentity();
2647 try {
2648 return phone.getDeviceSvn();
2649 } finally {
2650 Binder.restoreCallingIdentity(identity);
2651 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002652 }
2653
fionaxu43304da2017-11-27 22:51:16 -08002654 @Override
2655 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 final Phone phone = getPhone(subId);
2659 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2660 } finally {
2661 Binder.restoreCallingIdentity(identity);
2662 }
fionaxu43304da2017-11-27 22:51:16 -08002663 }
2664
2665 @Override
2666 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 final Phone phone = getPhone(subId);
2670 return phone == null ? null : phone.getCarrierName();
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
2673 }
fionaxu43304da2017-11-27 22:51:16 -08002674 }
2675
calvinpanffe225e2018-11-01 19:43:06 +08002676 @Override
chen xu0026ca62019-03-06 15:28:50 -08002677 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002678 final long identity = Binder.clearCallingIdentity();
2679 try {
2680 final Phone phone = getPhone(subId);
2681 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002682 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002683 } finally {
2684 Binder.restoreCallingIdentity(identity);
2685 }
2686 }
2687
2688 @Override
chen xu0026ca62019-03-06 15:28:50 -08002689 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002690 final long identity = Binder.clearCallingIdentity();
2691 try {
2692 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002693 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002694 } finally {
2695 Binder.restoreCallingIdentity(identity);
2696 }
2697 }
2698
chen xu651eec72018-11-11 19:03:44 -08002699 @Override
chen xu864e11c2018-12-06 22:10:03 -08002700 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2701 if (!isSubscriptionMccMnc) {
2702 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2703 }
chen xu651eec72018-11-11 19:03:44 -08002704 final Phone phone = PhoneFactory.getPhone(slotIndex);
2705 if (phone == null) {
2706 return TelephonyManager.UNKNOWN_CARRIER_ID;
2707 }
2708 final long identity = Binder.clearCallingIdentity();
2709 try {
2710 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
2713 }
2714 }
2715
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 //
2717 // Internal helper methods.
2718 //
2719
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002720 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2722 *
2723 * @throws SecurityException if the caller does not have the required permission
2724 */
2725 private void enforceModifyPermission() {
2726 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2727 }
2728
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002729 /**
2730 * Make sure the caller is system.
2731 *
2732 * @throws SecurityException if the caller is not system.
2733 */
2734 private void enforceSystemCaller() {
2735 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2736 throw new SecurityException("Caller must be system");
2737 }
2738 }
2739
Shuo Qianf2b2df42019-11-13 17:43:31 -08002740 private void enforceActiveEmergencySessionPermission() {
2741 mApp.enforceCallingOrSelfPermission(
2742 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2743 }
2744
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 /**
2746 * Make sure the caller has the CALL_PHONE permission.
2747 *
2748 * @throws SecurityException if the caller does not have the required permission
2749 */
2750 private void enforceCallPermission() {
2751 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2752 }
2753
paulhu423b5f22019-08-23 19:17:33 +08002754 private void enforceSettingsPermission() {
2755 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002756 }
2757
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002758 private String createTelUrl(String number) {
2759 if (TextUtils.isEmpty(number)) {
2760 return null;
2761 }
2762
Jake Hambye994d462014-02-03 13:10:13 -08002763 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002764 }
2765
Ihab Awadf9e92732013-12-05 18:02:52 -08002766 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002767 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2768 }
2769
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002770 private static void logv(String msg) {
2771 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2772 }
2773
Ihab Awadf9e92732013-12-05 18:02:52 -08002774 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2776 }
2777
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002778 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002780 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002781 }
2782
Sanket Padawe356d7632015-06-22 14:03:32 -07002783 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002784 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 final long identity = Binder.clearCallingIdentity();
2786 try {
2787 final Phone phone = PhoneFactory.getPhone(slotIndex);
2788 if (phone == null) {
2789 return PhoneConstants.PHONE_TYPE_NONE;
2790 } else {
2791 return phone.getPhoneType();
2792 }
2793 } finally {
2794 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 }
2797
2798 /**
2799 * Returns the CDMA ERI icon index to display
2800 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002801 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002802 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2803 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2804 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002805 }
2806
Sanket Padawe356d7632015-06-22 14:03:32 -07002807 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002808 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2809 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002810 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002811 mApp, subId, callingPackage, callingFeatureId,
2812 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002813 return -1;
2814 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815
2816 final long identity = Binder.clearCallingIdentity();
2817 try {
2818 final Phone phone = getPhone(subId);
2819 if (phone != null) {
2820 return phone.getCdmaEriIconIndex();
2821 } else {
2822 return -1;
2823 }
2824 } finally {
2825 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002826 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827 }
2828
2829 /**
2830 * Returns the CDMA ERI icon mode,
2831 * 0 - ON
2832 * 1 - FLASHING
2833 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002834 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002835 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2836 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2837 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002838 }
2839
Sanket Padawe356d7632015-06-22 14:03:32 -07002840 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002841 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2842 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002843 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002844 mApp, subId, callingPackage, callingFeatureId,
2845 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002846 return -1;
2847 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848
2849 final long identity = Binder.clearCallingIdentity();
2850 try {
2851 final Phone phone = getPhone(subId);
2852 if (phone != null) {
2853 return phone.getCdmaEriIconMode();
2854 } else {
2855 return -1;
2856 }
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 }
2861
2862 /**
2863 * Returns the CDMA ERI text,
2864 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002865 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002866 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2867 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2868 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002869 }
2870
Sanket Padawe356d7632015-06-22 14:03:32 -07002871 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002872 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2873 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002874 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002875 mApp, subId, callingPackage, callingFeatureId,
2876 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002877 return null;
2878 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879
2880 final long identity = Binder.clearCallingIdentity();
2881 try {
2882 final Phone phone = getPhone(subId);
2883 if (phone != null) {
2884 return phone.getCdmaEriText();
2885 } else {
2886 return null;
2887 }
2888 } finally {
2889 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002890 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 }
2892
2893 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002894 * Returns the CDMA MDN.
2895 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002896 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002897 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2899 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900
2901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002904 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 return phone.getLine1Number();
2906 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002907 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908 return null;
2909 }
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002912 }
2913 }
2914
2915 /**
2916 * Returns the CDMA MIN.
2917 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002918 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002919 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2921 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922
2923 final long identity = Binder.clearCallingIdentity();
2924 try {
2925 final Phone phone = getPhone(subId);
2926 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2927 return phone.getCdmaMin();
2928 } else {
2929 return null;
2930 }
2931 } finally {
2932 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002933 }
2934 }
2935
Hall Liud892bec2018-11-30 14:51:45 -08002936 @Override
2937 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2938 INumberVerificationCallback callback, String callingPackage) {
2939 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2940 != PERMISSION_GRANTED) {
2941 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2942 }
2943 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2944
2945 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2946 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2947 throw new SecurityException("Calling package must be configured in the device config");
2948 }
2949
2950 if (range == null) {
2951 throw new NullPointerException("Range must be non-null");
2952 }
2953
2954 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002955 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002956
2957 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2958 }
2959
Junda Liuca05d5d2014-08-14 22:36:34 -07002960 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002961 * Returns true if CDMA provisioning needs to run.
2962 */
2963 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002964 final long identity = Binder.clearCallingIdentity();
2965 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002966 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002970 }
2971
2972 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002973 * Sets the voice mail number of a given subId.
2974 */
2975 @Override
2976 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002977 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2978 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979
2980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2983 new Pair<String, String>(alphaTag, number), new Integer(subId));
2984 return success;
2985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002988 }
2989
Ta-wei Yen87c49842016-05-13 21:19:52 -07002990 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002991 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2992 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002993 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2994 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002995 if (!TextUtils.equals(callingPackage, systemDialer)) {
2996 throw new SecurityException("caller must be system dialer");
2997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998
2999 final long identity = Binder.clearCallingIdentity();
3000 try {
3001 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3002 if (phoneAccountHandle == null) {
3003 return null;
3004 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003005 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006 } finally {
3007 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003008 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003009 }
3010
3011 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003012 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3013 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003014 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003015 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003016 mApp, subId, callingPackage, callingFeatureId,
3017 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003018 return null;
3019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003021 final long identity = Binder.clearCallingIdentity();
3022 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003023 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003027 }
3028
3029 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003030 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3031 VisualVoicemailSmsFilterSettings settings) {
3032 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003033
3034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003037 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003041 }
3042
3043 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003044 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3045 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003046
3047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003050 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051 } finally {
3052 Binder.restoreCallingIdentity(identity);
3053 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003054 }
3055
3056 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003057 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3058 String callingPackage, int subId) {
3059 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003064 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003068 }
3069
3070 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003071 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003072 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003073
3074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003077 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003081 }
3082
3083 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003084 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3085 String callingAttributionTag, int subId, String number, int port, String text,
3086 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003087 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003088 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003089 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003090 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003091 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3092 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003093 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003094
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003095 /**
fionaxu0152e512016-11-14 13:36:14 -08003096 * Sets the voice activation state of a given subId.
3097 */
3098 @Override
3099 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3101 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102
3103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 final Phone phone = getPhone(subId);
3106 if (phone != null) {
3107 phone.setVoiceActivationState(activationState);
3108 } else {
3109 loge("setVoiceActivationState fails with invalid subId: " + subId);
3110 }
3111 } finally {
3112 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003113 }
3114 }
3115
3116 /**
3117 * Sets the data activation state of a given subId.
3118 */
3119 @Override
3120 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3122 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123
3124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 final Phone phone = getPhone(subId);
3127 if (phone != null) {
3128 phone.setDataActivationState(activationState);
3129 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003130 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003131 }
3132 } finally {
3133 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003134 }
3135 }
3136
3137 /**
3138 * Returns the voice activation state of a given subId.
3139 */
3140 @Override
3141 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003142 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003143
fionaxu0152e512016-11-14 13:36:14 -08003144 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 if (phone != null) {
3148 return phone.getVoiceActivationState();
3149 } else {
3150 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3151 }
3152 } finally {
3153 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003154 }
3155 }
3156
3157 /**
3158 * Returns the data activation state of a given subId.
3159 */
3160 @Override
3161 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003162 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003163
fionaxu0152e512016-11-14 13:36:14 -08003164 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 if (phone != null) {
3168 return phone.getDataActivationState();
3169 } else {
3170 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3171 }
3172 } finally {
3173 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003174 }
3175 }
3176
3177 /**
Wink Saville36469e72014-06-11 15:17:00 -07003178 * Returns the unread count of voicemails for a subId
3179 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003180 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003181 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3182 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003183 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003184 mApp, subId, callingPackage, callingFeatureId,
3185 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003186 return 0;
3187 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188 final long identity = Binder.clearCallingIdentity();
3189 try {
3190 final Phone phone = getPhone(subId);
3191 if (phone != null) {
3192 return phone.getVoiceMessageCount();
3193 } else {
3194 return 0;
3195 }
3196 } finally {
3197 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003198 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003199 }
3200
3201 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003202 * returns true, if the device is in a state where both voice and data
3203 * are supported simultaneously. This can change based on location or network condition.
3204 */
3205 @Override
3206 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 final long identity = Binder.clearCallingIdentity();
3208 try {
3209 final Phone phone = getPhone(subId);
3210 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3211 } finally {
3212 Binder.restoreCallingIdentity(identity);
3213 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003214 }
3215
3216 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003217 * Send the dialer code if called from the current default dialer or the caller has
3218 * carrier privilege.
3219 * @param inputCode The dialer code to send
3220 */
3221 @Override
3222 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003223 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003224 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003225 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3226 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003227 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003228 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003229 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003230 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003231
3232 final long identity = Binder.clearCallingIdentity();
3233 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003234 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235 } finally {
3236 Binder.restoreCallingIdentity(identity);
3237 }
fionaxu235cc5e2017-03-06 22:25:57 -08003238 }
3239
Pengquan Menga1bb6272018-09-06 09:59:22 -07003240 @Override
3241 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003242 TelephonyPermissions
3243 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3244 mApp, subId, "getNetworkSelectionMode");
3245 final long identity = Binder.clearCallingIdentity();
3246 try {
3247 if (!isActiveSubscription(subId)) {
3248 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3249 }
3250 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3251 } finally {
3252 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003253 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003254 }
3255
Brad Ebinger35c841c2018-10-01 10:40:55 -07003256 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003257 public boolean isInEmergencySmsMode() {
3258 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3259 final long identity = Binder.clearCallingIdentity();
3260 try {
3261 for (Phone phone : PhoneFactory.getPhones()) {
3262 if (phone.isInEmergencySmsMode()) {
3263 return true;
3264 }
3265 }
3266 } finally {
3267 Binder.restoreCallingIdentity(identity);
3268 }
3269 return false;
3270 }
3271
shilu366312e2019-12-17 09:28:10 -08003272 /**
3273 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3274 * @param subId The subscription to use to check the configuration.
3275 * @param c The callback that will be used to send the result.
3276 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003277 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003278 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3279 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003280 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3281 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003282
Brad Ebinger77b832e2019-10-17 17:03:22 -07003283 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3284 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3285 "IMS not available on device.");
3286 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003287 final long token = Binder.clearCallingIdentity();
3288 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003289 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003290 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003291 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003292 } catch (ImsException e) {
3293 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003294 } finally {
3295 Binder.restoreCallingIdentity(token);
3296 }
3297 }
3298
shilu366312e2019-12-17 09:28:10 -08003299 /**
3300 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3301 * @param subId The subscription to use to check the configuration.
3302 * @param c The callback that will be used to send the result.
3303 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003304 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003305 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003306 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3307 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003308 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3309 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3310 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003311 final long token = Binder.clearCallingIdentity();
3312 try {
3313 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3314 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3315 .removeRegistrationCallbackForSubscription(c, subId);
3316 } catch (ImsException e) {
3317 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3318 + "is inactive, ignoring unregister.");
3319 // If the subscription is no longer active, just return, since the callback
3320 // will already have been removed internally.
3321 } finally {
3322 Binder.restoreCallingIdentity(token);
3323 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003324 }
3325
Brad Ebinger774ba362019-10-22 17:36:18 -07003326 /**
3327 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3328 */
3329 @Override
3330 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3331 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3332 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3333 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3334 "IMS not available on device.");
3335 }
3336 final long token = Binder.clearCallingIdentity();
3337 try {
3338 Phone phone = getPhone(subId);
3339 if (phone == null) {
3340 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3341 + subId + "'");
3342 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3343 }
3344 phone.getImsRegistrationState(regState -> {
3345 try {
3346 consumer.accept((regState == null)
3347 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3348 } catch (RemoteException e) {
3349 // Ignore if the remote process is no longer available to call back.
3350 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3351 }
3352 });
3353 } finally {
3354 Binder.restoreCallingIdentity(token);
3355 }
3356 }
3357
3358 /**
3359 * Get the transport type for the IMS service registration state.
3360 */
3361 @Override
3362 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003363 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3364 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003365 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3366 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3367 "IMS not available on device.");
3368 }
3369 final long token = Binder.clearCallingIdentity();
3370 try {
3371 Phone phone = getPhone(subId);
3372 if (phone == null) {
3373 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3374 + subId + "'");
3375 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3376 }
3377 phone.getImsRegistrationTech(regTech -> {
3378 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3379 int regTechConverted = (regTech == null)
3380 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3381 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3382 regTechConverted);
3383 try {
3384 consumer.accept(regTechConverted);
3385 } catch (RemoteException e) {
3386 // Ignore if the remote process is no longer available to call back.
3387 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3388 }
3389 });
3390 } finally {
3391 Binder.restoreCallingIdentity(token);
3392 }
3393 }
3394
shilu366312e2019-12-17 09:28:10 -08003395 /**
3396 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3397 * @param subId The subscription to use to check the configuration.
3398 * @param c The callback that will be used to send the result.
3399 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003400 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003401 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3402 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003403 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3404 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003405 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3406 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3407 "IMS not available on device.");
3408 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003409 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3410 final long token = Binder.clearCallingIdentity();
3411 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003412 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003413 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003414 } catch (ImsException e) {
3415 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003416 } finally {
3417 Binder.restoreCallingIdentity(token);
3418 }
3419 }
3420
shilu366312e2019-12-17 09:28:10 -08003421 /**
3422 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3423 * @param subId The subscription to use to check the configuration.
3424 * @param c The callback that will be used to send the result.
3425 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003427 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003428 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3429 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003430 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3431 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3432 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003433
3434 final long token = Binder.clearCallingIdentity();
3435 try {
3436 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3437 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003438 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003439 } catch (ImsException e) {
3440 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3441 + "is inactive, ignoring unregister.");
3442 // If the subscription is no longer active, just return, since the callback
3443 // will already have been removed internally.
3444 } finally {
3445 Binder.restoreCallingIdentity(token);
3446 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003447 }
3448
3449 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003450 public boolean isCapable(int subId, int capability, int regTech) {
3451 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003452 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3453 final long token = Binder.clearCallingIdentity();
3454 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003455 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003456 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003457 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003458 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3459 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003460 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003461 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3462 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003463 } finally {
3464 Binder.restoreCallingIdentity(token);
3465 }
3466 }
3467
3468 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003469 public boolean isAvailable(int subId, int capability, int regTech) {
3470 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003471 final long token = Binder.clearCallingIdentity();
3472 try {
3473 Phone phone = getPhone(subId);
3474 if (phone == null) return false;
3475 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003476 } catch (com.android.ims.ImsException e) {
3477 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3478 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003479 } finally {
3480 Binder.restoreCallingIdentity(token);
3481 }
3482 }
3483
Brad Ebinger77b832e2019-10-17 17:03:22 -07003484 /**
3485 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3486 * subscription.
3487 * @param subId The subscription to use to check the configuration.
3488 * @param callback The callback that will be used to send the result.
3489 * @param capability The MmTelFeature capability that will be used to send the result.
3490 * @param transportType The transport type of the MmTelFeature capability.
3491 */
3492 @Override
3493 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3494 int transportType) {
3495 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3496 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3497 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3498 "IMS not available on device.");
3499 }
3500 final long token = Binder.clearCallingIdentity();
3501 try {
3502 int slotId = getSlotIndex(subId);
3503 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3504 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3505 + subId + "'");
3506 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3507 }
3508 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3509 transportType, aBoolean -> {
3510 try {
3511 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3512 } catch (RemoteException e) {
3513 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3514 + "running. Ignore");
3515 }
3516 });
3517 } finally {
3518 Binder.restoreCallingIdentity(token);
3519 }
3520 }
3521
shilu366312e2019-12-17 09:28:10 -08003522 /**
3523 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3524 * @param subId The subscription to use to check the configuration.
3525 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003526 @Override
3527 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003528 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3529 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003530
Brad Ebinger35c841c2018-10-01 10:40:55 -07003531 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3532 final long token = Binder.clearCallingIdentity();
3533 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003534 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003535 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003536 } catch (ImsException e) {
3537 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003538 } finally {
3539 Binder.restoreCallingIdentity(token);
3540 }
3541 }
3542
3543 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003544 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003546 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003550 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003551 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003552 } catch (ImsException e) {
3553 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003554 } finally {
3555 Binder.restoreCallingIdentity(identity);
3556 }
3557 }
3558
shilu366312e2019-12-17 09:28:10 -08003559 /**
3560 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3561 * @param subId The subscription to use to check the configuration.
3562 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003563 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003564 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003565 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3566 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003567 final long identity = Binder.clearCallingIdentity();
3568 try {
3569 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003570 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3571 } catch (ImsException e) {
3572 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003573 } finally {
3574 Binder.restoreCallingIdentity(identity);
3575 }
3576 }
3577
3578 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003579 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003581 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003585 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003586 } catch (ImsException e) {
3587 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003588 } finally {
3589 Binder.restoreCallingIdentity(identity);
3590 }
3591 }
3592
shilu366312e2019-12-17 09:28:10 -08003593 /**
3594 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3595 * @param subId The subscription to use to check the configuration.
3596 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003597 @Override
3598 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003599 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3600 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003601 final long identity = Binder.clearCallingIdentity();
3602 try {
3603 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003604 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003605 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003606 } catch (ImsException e) {
3607 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003608 } finally {
3609 Binder.restoreCallingIdentity(identity);
3610 }
3611 }
3612
3613 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003614 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003616 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003617 final long identity = Binder.clearCallingIdentity();
3618 try {
3619 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003620 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003621 } catch (ImsException e) {
3622 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003623 } finally {
3624 Binder.restoreCallingIdentity(identity);
3625 }
3626 }
3627
shilu366312e2019-12-17 09:28:10 -08003628 /**
3629 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3630 * @param subId The subscription to use to check the configuration.
3631 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003632 @Override
3633 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003634 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3635 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003636 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 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003640 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
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
3648 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003649 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003651 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003652 final long identity = Binder.clearCallingIdentity();
3653 try {
3654 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003655 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003656 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003657 } catch (ImsException e) {
3658 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003659 } finally {
3660 Binder.restoreCallingIdentity(identity);
3661 }
3662 }
3663
3664 @Override
3665 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3667 "setVoWiFiNonPersistent");
3668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003671 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003672 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003673 } catch (ImsException e) {
3674 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003675 } finally {
3676 Binder.restoreCallingIdentity(identity);
3677 }
3678 }
3679
shilu366312e2019-12-17 09:28:10 -08003680 /**
3681 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3682 * @param subId The subscription to use to check the configuration.
3683 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003684 @Override
3685 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003686 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3687 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003691 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003692 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003693 } catch (ImsException e) {
3694 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003695 } finally {
3696 Binder.restoreCallingIdentity(identity);
3697 }
3698 }
3699
3700 @Override
3701 public void setVoWiFiModeSetting(int subId, int mode) {
3702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3703 "setVoWiFiModeSetting");
3704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003707 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003708 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003709 } catch (ImsException e) {
3710 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
3714 }
3715
3716 @Override
3717 public int getVoWiFiRoamingModeSetting(int subId) {
3718 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3719 final long identity = Binder.clearCallingIdentity();
3720 try {
3721 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003722 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003723 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003724 } catch (ImsException e) {
3725 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
3729 }
3730
3731 @Override
3732 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3734 "setVoWiFiRoamingModeSetting");
3735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003738 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003739 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003740 } catch (ImsException e) {
3741 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003742 } finally {
3743 Binder.restoreCallingIdentity(identity);
3744 }
3745 }
3746
3747 @Override
3748 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3750 "setRttCapabilityEnabled");
3751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003754 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3755 } catch (ImsException e) {
3756 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 } finally {
3758 Binder.restoreCallingIdentity(identity);
3759 }
3760 }
3761
shilu366312e2019-12-17 09:28:10 -08003762 /**
3763 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3764 * @param subId The subscription to use to check the configuration.
3765 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003766 @Override
3767 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003768 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3769 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003770 final long identity = Binder.clearCallingIdentity();
3771 try {
3772 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003773 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003774 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003775 } catch (ImsException e) {
3776 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003777 } finally {
3778 Binder.restoreCallingIdentity(identity);
3779 }
3780 }
3781
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003782 @Override
3783 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3784 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3785 final long identity = Binder.clearCallingIdentity();
3786 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003787 if (!isImsAvailableOnDevice()) {
3788 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3789 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003790 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003791 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003792 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003793 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003794 } catch (ImsException e) {
3795 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003796 } finally {
3797 Binder.restoreCallingIdentity(identity);
3798 }
3799 }
3800
3801 @Override
3802 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3803 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3804 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003805 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3806 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3807 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003808 try {
3809 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003810 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003811 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003812 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003813 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3814 + "is inactive, ignoring unregister.");
3815 // If the subscription is no longer active, just return, since the callback will already
3816 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003817 } finally {
3818 Binder.restoreCallingIdentity(identity);
3819 }
3820 }
3821
allenwtsu99c623b2020-01-03 18:24:23 +08003822
3823 private void checkModifyPhoneStatePermission(int subId, String message) {
3824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3825 message);
3826 }
3827
3828 private boolean isImsProvisioningRequired(int subId, int capability,
3829 boolean isMmtelCapability) {
3830 Phone phone = getPhone(subId);
3831 if (phone == null) {
3832 loge("phone instance null for subid " + subId);
3833 return false;
3834 }
3835 if (isMmtelCapability) {
3836 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3837 return false;
3838 }
3839 } else {
3840 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3841 return false;
3842 }
3843 }
3844 return true;
3845 }
3846
3847 @Override
3848 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3849 boolean isProvisioned) {
3850 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3851
3852 final long identity = Binder.clearCallingIdentity();
3853 try {
3854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3855 if (!isImsProvisioningRequired(subId, capability, false)) {
3856 return;
3857 }
3858
3859 // this capability requires provisioning, route to the correct API.
3860 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3861 switch (capability) {
3862 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3863 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3864 ims.setEabProvisioned(isProvisioned);
3865 break;
3866 default: {
3867 throw new IllegalArgumentException("Tried to set provisioning for "
3868 + "rcs capability '" + capability + "', which does not require "
3869 + "provisioning.");
3870 }
3871 }
3872 } finally {
3873 Binder.restoreCallingIdentity(identity);
3874 }
3875
3876 }
3877
3878
3879 @Override
3880 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3881 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3882 final long identity = Binder.clearCallingIdentity();
3883 try {
3884 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3885 if (!isImsProvisioningRequired(subId, capability, false)) {
3886 return true;
3887 }
3888
3889 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3890 switch (capability) {
3891 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3892 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3893 return ims.isEabProvisionedOnDevice();
3894
3895 default: {
3896 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3897 + "capability '" + capability + "', which does not require "
3898 + "provisioning.");
3899 }
3900 }
3901
3902 } finally {
3903 Binder.restoreCallingIdentity(identity);
3904 }
3905 }
3906
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003907 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003908 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3909 boolean isProvisioned) {
3910 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3911 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3912 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3913 }
allenwtsu99c623b2020-01-03 18:24:23 +08003914 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003915 final long identity = Binder.clearCallingIdentity();
3916 try {
3917 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003918 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003919 return;
3920 }
3921
3922 // this capability requires provisioning, route to the correct API.
3923 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3924 switch (capability) {
3925 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3926 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3927 ims.setVolteProvisioned(isProvisioned);
3928 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3929 ims.setWfcProvisioned(isProvisioned);
3930 }
3931 break;
3932 }
3933 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3934 // There is currently no difference in VT provisioning type.
3935 ims.setVtProvisioned(isProvisioned);
3936 break;
3937 }
3938 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3939 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3940 // change the capability of the feature instead if needed.
3941 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3942 == isProvisioned) {
3943 // No change in provisioning.
3944 return;
3945 }
3946 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3947 try {
3948 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003949 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003950 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3951 + ", Exception" + e.getMessage());
3952 }
3953 break;
3954 }
3955 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003956 throw new IllegalArgumentException("Tried to set provisioning for "
3957 + "MmTel capability '" + capability + "', which does not require "
3958 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003959 }
3960 }
3961
3962 } finally {
3963 Binder.restoreCallingIdentity(identity);
3964 }
3965 }
3966
3967 @Override
3968 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3969 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3970 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3971 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3972 }
3973 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3974 final long identity = Binder.clearCallingIdentity();
3975 try {
3976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003977 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003978 return true;
3979 }
3980
3981 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3982 switch (capability) {
3983 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3984 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3985 return ims.isVolteProvisionedOnDevice();
3986 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3987 return ims.isWfcProvisionedOnDevice();
3988 }
3989 // This should never happen, since we are checking tech above to make sure it
3990 // is either LTE or IWLAN.
3991 throw new IllegalArgumentException("Invalid radio technology for voice "
3992 + "capability.");
3993 }
3994 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3995 // There is currently no difference in VT provisioning type.
3996 return ims.isVtProvisionedOnDevice();
3997 }
3998 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3999 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4000 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4001 }
4002 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004003 throw new IllegalArgumentException(
4004 "Tried to get provisioning for MmTel capability '" + capability
4005 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004006 }
4007 }
4008
4009 } finally {
4010 Binder.restoreCallingIdentity(identity);
4011 }
4012 }
4013
4014 @Override
4015 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4016 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4017 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4018 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4019 }
4020 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4021 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4022 return (provisionedBits & capability) > 0;
4023 }
4024
4025 @Override
4026 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4027 boolean isProvisioned) {
4028 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4029 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4030 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4031 }
4032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4033 "setProvisioningStatusForCapability");
4034 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4035 // If the current provisioning status for capability already matches isProvisioned,
4036 // do nothing.
4037 if (((provisionedBits & capability) > 0) == isProvisioned) {
4038 return;
4039 }
4040 if (isProvisioned) {
4041 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4042 } else {
4043 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4044 }
4045 }
4046
4047 /**
4048 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4049 * technology. The bitfield should mirror the bitfield defined by
4050 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4051 */
4052 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4053 String key = getMmTelProvisioningKey(subId, tech);
4054 // Default is no capabilities are provisioned.
4055 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4056 }
4057
4058 /**
4059 * Sets the MmTel capability provisioning bitfield (defined by
4060 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4061 * technology specified.
4062 *
4063 * Note: This is a synchronous command and should not be called on UI thread.
4064 */
4065 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4066 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4067 String key = getMmTelProvisioningKey(subId, tech);
4068 editor.putInt(key, newField);
4069 editor.commit();
4070 }
4071
4072 private static String getMmTelProvisioningKey(int subId, int tech) {
4073 // resulting key is provision_ims_mmtel_{subId}_{tech}
4074 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4075 }
4076
4077 /**
4078 * Query CarrierConfig to see if the specified capability requires provisioning for the
4079 * carrier associated with the subscription id.
4080 */
4081 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4082 int capability) {
4083 CarrierConfigManager configManager = new CarrierConfigManager(context);
4084 PersistableBundle c = configManager.getConfigForSubId(subId);
4085 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004086 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004087 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4088 false);
4089 boolean requireVoiceVtProvisioning = c.getBoolean(
4090 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4091
4092 // First check to make sure that the capability requires provisioning.
4093 switch (capability) {
4094 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4095 // intentional fallthrough
4096 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4097 if (requireVoiceVtProvisioning) {
4098 // Voice and Video requires provisioning
4099 return true;
4100 }
4101 break;
4102 }
4103 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4104 if (requireUtProvisioning) {
4105 // UT requires provisioning
4106 return true;
4107 }
4108 break;
4109 }
4110 }
4111 return false;
4112 }
4113
allenwtsu99c623b2020-01-03 18:24:23 +08004114 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4115 int capability) {
4116 CarrierConfigManager configManager = new CarrierConfigManager(context);
4117 PersistableBundle c = configManager.getConfigForSubId(subId);
4118
4119 boolean requireRcsProvisioning = c.getBoolean(
4120 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4121
4122 // First check to make sure that the capability requires provisioning.
4123 switch (capability) {
4124 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4125 // intentional fallthrough
4126 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4127 if (requireRcsProvisioning) {
4128 // OPTION or PRESENCE requires provisioning
4129 return true;
4130 }
4131 break;
4132 }
4133 }
4134 return false;
4135 }
4136
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004137 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004138 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004139 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4140 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4141 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004142 enforceReadPrivilegedPermission("getImsProvisioningInt");
4143 final long identity = Binder.clearCallingIdentity();
4144 try {
4145 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004146 int slotId = getSlotIndex(subId);
4147 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4148 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4149 + subId + "' for key:" + key);
4150 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4151 }
4152 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004153 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004154 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4155 + subId + "' for key:" + key);
4156 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004157 } finally {
4158 Binder.restoreCallingIdentity(identity);
4159 }
4160 }
4161
4162 @Override
4163 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004164 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4165 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4166 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004167 enforceReadPrivilegedPermission("getImsProvisioningString");
4168 final long identity = Binder.clearCallingIdentity();
4169 try {
4170 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004171 int slotId = getSlotIndex(subId);
4172 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4173 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4174 + subId + "' for key:" + key);
4175 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4176 }
4177 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004178 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004179 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4180 + subId + "' for key:" + key);
4181 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004182 } finally {
4183 Binder.restoreCallingIdentity(identity);
4184 }
4185 }
4186
4187 @Override
4188 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004189 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4190 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4191 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004192 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4193 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004194 final long identity = Binder.clearCallingIdentity();
4195 try {
4196 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004197 int slotId = getSlotIndex(subId);
4198 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4199 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4200 + subId + "' for key:" + key);
4201 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4202 }
4203 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004204 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004205 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4206 + "' for key:" + key);
4207 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004208 } finally {
4209 Binder.restoreCallingIdentity(identity);
4210 }
4211 }
4212
4213 @Override
4214 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004215 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4216 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4217 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4219 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004220 final long identity = Binder.clearCallingIdentity();
4221 try {
4222 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004223 int slotId = getSlotIndex(subId);
4224 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4225 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4226 + subId + "' for key:" + key);
4227 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4228 }
4229 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004230 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004231 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4232 + "' for key:" + key);
4233 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004234 } finally {
4235 Binder.restoreCallingIdentity(identity);
4236 }
4237 }
4238
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004239 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004240 int slotId = SubscriptionManager.getSlotIndex(subId);
4241 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004242 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4243 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 }
4245 return slotId;
4246 }
4247
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004248 private int getSlotIndex(int subId) {
4249 int slotId = SubscriptionManager.getSlotIndex(subId);
4250 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4251 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4252 }
4253 return slotId;
4254 }
4255
Wink Saville36469e72014-06-11 15:17:00 -07004256 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004257 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004258 */
4259 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004260 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4261 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004262 final int targetSdk = getTargetSdk(callingPackage);
4263 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004264 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004265 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004266 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004267 mApp, subId, callingPackage, callingFeatureId,
4268 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004269 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4270 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004271
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004272 final long identity = Binder.clearCallingIdentity();
4273 try {
4274 final Phone phone = getPhone(subId);
4275 if (phone != null) {
4276 return phone.getServiceState().getDataNetworkType();
4277 } else {
4278 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4279 }
4280 } finally {
4281 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004283 }
4284
4285 /**
4286 * Returns the data network type
4287 */
4288 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004289 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4290 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4291 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004292 }
4293
4294 /**
4295 * Returns the data network type for a subId
4296 */
4297 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004298 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4299 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004300 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004301 mApp, subId, callingPackage, callingFeatureId,
4302 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004303 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4304 }
4305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004306 final long identity = Binder.clearCallingIdentity();
4307 try {
4308 final Phone phone = getPhone(subId);
4309 if (phone != null) {
4310 return phone.getServiceState().getDataNetworkType();
4311 } else {
4312 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4313 }
4314 } finally {
4315 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004317 }
4318
4319 /**
Wink Saville36469e72014-06-11 15:17:00 -07004320 * Returns the Voice network type for a subId
4321 */
4322 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004323 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4324 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004326 mApp, subId, callingPackage, callingFeatureId,
4327 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004328 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4329 }
4330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004331 final long identity = Binder.clearCallingIdentity();
4332 try {
4333 final Phone phone = getPhone(subId);
4334 if (phone != null) {
4335 return phone.getServiceState().getVoiceNetworkType();
4336 } else {
4337 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4338 }
4339 } finally {
4340 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004342 }
4343
4344 /**
4345 * @return true if a ICC card is present
4346 */
4347 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004348 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004349 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4350 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004351 }
4352
4353 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004354 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004355 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004356 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004357 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004358 final long identity = Binder.clearCallingIdentity();
4359 try {
4360 final Phone phone = PhoneFactory.getPhone(slotIndex);
4361 if (phone != null) {
4362 return phone.getIccCard().hasIccCard();
4363 } else {
4364 return false;
4365 }
4366 } finally {
4367 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004369 }
4370
4371 /**
4372 * Return if the current radio is LTE on CDMA. This
4373 * is a tri-state return value as for a period of time
4374 * the mode may be unknown.
4375 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004376 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004377 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004378 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004379 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004380 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004381 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4382 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4383 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004384 }
4385
Sanket Padawe356d7632015-06-22 14:03:32 -07004386 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004387 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4388 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004389 try {
4390 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4391 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004392 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4393 }
4394
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004395 final long identity = Binder.clearCallingIdentity();
4396 try {
4397 final Phone phone = getPhone(subId);
4398 if (phone == null) {
4399 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4400 } else {
4401 return phone.getLteOnCdmaMode();
4402 }
4403 } finally {
4404 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004405 }
Wink Saville36469e72014-06-11 15:17:00 -07004406 }
4407
Wink Saville36469e72014-06-11 15:17:00 -07004408 /**
4409 * {@hide}
4410 * Returns Default subId, 0 in the case of single standby.
4411 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004412 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004413 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004414 }
4415
Shishir Agrawala9f32182016-04-12 12:00:16 -07004416 private int getSlotForDefaultSubscription() {
4417 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4418 }
4419
Wink Savilleb564aae2014-10-23 10:18:09 -07004420 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004421 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004422 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004423
Pengquan Menge92a50d2018-09-21 15:54:48 -07004424 private boolean isActiveSubscription(int subId) {
4425 return mSubscriptionController.isActiveSubId(subId);
4426 }
4427
Ihab Awadf2177b72013-11-25 13:33:23 -08004428 /**
4429 * @see android.telephony.TelephonyManager.WifiCallingChoices
4430 */
4431 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004432 final long identity = Binder.clearCallingIdentity();
4433 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004434 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004435 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4436 getWhenToMakeWifiCallsDefaultPreference());
4437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004440 }
4441
4442 /**
4443 * @see android.telephony.TelephonyManager.WifiCallingChoices
4444 */
4445 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 final long identity = Binder.clearCallingIdentity();
4447 try {
4448 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004449 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4451 } finally {
4452 Binder.restoreCallingIdentity(identity);
4453 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004454 }
4455
Sailesh Nepald1e68152013-12-12 19:08:02 -08004456 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004457 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004458 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004459 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004460
Jordan Liu4c733742019-02-28 12:03:40 -08004461 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4462 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4463 if (phoneId == -1) {
4464 throw new IllegalArgumentException("Given slot index: " + slotIndex
4465 + " does not correspond to an active phone");
4466 }
4467 return PhoneFactory.getPhone(phoneId);
4468 }
4469
Shishir Agrawal566b7612013-10-28 14:41:00 -07004470 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004471 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4472 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4474 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004475 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004476 if (DBG) {
4477 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4478 }
4479 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4480 p2);
4481 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004482
Jordan Liu4c733742019-02-28 12:03:40 -08004483
4484 @Override
4485 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4486 int slotIndex, String callingPackage, String aid, int p2) {
4487 enforceModifyPermission();
4488 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4489 if (DBG) {
4490 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4491 }
4492 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4493 callingPackage, aid, p2);
4494 }
4495
4496 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4497 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 final long identity = Binder.clearCallingIdentity();
4499 try {
4500 if (TextUtils.equals(ISDR_AID, aid)) {
4501 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004502 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4503 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004504 if (bestComponent == null
4505 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4506 loge("The calling package is not allowed to access ISD-R.");
4507 throw new SecurityException(
4508 "The calling package is not allowed to access ISD-R.");
4509 }
Derek Tan740e1672017-06-27 14:56:27 -07004510 }
Derek Tan740e1672017-06-27 14:56:27 -07004511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004512 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004513 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4514 null /* workSource */);
4515 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004516 return response;
4517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004520 }
4521
4522 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004523 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4525 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004526 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4527 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4528 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004529
Jordan Liu4c733742019-02-28 12:03:40 -08004530 @Override
4531 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4532 enforceModifyPermission();
4533 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4534 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4535 channel);
4536 }
4537
4538 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004539 final long identity = Binder.clearCallingIdentity();
4540 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004541 if (channel < 0) {
4542 return false;
4543 }
Jordan Liu4c733742019-02-28 12:03:40 -08004544 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4545 null /* workSource */);
4546 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004547 return success;
4548 } finally {
4549 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004550 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004551 }
4552
4553 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004554 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004555 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4557 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004558 if (DBG) {
4559 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4560 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4561 + p3 + " data=" + data);
4562 }
4563 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4564 command, p1, p2, p3, data);
4565 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004566
Jordan Liu4c733742019-02-28 12:03:40 -08004567 @Override
4568 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4569 int command, int p1, int p2, int p3, String data) {
4570 enforceModifyPermission();
4571 if (DBG) {
4572 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4573 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4574 + p3 + " data=" + data);
4575 }
4576 return iccTransmitApduLogicalChannelWithPermission(
4577 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4578 data);
4579 }
4580
4581 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4582 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004583 final long identity = Binder.clearCallingIdentity();
4584 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004585 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004586 return "";
4587 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004590 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4591 null /* workSource */);
4592 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004594 // Append the returned status code to the end of the response payload.
4595 String s = Integer.toHexString(
4596 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4597 if (response.payload != null) {
4598 s = IccUtils.bytesToHexString(response.payload) + s;
4599 }
4600 return s;
4601 } finally {
4602 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004603 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004604 }
Jake Hambye994d462014-02-03 13:10:13 -08004605
Evan Charltonc66da362014-05-16 14:06:40 -07004606 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004607 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4608 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4610 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004611 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004612 if (DBG) {
4613 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4614 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4615 }
4616 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4617 cla, command, p1, p2, p3, data);
4618 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004619
Jordan Liu4c733742019-02-28 12:03:40 -08004620 @Override
4621 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4622 int command, int p1, int p2, int p3, String data) {
4623 enforceModifyPermission();
4624 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4625 if (DBG) {
4626 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4627 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4628 + " data=" + data);
4629 }
4630
4631 return iccTransmitApduBasicChannelWithPermission(
4632 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4633 p2, p3, data);
4634 }
4635
4636 // open APDU basic channel assuming the caller has sufficient permissions
4637 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4638 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004639 final long identity = Binder.clearCallingIdentity();
4640 try {
4641 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4642 && TextUtils.equals(ISDR_AID, data)) {
4643 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004644 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4645 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646 if (bestComponent == null
4647 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4648 loge("The calling package is not allowed to select ISD-R.");
4649 throw new SecurityException(
4650 "The calling package is not allowed to select ISD-R.");
4651 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004652 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004654 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004655 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4656 null /* workSource */);
4657 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004659 // Append the returned status code to the end of the response payload.
4660 String s = Integer.toHexString(
4661 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4662 if (response.payload != null) {
4663 s = IccUtils.bytesToHexString(response.payload) + s;
4664 }
4665 return s;
4666 } finally {
4667 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004668 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004669 }
4670
4671 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004672 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004673 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4675 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004677 final long identity = Binder.clearCallingIdentity();
4678 try {
4679 if (DBG) {
4680 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4681 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4682 }
4683
4684 IccIoResult response =
4685 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4686 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4687 subId);
4688
4689 if (DBG) {
4690 log("Exchange SIM_IO [R]" + response);
4691 }
4692
4693 byte[] result = null;
4694 int length = 2;
4695 if (response.payload != null) {
4696 length = 2 + response.payload.length;
4697 result = new byte[length];
4698 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4699 } else {
4700 result = new byte[length];
4701 }
4702
4703 result[length - 1] = (byte) response.sw2;
4704 result[length - 2] = (byte) response.sw1;
4705 return result;
4706 } finally {
4707 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004708 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004709 }
4710
Nathan Haroldb3014052017-01-25 15:57:32 -08004711 /**
4712 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4713 * on a particular subscription
4714 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004715 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4716 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004717 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004718 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004719 return null;
4720 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004721
4722 final long identity = Binder.clearCallingIdentity();
4723 try {
4724 if (appType != TelephonyManager.APPTYPE_USIM
4725 && appType != TelephonyManager.APPTYPE_SIM) {
4726 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4727 return null;
4728 }
4729 Object response = sendRequest(
4730 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4731 if (response instanceof String[]) {
4732 return (String[]) response;
4733 }
yincheng zhaod698b842019-09-06 17:06:54 -07004734 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004736 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737 } finally {
4738 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004739 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004740 }
4741
yincheng zhaod698b842019-09-06 17:06:54 -07004742 /**
4743 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4744 * subscription.
4745 *
4746 * @param subId the id of the subscription.
4747 * @param appType the uicc app type, must be USIM or SIM.
4748 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4749 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004750 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004751 * @return number of fplmns that is successfully written to the SIM.
4752 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004753 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4754 String callingFeatureId) {
4755 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4756 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004757 if (DBG) logv("no permissions for setForbiddenplmns");
4758 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4759 }
4760 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4761 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4762 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4763 }
4764 if (fplmns == null) {
4765 throw new IllegalArgumentException("Fplmn List provided is null");
4766 }
4767 for (String fplmn : fplmns) {
4768 if (!CellIdentity.isValidPlmn(fplmn)) {
4769 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4770 }
4771 }
4772 final long identity = Binder.clearCallingIdentity();
4773 try {
4774 Object response = sendRequest(
4775 CMD_SET_FORBIDDEN_PLMNS,
4776 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4777 subId);
4778 return (int) response;
4779 } finally {
4780 Binder.restoreCallingIdentity(identity);
4781 }
4782 }
4783
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004784 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004785 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4787 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789 final long identity = Binder.clearCallingIdentity();
4790 try {
4791 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4792 if (response.payload == null) {
4793 return "";
4794 }
Evan Charltonc66da362014-05-16 14:06:40 -07004795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004796 // Append the returned status code to the end of the response payload.
4797 String s = Integer.toHexString(
4798 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4799 s = IccUtils.bytesToHexString(response.payload) + s;
4800 return s;
4801 } finally {
4802 Binder.restoreCallingIdentity(identity);
4803 }
Evan Charltonc66da362014-05-16 14:06:40 -07004804 }
4805
Jake Hambye994d462014-02-03 13:10:13 -08004806 /**
4807 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4808 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4809 *
4810 * @param itemID the ID of the item to read
4811 * @return the NV item as a String, or null on error.
4812 */
4813 @Override
4814 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004815 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4817 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818
4819 final long identity = Binder.clearCallingIdentity();
4820 try {
4821 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004822 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004823 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4824 return value;
4825 } finally {
4826 Binder.restoreCallingIdentity(identity);
4827 }
Jake Hambye994d462014-02-03 13:10:13 -08004828 }
4829
4830 /**
4831 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4832 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4833 *
4834 * @param itemID the ID of the item to read
4835 * @param itemValue the value to write, as a String
4836 * @return true on success; false on any failure
4837 */
4838 @Override
4839 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004840 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4842 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004843
4844 final long identity = Binder.clearCallingIdentity();
4845 try {
4846 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4847 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004848 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004849 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4850 return success;
4851 } finally {
4852 Binder.restoreCallingIdentity(identity);
4853 }
Jake Hambye994d462014-02-03 13:10:13 -08004854 }
4855
4856 /**
4857 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4858 * Used for device configuration by some CDMA operators.
4859 *
4860 * @param preferredRoamingList byte array containing the new PRL
4861 * @return true on success; false on any failure
4862 */
4863 @Override
4864 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4866 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004867
4868 final long identity = Binder.clearCallingIdentity();
4869 try {
4870 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4871 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4872 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4873 return success;
4874 } finally {
4875 Binder.restoreCallingIdentity(identity);
4876 }
Jake Hambye994d462014-02-03 13:10:13 -08004877 }
4878
4879 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004880 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004881 * Used for device configuration by some CDMA operators.
4882 *
chen xu6dac5ab2018-10-26 17:39:23 -07004883 * @param slotIndex - device slot.
4884 *
Jake Hambye994d462014-02-03 13:10:13 -08004885 * @return true on success; false on any failure
4886 */
4887 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004888 public boolean resetModemConfig(int slotIndex) {
4889 Phone phone = PhoneFactory.getPhone(slotIndex);
4890 if (phone != null) {
4891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4892 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004893
chen xu6dac5ab2018-10-26 17:39:23 -07004894 final long identity = Binder.clearCallingIdentity();
4895 try {
4896 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4897 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4898 return success;
4899 } finally {
4900 Binder.restoreCallingIdentity(identity);
4901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 }
chen xu6dac5ab2018-10-26 17:39:23 -07004903 return false;
4904 }
4905
4906 /**
4907 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4908 *
4909 * @param slotIndex - device slot.
4910 *
4911 * @return true on success; false on any failure
4912 */
4913 @Override
4914 public boolean rebootModem(int slotIndex) {
4915 Phone phone = PhoneFactory.getPhone(slotIndex);
4916 if (phone != null) {
4917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4918 mApp, phone.getSubId(), "rebootModem");
4919
4920 final long identity = Binder.clearCallingIdentity();
4921 try {
4922 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4923 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4924 return success;
4925 } finally {
4926 Binder.restoreCallingIdentity(identity);
4927 }
4928 }
4929 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004930 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004931
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004932 public String[] getPcscfAddress(String apnType, String callingPackage,
4933 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004934 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4936 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004937 return new String[0];
4938 }
4939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940 final long identity = Binder.clearCallingIdentity();
4941 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004942 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943 } finally {
4944 Binder.restoreCallingIdentity(identity);
4945 }
Wink Saville36469e72014-06-11 15:17:00 -07004946 }
4947
Brad Ebinger51f743a2017-01-23 13:50:20 -08004948 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004949 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4950 * {@link #disableIms(int)}.
4951 * @param slotIndex device slot.
4952 */
4953 public void resetIms(int slotIndex) {
4954 enforceModifyPermission();
4955
4956 final long identity = Binder.clearCallingIdentity();
4957 try {
4958 if (mImsResolver == null) {
4959 // may happen if the does not support IMS.
4960 return;
4961 }
4962 mImsResolver.disableIms(slotIndex);
4963 mImsResolver.enableIms(slotIndex);
4964 } finally {
4965 Binder.restoreCallingIdentity(identity);
4966 }
4967 }
4968
4969 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004970 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4971 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004972 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004973 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004974 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975
4976 final long identity = Binder.clearCallingIdentity();
4977 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004978 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004979 // may happen if the device does not support IMS.
4980 return;
4981 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004982 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983 } finally {
4984 Binder.restoreCallingIdentity(identity);
4985 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004986 }
4987
4988 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004989 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4990 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004991 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004992 public void disableIms(int slotId) {
4993 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994
4995 final long identity = Binder.clearCallingIdentity();
4996 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004997 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004998 // may happen if the device does not support IMS.
4999 return;
5000 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005001 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002 } finally {
5003 Binder.restoreCallingIdentity(identity);
5004 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005005 }
5006
5007 /**
5008 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
5009 * feature or {@link null} if the service is not available. If the feature is available, the
5010 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
5011 */
5012 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08005013 IImsServiceFeatureCallback callback) {
5014 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005015
5016 final long identity = Binder.clearCallingIdentity();
5017 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005018 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005019 // may happen if the device does not support IMS.
5020 return null;
5021 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005022 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023 } finally {
5024 Binder.restoreCallingIdentity(identity);
5025 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005026 }
5027
5028 /**
5029 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5030 * feature during emergency calling or {@link null} if the service is not available. If the
5031 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5032 * listener for feature updates.
5033 */
5034 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5035 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036
5037 final long identity = Binder.clearCallingIdentity();
5038 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005039 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005040 // may happen if the device does not support IMS.
5041 return null;
5042 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005043 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 } finally {
5045 Binder.restoreCallingIdentity(identity);
5046 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005047 }
5048
Brad Ebinger5f64b052017-12-14 14:26:15 -08005049 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005050 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5051 */
5052 public void unregisterImsFeatureCallback(int slotId, int featureType,
5053 IImsServiceFeatureCallback callback) {
5054 enforceModifyPermission();
5055
5056 final long identity = Binder.clearCallingIdentity();
5057 try {
5058 if (mImsResolver == null) return;
5059 mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback);
5060 } finally {
5061 Binder.restoreCallingIdentity(identity);
5062 }
5063 }
5064
5065 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005066 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005067 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005068 */
5069 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5070 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071
5072 final long identity = Binder.clearCallingIdentity();
5073 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005074 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005075 // may happen if the device does not support IMS.
5076 return null;
5077 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005078 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079 } finally {
5080 Binder.restoreCallingIdentity(identity);
5081 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005082 }
5083
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005084 /**
5085 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005086 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005087 */
5088 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5089 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090
5091 final long identity = Binder.clearCallingIdentity();
5092 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005093 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005094 // may happen if the device does not support IMS.
5095 return null;
5096 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005097 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 } finally {
5099 Binder.restoreCallingIdentity(identity);
5100 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005101 }
5102
Brad Ebinger884c07b2018-02-15 16:17:40 -08005103 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005104 * Sets the ImsService Package Name that Telephony will bind to.
5105 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005106 * @param slotIndex the slot ID that the ImsService should bind for.
5107 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005108 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005109 * @param featureTypes An integer array of feature types associated with a packageName.
5110 * @param packageName The name of the package that the current configuration will be replaced
5111 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005112 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005113 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005114 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5115 int[] featureTypes, String packageName) {
5116 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5117 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5119 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005120 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005121
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005122 final long identity = Binder.clearCallingIdentity();
5123 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005124 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005125 // may happen if the device does not support IMS.
5126 return false;
5127 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005128 Map<Integer, String> featureConfig = new HashMap<>();
5129 for (int featureType : featureTypes) {
5130 featureConfig.put(featureType, packageName);
5131 }
5132 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5133 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 } finally {
5135 Binder.restoreCallingIdentity(identity);
5136 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005137 }
5138
5139 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005140 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005141 *
5142 * @param slotId The slot that the ImsService is associated with.
5143 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5144 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005145 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005146 * @return the package name of the ImsService configuration.
5147 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005148 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5149 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005150 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005151 TelephonyPermissions
5152 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5153 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5154 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156 final long identity = Binder.clearCallingIdentity();
5157 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005158 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005159 // may happen if the device does not support IMS.
5160 return "";
5161 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005162 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005163 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5164 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005165 } finally {
5166 Binder.restoreCallingIdentity(identity);
5167 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005168 }
5169
Brad Ebinger77b832e2019-10-17 17:03:22 -07005170 /**
5171 * Get the MmTelFeature state associated with the requested subscription id.
5172 * @param subId The subscription that the MmTelFeature is associated with.
5173 * @param callback A callback with an integer containing the
5174 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5175 */
5176 @Override
5177 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5178 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5179 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5180 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5181 "IMS not available on device.");
5182 }
5183 final long token = Binder.clearCallingIdentity();
5184 try {
5185 int slotId = getSlotIndex(subId);
5186 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5187 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5188 + subId + "'");
5189 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5190 }
5191 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5192 try {
5193 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5194 } catch (RemoteException e) {
5195 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5196 + "Ignore");
5197 }
5198 });
5199 } finally {
5200 Binder.restoreCallingIdentity(token);
5201 }
5202 }
5203
Wink Saville36469e72014-06-11 15:17:00 -07005204 public void setImsRegistrationState(boolean registered) {
5205 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206
5207 final long identity = Binder.clearCallingIdentity();
5208 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005209 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210 } finally {
5211 Binder.restoreCallingIdentity(identity);
5212 }
Wink Saville36469e72014-06-11 15:17:00 -07005213 }
5214
5215 /**
Stuart Scott54788802015-03-30 13:18:01 -07005216 * Set the network selection mode to automatic.
5217 *
5218 */
5219 @Override
5220 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5222 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223
5224 final long identity = Binder.clearCallingIdentity();
5225 try {
shilufc958392020-01-20 11:36:01 -08005226 if (!isActiveSubscription(subId)) {
5227 return;
5228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5230 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5231 } finally {
5232 Binder.restoreCallingIdentity(identity);
5233 }
Stuart Scott54788802015-03-30 13:18:01 -07005234 }
5235
Pengquan Mengea84e042018-09-20 14:57:26 -07005236 /**
5237 * Ask the radio to connect to the input network and change selection mode to manual.
5238 *
5239 * @param subId the id of the subscription.
5240 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5241 * the operator to attach to.
5242 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5243 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5244 * normal network selection next time.
5245 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005246 */
5247 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005248 public boolean setNetworkSelectionModeManual(
5249 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5251 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005252
5253 if (!isActiveSubscription(subId)) {
5254 return false;
5255 }
5256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 final long identity = Binder.clearCallingIdentity();
5258 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005259 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005261 if (DBG) {
5262 log("setNetworkSelectionModeManual: subId: " + subId
5263 + " operator: " + operatorInfo);
5264 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005265 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5266 } finally {
5267 Binder.restoreCallingIdentity(identity);
5268 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005269 }
5270
5271 /**
5272 * Scans for available networks.
5273 */
5274 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005275 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5276 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5278 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005279 LocationAccessPolicy.LocationPermissionResult locationResult =
5280 LocationAccessPolicy.checkLocationPermission(mApp,
5281 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5282 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005283 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005284 .setCallingPid(Binder.getCallingPid())
5285 .setCallingUid(Binder.getCallingUid())
5286 .setMethod("getCellNetworkScanResults")
5287 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5288 .build());
5289 switch (locationResult) {
5290 case DENIED_HARD:
5291 throw new SecurityException("Not allowed to access scan results -- location");
5292 case DENIED_SOFT:
5293 return null;
5294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005295
Pengquan Menga1bb6272018-09-06 09:59:22 -07005296 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297 try {
5298 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005299 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 } finally {
5302 Binder.restoreCallingIdentity(identity);
5303 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005304 }
5305
5306 /**
sqian80370722020-01-29 15:02:51 -08005307 * Get the call forwarding info, given the call forwarding reason.
5308 */
5309 @Override
5310 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5311 enforceReadPrivilegedPermission("getCallForwarding");
5312 long identity = Binder.clearCallingIdentity();
5313 try {
5314 if (DBG) {
5315 log("getCallForwarding: subId " + subId
5316 + " callForwardingReason" + callForwardingReason);
5317 }
5318 return (CallForwardingInfo) sendRequest(
5319 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5320 } finally {
5321 Binder.restoreCallingIdentity(identity);
5322 }
5323 }
5324
5325 /**
5326 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5327 * reason, the number to forward, and the timeout before the forwarding is attempted.
5328 */
5329 @Override
5330 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5331 enforceModifyPermission();
5332 long identity = Binder.clearCallingIdentity();
5333 try {
5334 if (DBG) {
5335 log("setCallForwarding: subId " + subId
5336 + " callForwardingInfo" + callForwardingInfo);
5337 }
5338 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
5342 }
5343
5344 /**
5345 * Get the call forwarding info, given the call forwarding reason.
5346 */
5347 @Override
5348 public int getCallWaitingStatus(int subId) {
5349 enforceReadPrivilegedPermission("getCallForwarding");
5350 long identity = Binder.clearCallingIdentity();
5351 try {
5352 if (DBG) log("getCallWaitingStatus: subId " + subId);
5353 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5354 } finally {
5355 Binder.restoreCallingIdentity(identity);
5356 }
5357 }
5358
5359 /**
5360 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5361 * reason, the number to forward, and the timeout before the forwarding is attempted.
5362 */
5363 @Override
5364 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5365 enforceModifyPermission();
5366 long identity = Binder.clearCallingIdentity();
5367 try {
5368 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5369 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5370 } finally {
5371 Binder.restoreCallingIdentity(identity);
5372 }
5373 }
5374
5375 /**
yinxub1bed742017-04-17 11:45:04 -07005376 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005377 *
yinxub1bed742017-04-17 11:45:04 -07005378 * @param subId id of the subscription
5379 * @param request contains the radio access networks with bands/channels to scan
5380 * @param messenger callback messenger for scan results or errors
5381 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005382 * @return the id of the requested scan which can be used to stop the scan.
5383 */
5384 @Override
5385 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005386 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5388 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005389 LocationAccessPolicy.LocationPermissionResult locationResult =
5390 LocationAccessPolicy.checkLocationPermission(mApp,
5391 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5392 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005393 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005394 .setCallingPid(Binder.getCallingPid())
5395 .setCallingUid(Binder.getCallingUid())
5396 .setMethod("requestNetworkScan")
5397 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5398 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005399 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005400 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005401 if (e != null) {
5402 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5403 throw e;
5404 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005405 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005406 return TelephonyScanManager.INVALID_SCAN_ID;
5407 }
5408 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005409 }
Hall Liu912dfd32019-04-25 14:02:26 -07005410 int callingUid = Binder.getCallingUid();
5411 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005412 final long identity = Binder.clearCallingIdentity();
5413 try {
5414 return mNetworkScanRequestTracker.startNetworkScan(
5415 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005416 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005417 } finally {
5418 Binder.restoreCallingIdentity(identity);
5419 }
yinxu504e1392017-04-12 16:03:22 -07005420 }
5421
Hall Liub2ac8ef2019-02-28 15:56:23 -08005422 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005423 NetworkScanRequest request, int subId) {
5424 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5425 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5426 boolean hasNetworkScanPermission =
5427 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5428 == PERMISSION_GRANTED;
5429
5430 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5431 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5432 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005433 }
5434
5435 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5436 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005437 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5438 return new SecurityException("Specific channels must not be"
5439 + " scanned without location access.");
5440 }
5441 }
5442 }
5443
Hall Liub2ac8ef2019-02-28 15:56:23 -08005444 return null;
5445 }
5446
yinxu504e1392017-04-12 16:03:22 -07005447 /**
5448 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005449 *
5450 * @param subId id of the subscription
5451 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005452 */
5453 @Override
5454 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5456 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457
Hall Liu912dfd32019-04-25 14:02:26 -07005458 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 final long identity = Binder.clearCallingIdentity();
5460 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005461 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462 } finally {
5463 Binder.restoreCallingIdentity(identity);
5464 }
yinxu504e1392017-04-12 16:03:22 -07005465 }
5466
5467 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005468 * Get the calculated preferred network type.
5469 * Used for debugging incorrect network type.
5470 *
5471 * @return the preferred network type, defined in RILConstants.java.
5472 */
5473 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005474 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005475 final Phone defaultPhone = getDefaultPhone();
5476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005477 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005478 return RILConstants.PREFERRED_NETWORK_MODE;
5479 }
5480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481 final long identity = Binder.clearCallingIdentity();
5482 try {
5483 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005484 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485 } finally {
5486 Binder.restoreCallingIdentity(identity);
5487 }
Junda Liu84d15a22014-07-02 11:21:04 -07005488 }
5489
5490 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005491 * Get the preferred network type.
5492 * Used for device configuration by some CDMA operators.
5493 *
5494 * @return the preferred network type, defined in RILConstants.java.
5495 */
5496 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005497 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005498 TelephonyPermissions
5499 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5500 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005501
5502 final long identity = Binder.clearCallingIdentity();
5503 try {
5504 if (DBG) log("getPreferredNetworkType");
5505 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5506 int networkType = (result != null ? result[0] : -1);
5507 if (DBG) log("getPreferredNetworkType: " + networkType);
5508 return networkType;
5509 } finally {
5510 Binder.restoreCallingIdentity(identity);
5511 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005512 }
5513
5514 /**
5515 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005516 *
5517 * @param networkType the preferred network type, defined in RILConstants.java.
5518 * @return true on success; false on any failure.
5519 */
5520 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005521 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5523 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524
5525 final long identity = Binder.clearCallingIdentity();
5526 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005527 Settings.Global.putInt(mApp.getContentResolver(),
5528 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005529
5530 Boolean success = (Boolean) sendRequest(
5531 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5532 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5533 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534 } finally {
5535 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005536 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005537 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005538
5539 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005540 * Get the allowed network types that store in the telephony provider.
5541 *
5542 * @param subId the id of the subscription.
5543 * @return allowedNetworkTypes the allowed network types.
5544 */
5545 @Override
5546 public long getAllowedNetworkTypes(int subId) {
5547 TelephonyPermissions
5548 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5549 mApp, subId, "getAllowedNetworkTypes");
5550
5551 final long identity = Binder.clearCallingIdentity();
5552 try {
5553 return SubscriptionManager.getLongSubscriptionProperty(
5554 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5555 } finally {
5556 Binder.restoreCallingIdentity(identity);
5557 }
5558 }
5559
5560 /**
5561 * Set the allowed network types.
5562 *
5563 * @param subId the id of the subscription.
5564 * @param allowedNetworkTypes the allowed network types.
5565 * @return true on success; false on any failure.
5566 */
5567 @Override
5568 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5570 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005571
calvinpan089c2a62020-03-12 14:17:55 +08005572 SubscriptionManager.setSubscriptionProperty(subId,
5573 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5574 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005575
calvinpan089c2a62020-03-12 14:17:55 +08005576 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5577 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5578 RILConstants.PREFERRED_NETWORK_MODE);
5579 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005580 }
5581
5582 /**
Miaoa84611c2019-03-15 09:21:10 +08005583 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005584 *
Miaoa84611c2019-03-15 09:21:10 +08005585 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005586 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005587 * @hide
5588 */
5589 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005590 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005591 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005593 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594 try {
Miaoa84611c2019-03-15 09:21:10 +08005595 if (phone != null) {
5596 return phone.hasMatchedTetherApnSetting();
5597 } else {
5598 return false;
5599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005600 } finally {
5601 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005602 }
Junda Liu475951f2014-11-07 16:45:03 -08005603 }
5604
5605 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005606 * Set mobile data enabled
5607 * Used by the user through settings etc to turn on/off mobile data
5608 *
5609 * @param enable {@code true} turn turn data on, else {@code false}
5610 */
5611 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005612 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5614 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615
5616 final long identity = Binder.clearCallingIdentity();
5617 try {
5618 int phoneId = mSubscriptionController.getPhoneId(subId);
5619 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5620 Phone phone = PhoneFactory.getPhone(phoneId);
5621 if (phone != null) {
5622 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005623 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005625 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005626 }
5627 } finally {
5628 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005629 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005630 }
5631
5632 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005633 * Enable or disable always reporting signal strength changes from radio.
5634 *
5635 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5636 */
5637 @Override
5638 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5639 enforceModifyPermission();
5640 enforceSystemCaller();
5641
5642 final long identity = Binder.clearCallingIdentity();
5643 final Phone phone = getPhone(subId);
5644 try {
5645 if (phone != null) {
5646 if (DBG) {
5647 log("setAlwaysReportSignalStrength: subId=" + subId
5648 + " isEnable=" + isEnable);
5649 }
5650 phone.setAlwaysReportSignalStrength(isEnable);
5651 } else {
5652 loge("setAlwaysReportSignalStrength: no phone found for subId="
5653 + subId);
5654 }
5655 } finally {
5656 Binder.restoreCallingIdentity(identity);
5657 }
5658 }
5659
5660 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005661 * Get the user enabled state of Mobile Data.
5662 *
5663 * TODO: remove and use isUserDataEnabled.
5664 * This can't be removed now because some vendor codes
5665 * calls through ITelephony directly while they should
5666 * use TelephonyManager.
5667 *
5668 * @return true on enabled
5669 */
5670 @Override
5671 public boolean getDataEnabled(int subId) {
5672 return isUserDataEnabled(subId);
5673 }
5674
5675 /**
5676 * Get whether mobile data is enabled per user setting.
5677 *
5678 * There are other factors deciding whether mobile data is actually enabled, but they are
5679 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005680 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005681 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005682 *
5683 * @return {@code true} if data is enabled else {@code false}
5684 */
5685 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005686 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005687 try {
5688 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5689 null);
5690 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5692 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694
5695 final long identity = Binder.clearCallingIdentity();
5696 try {
5697 int phoneId = mSubscriptionController.getPhoneId(subId);
5698 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5699 Phone phone = PhoneFactory.getPhone(phoneId);
5700 if (phone != null) {
5701 boolean retVal = phone.isUserDataEnabled();
5702 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5703 return retVal;
5704 } else {
5705 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5706 return false;
5707 }
5708 } finally {
5709 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005710 }
5711 }
5712
5713 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005714 * Checks if the device is capable of mobile data by considering whether whether the
5715 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5716 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005717 *
Shuo Qian985d1232020-01-08 14:30:06 -08005718 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005719 */
5720 @Override
5721 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005722 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723
5724 final long identity = Binder.clearCallingIdentity();
5725 try {
5726 int phoneId = mSubscriptionController.getPhoneId(subId);
5727 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5728 Phone phone = PhoneFactory.getPhone(phoneId);
5729 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005730 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5732 return retVal;
5733 } else {
5734 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5735 return false;
5736 }
5737 } finally {
5738 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005739 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005740 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005741
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005742 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005743 Phone phone) {
5744 //load access rules from carrier configs, and check those as well: b/139133814
5745 SubscriptionController subController = SubscriptionController.getInstance();
5746 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5747 || subController == null) return privilegeFromSim;
5748
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005749 PackageManager pkgMgr = phone.getContext().getPackageManager();
5750 String[] packages = pkgMgr.getPackagesForUid(uid);
5751
5752 final long identity = Binder.clearCallingIdentity();
5753 try {
5754 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5755 SubscriptionManager subManager = (SubscriptionManager)
5756 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5757 for (String pkg : packages) {
5758 if (subManager.canManageSubscription(subInfo, pkg)) {
5759 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5760 }
5761 }
5762 return privilegeFromSim;
5763 } finally {
5764 Binder.restoreCallingIdentity(identity);
5765 }
5766 }
5767
5768 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5769 String pkgName) {
5770 //load access rules from carrier configs, and check those as well: b/139133814
5771 SubscriptionController subController = SubscriptionController.getInstance();
5772 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5773 || subController == null) return privilegeFromSim;
5774
5775 final long identity = Binder.clearCallingIdentity();
5776 try {
5777 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5778 SubscriptionManager subManager = (SubscriptionManager)
5779 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5780 return subManager.canManageSubscription(subInfo, pkgName)
5781 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
5785 }
5786
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005787 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005788 public int getCarrierPrivilegeStatus(int subId) {
5789 final Phone phone = getPhone(subId);
5790 if (phone == null) {
5791 loge("getCarrierPrivilegeStatus: Invalid subId");
5792 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5793 }
5794 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005795 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005796 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005797 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5798 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005799
5800 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5801 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005802 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005803 }
Junda Liu29340342014-07-10 15:23:27 -07005804
5805 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005806 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005807 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005808 final Phone phone = getPhone(subId);
5809 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005810 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005811 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5812 }
5813 UiccProfile profile =
5814 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5815 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005816 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005817 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5818 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005819 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005820 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005821 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005822 }
5823
5824 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005825 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5826 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005827 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005828 }
5829
5830 int phoneId = SubscriptionManager.getPhoneId(subId);
5831 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005832 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005833 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005834 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5835 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005836 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5837 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5838 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005839 }
5840
5841 @Override
5842 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005843 if (TextUtils.isEmpty(pkgName))
5844 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005845 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5846 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5847 UiccCard card = UiccController.getInstance().getUiccCard(i);
5848 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005849 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005850 continue;
5851 }
5852
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005853 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5854 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5855 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005856 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5857 break;
5858 }
5859 }
5860
5861 return result;
Junda Liu29340342014-07-10 15:23:27 -07005862 }
Derek Tan89e89d42014-07-08 17:00:10 -07005863
5864 @Override
Junda Liue64de782015-04-16 17:19:16 -07005865 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5866 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5867 loge("phoneId " + phoneId + " is not valid.");
5868 return null;
5869 }
5870 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005871 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005872 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005873 return null ;
5874 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005875 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005876 }
5877
Amith Yamasani6e118872016-02-19 12:53:51 -08005878 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005879 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005880 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005881 List<String> privilegedPackages = new ArrayList<>();
5882 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005883 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5884 // has UICC in that slot.
5885 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005886 if (card.hasCarrierPrivilegeRules()) {
5887 if (packages == null) {
5888 // Only check packages in user 0 for now
5889 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005890 PackageManager.MATCH_DISABLED_COMPONENTS
5891 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005892 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005893 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005894 }
5895 for (int p = packages.size() - 1; p >= 0; p--) {
5896 PackageInfo pkgInfo = packages.get(p);
5897 if (pkgInfo != null && pkgInfo.packageName != null
5898 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005899 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005900 privilegedPackages.add(pkgInfo.packageName);
5901 }
5902 }
5903 }
5904 }
5905 return privilegedPackages;
5906 }
5907
chen xuf7e9fe82019-05-09 19:31:02 -07005908 @Override
5909 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005910 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5911
5912 final long identity = Binder.clearCallingIdentity();
5913
chen xuf7e9fe82019-05-09 19:31:02 -07005914 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005915 try {
5916 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5917 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5918 }
5919 } finally {
5920 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005921 }
5922 return privilegedPackages;
5923 }
5924
Wink Savilleb564aae2014-10-23 10:18:09 -07005925 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005926 final Phone phone = getPhone(subId);
5927 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005928 if (card == null) {
5929 loge("getIccId: No UICC");
5930 return null;
5931 }
5932 String iccId = card.getIccId();
5933 if (TextUtils.isEmpty(iccId)) {
5934 loge("getIccId: ICC ID is null or empty.");
5935 return null;
5936 }
5937 return iccId;
5938 }
5939
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005940 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005941 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5942 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005943 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005944 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946 final long identity = Binder.clearCallingIdentity();
5947 try {
5948 final String iccId = getIccId(subId);
5949 final Phone phone = getPhone(subId);
5950 if (phone == null) {
5951 return false;
5952 }
5953 final String subscriberId = phone.getSubscriberId();
5954
5955 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005956 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957 + subscriberId + " to " + number);
5958 }
5959
5960 if (TextUtils.isEmpty(iccId)) {
5961 return false;
5962 }
5963
5964 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5965
5966 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5967 if (alphaTag == null) {
5968 editor.remove(alphaTagPrefKey);
5969 } else {
5970 editor.putString(alphaTagPrefKey, alphaTag);
5971 }
5972
5973 // Record both the line number and IMSI for this ICCID, since we need to
5974 // track all merged IMSIs based on line number
5975 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5976 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5977 if (number == null) {
5978 editor.remove(numberPrefKey);
5979 editor.remove(subscriberPrefKey);
5980 } else {
5981 editor.putString(numberPrefKey, number);
5982 editor.putString(subscriberPrefKey, subscriberId);
5983 }
5984
5985 editor.commit();
5986 return true;
5987 } finally {
5988 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005989 }
Derek Tan7226c842014-07-02 17:42:23 -07005990 }
5991
5992 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005993 public String getLine1NumberForDisplay(int subId, String callingPackage,
5994 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005995 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005996 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005997 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005998 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005999 return null;
6000 }
Derek Tan97ebb422014-09-05 16:55:38 -07006001
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006002 final long identity = Binder.clearCallingIdentity();
6003 try {
6004 String iccId = getIccId(subId);
6005 if (iccId != null) {
6006 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6007 if (DBG_MERGE) {
6008 log("getLine1NumberForDisplay returning "
6009 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6010 }
6011 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006012 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6014 return null;
6015 } finally {
6016 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006017 }
Derek Tan7226c842014-07-02 17:42:23 -07006018 }
6019
6020 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006021 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6022 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006023 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006024 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006025 return null;
6026 }
Derek Tan97ebb422014-09-05 16:55:38 -07006027
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028 final long identity = Binder.clearCallingIdentity();
6029 try {
6030 String iccId = getIccId(subId);
6031 if (iccId != null) {
6032 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6033 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6034 }
6035 return null;
6036 } finally {
6037 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006038 }
Derek Tan7226c842014-07-02 17:42:23 -07006039 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006040
6041 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006042 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6043 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006044 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6045 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006046 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006047 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006048 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006049 return null;
6050 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006051
Jordan Liub49b04b2019-05-06 14:45:15 -07006052 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6053 // the process, where TelephonyManager was instantiated.
6054 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006055 final long identity = Binder.clearCallingIdentity();
6056 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006057 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006058 final TelephonyManager tele = TelephonyManager.from(context);
6059 final SubscriptionManager sub = SubscriptionManager.from(context);
6060
6061 // Figure out what subscribers are currently active
6062 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063
Jordan Liub49b04b2019-05-06 14:45:15 -07006064 // Only consider subs which match the current subId
6065 // This logic can be simplified. See b/131189269 for progress.
6066 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006067 activeSubscriberIds.add(tele.getSubscriberId(subId));
6068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069
6070 // First pass, find a number override for an active subscriber
6071 String mergeNumber = null;
6072 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6073 for (String key : prefs.keySet()) {
6074 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6075 final String subscriberId = (String) prefs.get(key);
6076 if (activeSubscriberIds.contains(subscriberId)) {
6077 final String iccId = key.substring(
6078 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6079 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6080 mergeNumber = (String) prefs.get(numberKey);
6081 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006082 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083 + " for active subscriber " + subscriberId);
6084 }
6085 if (!TextUtils.isEmpty(mergeNumber)) {
6086 break;
6087 }
6088 }
6089 }
6090 }
6091
6092 // Shortcut when no active merged subscribers
6093 if (TextUtils.isEmpty(mergeNumber)) {
6094 return null;
6095 }
6096
6097 // Second pass, find all subscribers under that line override
6098 final ArraySet<String> result = new ArraySet<>();
6099 for (String key : prefs.keySet()) {
6100 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6101 final String number = (String) prefs.get(key);
6102 if (mergeNumber.equals(number)) {
6103 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6104 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6105 final String subscriberId = (String) prefs.get(subscriberKey);
6106 if (!TextUtils.isEmpty(subscriberId)) {
6107 result.add(subscriberId);
6108 }
6109 }
6110 }
6111 }
6112
6113 final String[] resultArray = result.toArray(new String[result.size()]);
6114 Arrays.sort(resultArray);
6115 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006116 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6118 }
6119 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006120 } finally {
6121 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006122 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006123 }
6124
6125 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006126 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6127 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6128
6129 final long identity = Binder.clearCallingIdentity();
6130 try {
6131 final TelephonyManager telephonyManager = mApp.getSystemService(
6132 TelephonyManager.class);
6133 String subscriberId = telephonyManager.getSubscriberId(subId);
6134 if (subscriberId == null) {
6135 if (DBG) {
6136 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6137 + subId);
6138 }
6139 return null;
6140 }
6141
6142 final SubscriptionInfo info = SubscriptionController.getInstance()
6143 .getSubscriptionInfo(subId);
6144 final ParcelUuid groupUuid = info.getGroupUuid();
6145 // If it doesn't belong to any group, return just subscriberId of itself.
6146 if (groupUuid == null) {
6147 return new String[]{subscriberId};
6148 }
6149
6150 // Get all subscriberIds from the group.
6151 final List<String> mergedSubscriberIds = new ArrayList<>();
6152 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006153 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6154 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006155 for (SubscriptionInfo subInfo : groupInfos) {
6156 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6157 if (subscriberId != null) {
6158 mergedSubscriberIds.add(subscriberId);
6159 }
6160 }
6161
6162 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6163 } finally {
6164 Binder.restoreCallingIdentity(identity);
6165
6166 }
6167 }
6168
6169 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006170 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006171 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006172 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006173
6174 final long identity = Binder.clearCallingIdentity();
6175 try {
6176 final Phone phone = getPhone(subId);
6177 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6178 } finally {
6179 Binder.restoreCallingIdentity(identity);
6180 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006181 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006182
6183 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006184 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006185 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6186 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006187 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6188 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006189
6190 final long identity = Binder.clearCallingIdentity();
6191 try {
6192 final Phone phone = getPhone(subId);
6193 if (phone == null) {
6194 return false;
6195 }
6196 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6197 cdmaNonRoamingList);
6198 } finally {
6199 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006200 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006201 }
6202
6203 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006204 @Deprecated
6205 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6206 enforceModifyPermission();
6207
6208 int returnValue = 0;
6209 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006210 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006211 if(result.exception == null) {
6212 if (result.result != null) {
6213 byte[] responseData = (byte[])(result.result);
6214 if(responseData.length > oemResp.length) {
6215 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6216 responseData.length + "bytes. Buffer Size is " +
6217 oemResp.length + "bytes.");
6218 }
6219 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6220 returnValue = responseData.length;
6221 }
6222 } else {
6223 CommandException ex = (CommandException) result.exception;
6224 returnValue = ex.getCommandError().ordinal();
6225 if(returnValue > 0) returnValue *= -1;
6226 }
6227 } catch (RuntimeException e) {
6228 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6229 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6230 if(returnValue > 0) returnValue *= -1;
6231 }
6232
6233 return returnValue;
6234 }
6235
6236 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006237 public void setRadioCapability(RadioAccessFamily[] rafs) {
6238 try {
6239 ProxyController.getInstance().setRadioCapability(rafs);
6240 } catch (RuntimeException e) {
6241 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6242 }
6243 }
6244
6245 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006246 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006247 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006248 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006249 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006250 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006251 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006252 final long identity = Binder.clearCallingIdentity();
6253 try {
chen xub97461a2018-10-26 14:17:57 -07006254 TelephonyPermissions
6255 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6256 mApp, phone.getSubId(), "getRadioAccessFamily");
6257 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258 } finally {
6259 Binder.restoreCallingIdentity(identity);
6260 }
chen xub97461a2018-10-26 14:17:57 -07006261 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006262 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006263
6264 @Override
6265 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006266 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006267 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006268
6269 final long identity = Binder.clearCallingIdentity();
6270 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006271 ImsManager.getInstance(defaultPhone.getContext(),
6272 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006273 } finally {
6274 Binder.restoreCallingIdentity(identity);
6275 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006276 }
6277
6278 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006279 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006280 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006281 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6282 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006283 return false;
6284 }
Svet Ganovb320e182015-04-16 12:30:10 -07006285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286 final long identity = Binder.clearCallingIdentity();
6287 try {
6288 // Check the user preference and the system-level IMS setting. Even if the user has
6289 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6290 // In the long run, we may instead need to check if there exists a connection service
6291 // which can support video calling.
6292 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006293 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294 return imsManager.isVtEnabledByPlatform()
6295 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6296 && imsManager.isVtEnabledByUser();
6297 } finally {
6298 Binder.restoreCallingIdentity(identity);
6299 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006300 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006301
Andrew Leea1239f22015-03-02 17:44:07 -08006302 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006303 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6304 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006306 mApp, subId, callingPackage, callingFeatureId,
6307 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308 return false;
6309 }
6310
6311 final long identity = Binder.clearCallingIdentity();
6312 try {
6313 CarrierConfigManager configManager =
6314 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006315 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6317 } finally {
6318 Binder.restoreCallingIdentity(identity);
6319 }
Andrew Leea1239f22015-03-02 17:44:07 -08006320 }
6321
6322 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006323 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006325 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006326 return false;
6327 }
6328
6329 final long identity = Binder.clearCallingIdentity();
6330 try {
6331 CarrierConfigManager configManager =
6332 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006333 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6335 } finally {
6336 Binder.restoreCallingIdentity(identity);
6337 }
Andrew Leea1239f22015-03-02 17:44:07 -08006338 }
6339
Andrew Lee9431b832015-03-09 18:46:45 -07006340 @Override
6341 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006342 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006343 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006344 }
6345
6346 @Override
6347 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006348 final long identity = Binder.clearCallingIdentity();
6349 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006350 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006351 } finally {
6352 Binder.restoreCallingIdentity(identity);
6353 }
Andrew Lee9431b832015-03-09 18:46:45 -07006354 }
6355
Hall Liuf6668912018-10-31 17:05:23 -07006356 /**
6357 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6358 * support for the feature and device firmware support.
6359 *
6360 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6361 */
6362 @Override
6363 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006365 final Phone phone = getPhone(subscriptionId);
6366 if (phone == null) {
6367 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6368 return false;
6369 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006370 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006371 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006372 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6373 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006374 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375 return isCarrierSupported && isDeviceSupported;
6376 } finally {
6377 Binder.restoreCallingIdentity(identity);
6378 }
Hall Liu98187582018-01-22 19:15:32 -08006379 }
6380
Hall Liuf6668912018-10-31 17:05:23 -07006381 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006382 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6383 * RTT setting, will return true if the device and carrier both support RTT.
6384 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006385 */
6386 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387 final long identity = Binder.clearCallingIdentity();
6388 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006389 boolean isRttSupported = isRttSupported(subscriptionId);
6390 boolean isUserRttSettingOn = Settings.Secure.getInt(
6391 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6392 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6393 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6394 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006395 } finally {
6396 Binder.restoreCallingIdentity(identity);
6397 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006398 }
6399
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006400 @Deprecated
6401 @Override
6402 public String getDeviceId(String callingPackage) {
6403 return getDeviceIdWithFeature(callingPackage, null);
6404 }
6405
Sanket Padawe7310cc72015-01-14 09:53:20 -08006406 /**
6407 * Returns the unique device ID of phone, for example, the IMEI for
6408 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6409 *
6410 * <p>Requires Permission:
6411 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6412 */
6413 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006414 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006415 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006416 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006417 return null;
6418 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006419 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006420 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006421 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006422 return null;
6423 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424
6425 final long identity = Binder.clearCallingIdentity();
6426 try {
6427 return phone.getDeviceId();
6428 } finally {
6429 Binder.restoreCallingIdentity(identity);
6430 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006431 }
6432
Ping Sunc67b7c22016-03-02 19:16:45 +08006433 /**
6434 * {@hide}
6435 * Returns the IMS Registration Status on a particular subid
6436 *
6437 * @param subId
6438 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006439 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006440 Phone phone = getPhone(subId);
6441 if (phone != null) {
6442 return phone.isImsRegistered();
6443 } else {
6444 return false;
6445 }
6446 }
6447
Santos Cordon7a1885b2015-02-03 11:15:19 -08006448 @Override
6449 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006450 final long identity = Binder.clearCallingIdentity();
6451 try {
6452 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6453 } finally {
6454 Binder.restoreCallingIdentity(identity);
6455 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006456 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006457
Tyler Gunnf70ed162019-04-03 15:28:53 -07006458 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006459 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006460 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006462 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006463 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6464 }
6465 final long identity = Binder.clearCallingIdentity();
6466 try {
6467 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6468 } finally {
6469 Binder.restoreCallingIdentity(identity);
6470 }
6471 }
6472
6473 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006474 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6475 final long identity = Binder.clearCallingIdentity();
6476 try {
6477 Phone phone = getPhone(subscriptionId);
6478 if (phone == null) {
6479 return null;
6480 }
6481 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6482 } finally {
6483 Binder.restoreCallingIdentity(identity);
6484 }
6485 }
6486
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006487 /**
6488 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006489 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006490 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006491 final long identity = Binder.clearCallingIdentity();
6492 try {
6493 Phone phone = getPhone(subId);
6494 if (phone != null) {
6495 return phone.isWifiCallingEnabled();
6496 } else {
6497 return false;
6498 }
6499 } finally {
6500 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006501 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006502 }
6503
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006504 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006505 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006506 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006507 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508 final long identity = Binder.clearCallingIdentity();
6509 try {
6510 Phone phone = getPhone(subId);
6511 if (phone != null) {
6512 return phone.isVideoEnabled();
6513 } else {
6514 return false;
6515 }
6516 } finally {
6517 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006518 }
6519 }
6520
6521 /**
6522 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6523 * defined in {@link ImsRegistrationImplBase}.
6524 */
6525 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526 final long identity = Binder.clearCallingIdentity();
6527 try {
6528 Phone phone = getPhone(subId);
6529 if (phone != null) {
6530 return phone.getImsRegistrationTech();
6531 } else {
6532 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6533 }
6534 } finally {
6535 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006536 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006537 }
6538
Stuart Scott8eef64f2015-04-08 15:13:54 -07006539 @Override
6540 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006541 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006542 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6543 return;
6544 }
6545
Svet Ganovcc087f82015-05-12 20:35:54 -07006546 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006547
Svet Ganovcc087f82015-05-12 20:35:54 -07006548 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006549 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6550 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006551 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006552 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006553 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006554 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6555 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006556 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006557 // There has been issues when Sms raw table somehow stores orphan
6558 // fragments. They lead to garbled message when new fragments come
6559 // in and combined with those stale ones. In case this happens again,
6560 // user can reset all network settings which will clean up this table.
6561 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006562 // Clean up IMS settings as well here.
6563 int slotId = getSlotIndex(subId);
6564 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6565 ImsManager.getInstance(mApp, slotId).factoryReset();
6566 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006567
6568 // Erase modem config if erase modem on network setting is enabled.
6569 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6570 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6571 if (configValue != null && Boolean.parseBoolean(configValue)) {
6572 sendEraseModemConfig(getDefaultPhone());
6573 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006574 } finally {
6575 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006576 }
6577 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006578
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006579 private void cleanUpSmsRawTable(Context context) {
6580 ContentResolver resolver = context.getContentResolver();
6581 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6582 resolver.delete(uri, null, null);
6583 }
6584
Narayan Kamath1c496c22015-04-16 14:40:19 +01006585 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006586 public String getSimLocaleForSubscriber(int subId) {
6587 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6588 final Phone phone = getPhone(subId);
6589 if (phone == null) {
6590 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006591 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006593 final long identity = Binder.clearCallingIdentity();
6594 try {
chen xu5d3637b2019-01-21 23:31:38 -08006595 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006596 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006597 if (info == null) {
6598 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6599 return null;
6600 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601 // Try and fetch the locale from the carrier properties or from the SIM language
6602 // preferences (EF-PL and EF-LI)...
6603 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006605 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6606 if (localeFromDefaultSim != null) {
6607 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6608 if (DBG) log("Using locale from subId: " + subId + " locale: "
6609 + localeFromDefaultSim);
6610 return localeFromDefaultSim.toLanguageTag();
6611 } else {
6612 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006613 }
6614 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006615
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616 // The SIM language preferences only store a language (e.g. fr = French), not an
6617 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6618 // the SIM and carrier preferences does not include a country we add the country
6619 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006620 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006621 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006622 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006623 return mccLocale.toLanguageTag();
6624 }
6625
6626 if (DBG) log("No locale found - returning null");
6627 return null;
6628 } finally {
6629 Binder.restoreCallingIdentity(identity);
6630 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006631 }
6632
6633 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006634 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6635 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006636 }
6637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006638 /**
6639 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6640 */
6641 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006642 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6643 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006644 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006645
Chenjie Yu1ba97252018-01-11 18:16:20 -08006646 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006647 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006648
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006649 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006650 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6651 * representing the state of the modem.
6652 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006653 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6654 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006655 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006656 */
6657 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006658 public void requestModemActivityInfo(ResultReceiver result) {
6659 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006660 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006661
6662 final long identity = Binder.clearCallingIdentity();
6663 try {
sqian1a1be542020-03-05 11:37:28 -08006664 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665 } finally {
6666 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006667 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006668 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006669
Siddharth Rayb8114062018-06-17 15:02:38 -07006670 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6671 // less than total activity duration.
6672 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6673 if (info == null) {
6674 return false;
6675 }
6676 int activityDurationMs =
6677 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6678 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006679 int[] txTimeMs = info.getTransmitTimeMillis();
6680 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6681 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006682 }
6683 return (info.isValid()
6684 && (info.getSleepTimeMillis() <= activityDurationMs)
6685 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006686 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006687 && (totalTxTimeMs <= activityDurationMs));
6688 }
6689
Jack Yu85bd38a2015-11-09 11:34:32 -08006690 /**
6691 * {@hide}
6692 * Returns the service state information on specified subscription.
6693 */
6694 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006695 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6696 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006697 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006698 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006699 return null;
6700 }
6701
Hall Liuf19c44f2018-11-27 14:38:17 -08006702 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6703 LocationAccessPolicy.checkLocationPermission(mApp,
6704 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6705 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006706 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006707 .setCallingPid(Binder.getCallingPid())
6708 .setCallingUid(Binder.getCallingUid())
6709 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006710 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006711 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6712 .build());
6713
6714 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6715 LocationAccessPolicy.checkLocationPermission(mApp,
6716 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6717 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006718 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006719 .setCallingPid(Binder.getCallingPid())
6720 .setCallingUid(Binder.getCallingUid())
6721 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006722 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006723 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6724 .build());
6725 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6726 boolean hasFinePermission =
6727 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6728 boolean hasCoarsePermission =
6729 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006731 final long identity = Binder.clearCallingIdentity();
6732 try {
6733 final Phone phone = getPhone(subId);
6734 if (phone == null) {
6735 return null;
6736 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006737
Hall Liuf19c44f2018-11-27 14:38:17 -08006738 ServiceState ss = phone.getServiceState();
6739
6740 // Scrub out the location info in ServiceState depending on what level of access
6741 // the caller has.
6742 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006743 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6744 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745 } finally {
6746 Binder.restoreCallingIdentity(identity);
6747 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006748 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006749
6750 /**
6751 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6752 *
6753 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6754 * voicemail ringtone.
6755 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6756 * PhoneAccount.
6757 */
6758 @Override
6759 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760 final long identity = Binder.clearCallingIdentity();
6761 try {
6762 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6763 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006764 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006765 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6768 } finally {
6769 Binder.restoreCallingIdentity(identity);
6770 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006771 }
6772
6773 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006774 * Sets the per-account voicemail ringtone.
6775 *
6776 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6777 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6778 *
6779 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6780 * voicemail ringtone.
6781 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6782 * PhoneAccount.
6783 */
6784 @Override
6785 public void setVoicemailRingtoneUri(String callingPackage,
6786 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006787 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006788 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006789 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6790 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6792 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6793 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006794 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006795
6796 final long identity = Binder.clearCallingIdentity();
6797 try {
6798 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6799 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006800 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801 }
6802 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6803 } finally {
6804 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006805 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006806 }
6807
6808 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006809 * Returns whether vibration is set for voicemail notification in Phone settings.
6810 *
6811 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6812 * voicemail vibration setting.
6813 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6814 */
6815 @Override
6816 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006817 final long identity = Binder.clearCallingIdentity();
6818 try {
6819 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6820 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006821 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006822 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006823
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006824 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6825 } finally {
6826 Binder.restoreCallingIdentity(identity);
6827 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006828 }
6829
Youhan Wange64578a2016-05-02 15:32:42 -07006830 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006831 * Sets the per-account voicemail vibration.
6832 *
6833 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6834 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6835 *
6836 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6837 * voicemail vibration setting.
6838 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6839 * specific PhoneAccount.
6840 */
6841 @Override
6842 public void setVoicemailVibrationEnabled(String callingPackage,
6843 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006844 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006845 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006846 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6847 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6849 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6850 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006851 }
6852
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006853 final long identity = Binder.clearCallingIdentity();
6854 try {
6855 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6856 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006857 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006858 }
6859 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6860 } finally {
6861 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006862 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006863 }
6864
6865 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006866 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6867 *
6868 * @throws SecurityException if the caller does not have the required permission
6869 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006870 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006871 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006872 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006873 }
6874
6875 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006876 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6877 * permission.
6878 *
6879 * @throws SecurityException if the caller does not have the required permission
6880 */
6881 private void enforceSendSmsPermission() {
6882 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6883 }
6884
6885 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006886 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006887 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006888 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006889 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006890 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891 final long identity = Binder.clearCallingIdentity();
6892 try {
6893 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006894 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895 if (componentName == null) {
6896 throw new SecurityException(
6897 "Caller not current active visual voicemail package[null]");
6898 }
6899 String vvmPackage = componentName.getPackageName();
6900 if (!callingPackage.equals(vvmPackage)) {
6901 throw new SecurityException("Caller not current active visual voicemail package["
6902 + vvmPackage + "]");
6903 }
6904 } finally {
6905 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006906 }
6907 }
6908
6909 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006910 * Return the application ID for the app type.
6911 *
6912 * @param subId the subscription ID that this request applies to.
6913 * @param appType the uicc app type.
6914 * @return Application ID for specificied app type, or null if no uicc.
6915 */
6916 @Override
6917 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006918 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006919 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006920
6921 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006922 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006923 if (phone == null) {
6924 return null;
6925 }
6926 String aid = null;
6927 try {
6928 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6929 .getApplicationByType(appType).getAid();
6930 } catch (Exception e) {
6931 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6932 }
6933 return aid;
6934 } finally {
6935 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006936 }
Youhan Wange64578a2016-05-02 15:32:42 -07006937 }
6938
Youhan Wang4001d252016-05-11 10:29:41 -07006939 /**
6940 * Return the Electronic Serial Number.
6941 *
6942 * @param subId the subscription ID that this request applies to.
6943 * @return ESN or null if error.
6944 */
6945 @Override
6946 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006947 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006948 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006949
6950 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006951 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952 if (phone == null) {
6953 return null;
6954 }
6955 String esn = null;
6956 try {
6957 esn = phone.getEsn();
6958 } catch (Exception e) {
6959 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6960 }
6961 return esn;
6962 } finally {
6963 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006964 }
Youhan Wang4001d252016-05-11 10:29:41 -07006965 }
6966
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006967 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006968 * Return the Preferred Roaming List Version.
6969 *
6970 * @param subId the subscription ID that this request applies to.
6971 * @return PRLVersion or null if error.
6972 */
6973 @Override
6974 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006975 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006976 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006977
6978 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006979 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006980 if (phone == null) {
6981 return null;
6982 }
6983 String cdmaPrlVersion = null;
6984 try {
6985 cdmaPrlVersion = phone.getCdmaPrlVersion();
6986 } catch (Exception e) {
6987 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6988 }
6989 return cdmaPrlVersion;
6990 } finally {
6991 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006992 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006993 }
6994
6995 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006996 * Get snapshot of Telephony histograms
6997 * @return List of Telephony histograms
6998 * @hide
6999 */
7000 @Override
7001 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7003 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004
7005 final long identity = Binder.clearCallingIdentity();
7006 try {
7007 return RIL.getTelephonyRILTimingHistograms();
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
7010 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007011 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007012
7013 /**
7014 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007015 * Set the allowed carrier list and the excluded carrier list, indicating 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 Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007020 */
7021 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007022 @TelephonyManager.SetCarrierRestrictionResult
7023 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007024 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007025 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007026
Michele Berionne482f8202018-11-27 18:57:59 -08007027 if (carrierRestrictionRules == null) {
7028 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007029 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007030
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 final long identity = Binder.clearCallingIdentity();
7032 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007033 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007034 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 } finally {
7036 Binder.restoreCallingIdentity(identity);
7037 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007038 }
7039
7040 /**
7041 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007042 * Get the allowed carrier list and the excluded carrier list, including the priority between
7043 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007044 * Require system privileges. In the future we may add this to carrier APIs.
7045 *
Michele Berionne482f8202018-11-27 18:57:59 -08007046 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007047 */
7048 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007049 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007050 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007051 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052
7053 final long identity = Binder.clearCallingIdentity();
7054 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007055 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7056 if (response instanceof CarrierRestrictionRules) {
7057 return (CarrierRestrictionRules) response;
7058 }
7059 // Response is an Exception of some kind,
7060 // which is signalled to the user as a NULL retval
7061 return null;
7062 } catch (Exception e) {
7063 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7064 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007065 } finally {
7066 Binder.restoreCallingIdentity(identity);
7067 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007068 }
7069
fionaxu59545b42016-05-25 15:53:37 -07007070 /**
7071 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7072 * @param subId the subscription ID that this action applies to.
7073 * @param enabled control enable or disable metered apns.
7074 * {@hide}
7075 */
7076 @Override
7077 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7078 enforceModifyPermission();
7079 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080
7081 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007082 if (phone == null) {
7083 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7084 return;
7085 }
7086 try {
7087 phone.carrierActionSetMeteredApnsEnabled(enabled);
7088 } catch (Exception e) {
7089 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 } finally {
7091 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007092 }
7093 }
7094
7095 /**
7096 * Action set from carrier signalling broadcast receivers to enable/disable radio
7097 * @param subId the subscription ID that this action applies to.
7098 * @param enabled control enable or disable radio.
7099 * {@hide}
7100 */
7101 @Override
7102 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7103 enforceModifyPermission();
7104 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007105
7106 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007107 if (phone == null) {
7108 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7109 return;
7110 }
7111 try {
7112 phone.carrierActionSetRadioEnabled(enabled);
7113 } catch (Exception e) {
7114 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007115 } finally {
7116 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007117 }
7118 }
7119
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007120 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007121 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7122 * network status based on which carrier apps could apply actions accordingly,
7123 * enable/disable default url handler for example.
7124 *
7125 * @param subId the subscription ID that this action applies to.
7126 * @param report control start/stop reporting the default network status.
7127 * {@hide}
7128 */
7129 @Override
7130 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7131 enforceModifyPermission();
7132 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133
7134 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007135 if (phone == null) {
7136 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7137 return;
7138 }
7139 try {
7140 phone.carrierActionReportDefaultNetworkStatus(report);
7141 } catch (Exception e) {
7142 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007143 } finally {
7144 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007145 }
7146 }
7147
7148 /**
fionaxud9622282017-07-17 17:51:30 -07007149 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7150 * @param subId the subscription ID that this action applies to.
7151 * {@hide}
7152 */
7153 @Override
7154 public void carrierActionResetAll(int subId) {
7155 enforceModifyPermission();
7156 final Phone phone = getPhone(subId);
7157 if (phone == null) {
7158 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7159 return;
7160 }
7161 try {
7162 phone.carrierActionResetAll();
7163 } catch (Exception e) {
7164 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7165 }
7166 }
7167
7168 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007169 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7170 * bug report is being generated.
7171 */
7172 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007173 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007174 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7175 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007176 writer.println("Permission Denial: can't dump Phone from pid="
7177 + Binder.getCallingPid()
7178 + ", uid=" + Binder.getCallingUid()
7179 + "without permission "
7180 + android.Manifest.permission.DUMP);
7181 return;
7182 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007183 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007184 }
Jack Yueb89b242016-06-22 13:27:47 -07007185
Brad Ebingerdac2f002018-04-03 15:17:52 -07007186 @Override
7187 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7188 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7189 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007190 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7191 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007192 }
7193
Jack Yueb89b242016-06-22 13:27:47 -07007194 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007195 * Policy control of data connection. Usually used when data limit is passed.
7196 * @param enabled True if enabling the data, otherwise disabling.
7197 * @param subId Subscription index
7198 * {@hide}
7199 */
7200 @Override
7201 public void setPolicyDataEnabled(boolean enabled, int subId) {
7202 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007203
7204 final long identity = Binder.clearCallingIdentity();
7205 try {
7206 Phone phone = getPhone(subId);
7207 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007208 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209 }
7210 } finally {
7211 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007212 }
7213 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007214
7215 /**
7216 * Get Client request stats
7217 * @return List of Client Request Stats
7218 * @hide
7219 */
7220 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007221 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7222 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007224 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007225 return null;
7226 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007227 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007229 final long identity = Binder.clearCallingIdentity();
7230 try {
7231 if (phone != null) {
7232 return phone.getClientRequestStats();
7233 }
7234
7235 return null;
7236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007239 }
7240
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007241 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007242 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007243 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007244 }
Jack Yueb4124c2017-02-16 15:32:43 -08007245
7246 /**
Grace Chen70990072017-03-24 17:21:30 -07007247 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007248 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007249 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007250 * @param state State of SIM (power down, power up, pass through)
7251 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7252 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7253 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007254 *
7255 **/
7256 @Override
Grace Chen70990072017-03-24 17:21:30 -07007257 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007258 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007259 Phone phone = PhoneFactory.getPhone(slotIndex);
7260
vagdeviaf9a5b92018-08-15 16:01:53 -07007261 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007263 final long identity = Binder.clearCallingIdentity();
7264 try {
7265 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007266 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007267 }
7268 } finally {
7269 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007270 }
7271 }
Shuo Qiandd210312017-04-12 22:11:33 +00007272
Tyler Gunn65d45c22017-06-05 11:22:26 -07007273 private boolean isUssdApiAllowed(int subId) {
7274 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007275 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007276 if (configManager == null) {
7277 return false;
7278 }
7279 PersistableBundle pb = configManager.getConfigForSubId(subId);
7280 if (pb == null) {
7281 return false;
7282 }
7283 return pb.getBoolean(
7284 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7285 }
7286
Shuo Qiandd210312017-04-12 22:11:33 +00007287 /**
7288 * Check if phone is in emergency callback mode
7289 * @return true if phone is in emergency callback mode
7290 * @param subId sub id
7291 */
goneil9c5f4872017-12-05 14:07:56 -08007292 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007293 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007294 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007295 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007296
7297 final long identity = Binder.clearCallingIdentity();
7298 try {
7299 if (phone != null) {
7300 return phone.isInEcm();
7301 } else {
7302 return false;
7303 }
7304 } finally {
7305 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007306 }
7307 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007308
7309 /**
7310 * Get the current signal strength information for the given subscription.
7311 * Because this information is not updated when the device is in a low power state
7312 * it should not be relied-upon to be current.
7313 * @param subId Subscription index
7314 * @return the most recent cached signal strength info from the modem
7315 */
7316 @Override
7317 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318 final long identity = Binder.clearCallingIdentity();
7319 try {
7320 Phone p = getPhone(subId);
7321 if (p == null) {
7322 return null;
7323 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007325 return p.getSignalStrength();
7326 } finally {
7327 Binder.restoreCallingIdentity(identity);
7328 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007329 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007330
Pengquan Meng77b7f132018-08-22 14:49:57 -07007331 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007332 * Get the current modem radio state for the given slot.
7333 * @param slotIndex slot index.
7334 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007335 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007336 * @return the current radio power state from the modem
7337 */
7338 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007339 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007340 Phone phone = PhoneFactory.getPhone(slotIndex);
7341 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007342 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7343 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007344 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7345 }
7346
7347 final long identity = Binder.clearCallingIdentity();
7348 try {
7349 return phone.getRadioPowerState();
7350 } finally {
7351 Binder.restoreCallingIdentity(identity);
7352 }
7353 }
7354 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7355 }
7356
7357 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007358 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7359 *
7360 * <p>Requires one of the following permissions:
7361 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7362 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7363 * privileges.
7364 *
7365 * @param subId subscription id
7366 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7367 * {@code false}.
7368 */
7369 @Override
7370 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007371 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7372 null /* message */);
7373
Pengquan Menga1bb6272018-09-06 09:59:22 -07007374 boolean isEnabled = false;
7375 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007376 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007377 Phone phone = getPhone(subId);
7378 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007379 } catch (Exception e) {
7380 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7381 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007382 } finally {
7383 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007384 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007385 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007386 }
7387
7388
7389 /**
7390 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7391 *
7392 * <p> Requires permission:
7393 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7394 * privileges.
7395 *
7396 * @param subId subscription id
7397 * @param isEnabled {@code true} means enable, {@code false} means disable.
7398 */
7399 @Override
7400 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7402 mApp, subId, "setDataRoamingEnabled");
7403
Pengquan Menga1bb6272018-09-06 09:59:22 -07007404 final long identity = Binder.clearCallingIdentity();
7405 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007406 Phone phone = getPhone(subId);
7407 if (phone != null) {
7408 phone.setDataRoamingEnabled(isEnabled);
7409 }
7410 } finally {
7411 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007412 }
7413 }
7414
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007415 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007416 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007417 TelephonyPermissions
7418 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007419 mApp, subId, "isManualNetworkSelectionAllowed");
7420
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007421 boolean isAllowed = true;
7422 final long identity = Binder.clearCallingIdentity();
7423 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007424 Phone phone = getPhone(subId);
7425 if (phone != null) {
7426 isAllowed = phone.isCspPlmnEnabled();
7427 }
7428 } finally {
7429 Binder.restoreCallingIdentity(identity);
7430 }
7431 return isAllowed;
7432 }
7433
7434 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007435 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liua39e6c12020-03-04 13:59:23 -08007436 try {
7437 PackageManager pm = mApp.getPackageManager();
7438 if (Binder.getCallingUid() != pm.getPackageUid(callingPackage, 0)) {
7439 throw new SecurityException("Calling package " + callingPackage + " does not match "
7440 + "calling UID");
7441 }
7442 } catch (PackageManager.NameNotFoundException e) {
7443 throw new SecurityException("Invalid calling package. e=" + e);
7444 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007445 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007446 try {
7447 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007448 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007449 } catch (SecurityException e) {
7450 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7451 // has carrier privileges on an active UICC
7452 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7453 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007454 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007455 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007456 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007457
7458 final long identity = Binder.clearCallingIdentity();
7459 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007460 UiccController uiccController = UiccController.getInstance();
7461 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007462 if (hasReadPermission) {
7463 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007464 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007465
7466 // Remove private info if the caller doesn't have access
7467 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7468 for (UiccCardInfo cardInfo : cardInfos) {
7469 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7470 // is available
7471 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7472 if (card == null || card.getUiccProfile() == null) {
7473 // assume no access if the card or profile is unavailable
7474 filteredInfos.add(cardInfo.getUnprivileged());
7475 continue;
7476 }
7477 UiccProfile profile = card.getUiccProfile();
7478 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7479 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7480 filteredInfos.add(cardInfo);
7481 } else {
7482 filteredInfos.add(cardInfo.getUnprivileged());
7483 }
7484 }
7485 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007486 } finally {
7487 Binder.restoreCallingIdentity(identity);
7488 }
7489 }
7490
7491 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007492 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007493 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 final long identity = Binder.clearCallingIdentity();
7496 try {
7497 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7498 if (slots == null) {
7499 Rlog.i(LOG_TAG, "slots is null.");
7500 return null;
7501 }
7502
7503 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7504 for (int i = 0; i < slots.length; i++) {
7505 UiccSlot slot = slots[i];
7506 if (slot == null) {
7507 continue;
7508 }
7509
Jordan Liu7be7e652019-05-06 18:55:02 +00007510 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 UiccCard card = slot.getUiccCard();
7512 if (card != null) {
7513 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007514 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007515 cardId = slot.getEid();
7516 if (TextUtils.isEmpty(cardId)) {
7517 cardId = slot.getIccId();
7518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007519 }
7520
Jordan Liu857451f2019-05-09 16:35:35 -07007521 if (cardId != null) {
7522 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7523 // if cardId is an EID, it's all digits so this is fine
7524 cardId = IccUtils.stripTrailingFs(cardId);
7525 }
7526
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 int cardState = 0;
7528 switch (slot.getCardState()) {
7529 case CARDSTATE_ABSENT:
7530 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7531 break;
7532 case CARDSTATE_PRESENT:
7533 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7534 break;
7535 case CARDSTATE_ERROR:
7536 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7537 break;
7538 case CARDSTATE_RESTRICTED:
7539 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7540 break;
7541 default:
7542 break;
7543
7544 }
7545
7546 infos[i] = new UiccSlotInfo(
7547 slot.isActive(),
7548 slot.isEuicc(),
7549 cardId,
7550 cardState,
7551 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007552 slot.isExtendedApduSupported(),
7553 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 }
7555 return infos;
7556 } finally {
7557 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007558 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007559 }
7560
7561 @Override
7562 public boolean switchSlots(int[] physicalSlots) {
7563 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564
7565 final long identity = Binder.clearCallingIdentity();
7566 try {
7567 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7568 } finally {
7569 Binder.restoreCallingIdentity(identity);
7570 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007571 }
Jack Yu4c988042018-02-27 15:30:01 -08007572
7573 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007574 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007575 final long identity = Binder.clearCallingIdentity();
7576 try {
7577 return UiccController.getInstance().getCardIdForDefaultEuicc();
7578 } finally {
7579 Binder.restoreCallingIdentity(identity);
7580 }
7581 }
7582
Pengquan Meng85728fb2018-03-12 16:31:21 -07007583 /**
goneil47ffb6e2018-04-06 15:40:58 -07007584 * A test API to reload the UICC profile.
7585 *
7586 * <p>Requires that the calling app has permission
7587 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7588 * @hide
7589 */
7590 @Override
7591 public void refreshUiccProfile(int subId) {
7592 enforceModifyPermission();
7593
7594 final long identity = Binder.clearCallingIdentity();
7595 try {
7596 Phone phone = getPhone(subId);
7597 if (phone == null) {
7598 return;
7599 }
7600 UiccCard uiccCard = phone.getUiccCard();
7601 if (uiccCard == null) {
7602 return;
7603 }
7604 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7605 if (uiccProfile == null) {
7606 return;
7607 }
7608 uiccProfile.refresh();
7609 } finally {
7610 Binder.restoreCallingIdentity(identity);
7611 }
7612 }
7613
7614 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007615 * Returns false if the mobile data is disabled by default, otherwise return true.
7616 */
7617 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007618 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007619 }
7620
7621 /**
7622 * Returns true if the data roaming is enabled by default, i.e the system property
7623 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7624 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7625 */
7626 private boolean getDefaultDataRoamingEnabled(int subId) {
7627 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007628 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007629 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007630 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7631 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7632 return isDataRoamingEnabled;
7633 }
7634
7635 /**
7636 * Returns the default network type for the given {@code subId}, if the default network type is
7637 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7638 */
7639 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007640 List<Integer> list = TelephonyProperties.default_network();
7641 int phoneId = mSubscriptionController.getPhoneId(subId);
7642 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7643 return list.get(phoneId);
7644 }
7645 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007646 }
fionaxua13278b2018-03-21 00:08:13 -07007647
7648 @Override
7649 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007650 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007651 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007652
7653 final long identity = Binder.clearCallingIdentity();
7654 try {
7655 final Phone phone = getPhone(subId);
7656 if (phone == null) {
7657 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7658 return;
7659 }
chen xueaba88a2019-03-15 13:15:10 -07007660 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7661 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662 } finally {
7663 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007664 }
fionaxua13278b2018-03-21 00:08:13 -07007665 }
7666
7667 @Override
7668 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007669 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007670
7671 final long identity = Binder.clearCallingIdentity();
7672 try {
7673 final Phone phone = getPhone(subId);
7674 if (phone == null) {
7675 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7676 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7677 }
7678 return phone.getCarrierIdListVersion();
7679 } finally {
7680 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007681 }
fionaxua13278b2018-03-21 00:08:13 -07007682 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007683
7684 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007685 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7686 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007687 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007688 mApp, subId, callingPackage, callingFeatureId,
7689 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007690 return -1;
7691 }
7692
7693 final long identity = Binder.clearCallingIdentity();
7694 try {
7695 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7696 } finally {
7697 Binder.restoreCallingIdentity(identity);
7698 }
7699 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007700
7701 @Override
7702 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007703 TelephonyPermissions
7704 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007705 mApp, subId, "getCdmaRoamingMode");
7706
7707 final long identity = Binder.clearCallingIdentity();
7708 try {
7709 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7710 } finally {
7711 Binder.restoreCallingIdentity(identity);
7712 }
7713 }
7714
7715 @Override
7716 public boolean setCdmaRoamingMode(int subId, int mode) {
7717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7718 mApp, subId, "setCdmaRoamingMode");
7719
7720 final long identity = Binder.clearCallingIdentity();
7721 try {
7722 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7723 } finally {
7724 Binder.restoreCallingIdentity(identity);
7725 }
7726 }
7727
7728 @Override
7729 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7731 mApp, subId, "setCdmaSubscriptionMode");
7732
7733 final long identity = Binder.clearCallingIdentity();
7734 try {
7735 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7736 } finally {
7737 Binder.restoreCallingIdentity(identity);
7738 }
7739 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007740
sqianc5eccab2018-10-19 18:46:41 -07007741 @Override
sqian8c685422019-02-22 15:55:18 -08007742 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007743 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007744 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007745 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7746 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007747 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7748 }
7749 final long identity = Binder.clearCallingIdentity();
7750 try {
sqian854d44b2018-12-12 16:48:18 -08007751 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7752 for (Phone phone: PhoneFactory.getPhones()) {
7753 if (phone.getEmergencyNumberTracker() != null
7754 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7755 emergencyNumberListInternal.put(
7756 phone.getSubId(),
7757 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7758 }
sqian11b7a0e2018-12-05 18:48:28 -08007759 }
sqian854d44b2018-12-12 16:48:18 -08007760 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007761 } finally {
7762 Binder.restoreCallingIdentity(identity);
7763 }
sqianc5eccab2018-10-19 18:46:41 -07007764 }
7765
7766 @Override
sqian8c685422019-02-22 15:55:18 -08007767 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007768 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007769 if (!exactMatch) {
7770 TelephonyPermissions
7771 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007772 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007773 }
7774 final long identity = Binder.clearCallingIdentity();
7775 try {
sqian854d44b2018-12-12 16:48:18 -08007776 for (Phone phone: PhoneFactory.getPhones()) {
7777 if (phone.getEmergencyNumberTracker() != null
7778 && phone.getEmergencyNumberTracker() != null) {
7779 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7780 number, exactMatch)) {
7781 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007782 }
7783 }
sqian11b7a0e2018-12-05 18:48:28 -08007784 }
7785 return false;
7786 } finally {
7787 Binder.restoreCallingIdentity(identity);
7788 }
7789 }
7790
sqianf4ca7ed2019-01-15 18:32:07 -08007791 /**
7792 * Update emergency number list for test mode.
7793 */
7794 @Override
7795 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7796 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7797 "updateEmergencyNumberListTestMode");
7798
7799 final long identity = Binder.clearCallingIdentity();
7800 try {
7801 for (Phone phone: PhoneFactory.getPhones()) {
7802 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7803 if (tracker != null) {
7804 tracker.executeEmergencyNumberTestModeCommand(action, num);
7805 }
7806 }
7807 } finally {
7808 Binder.restoreCallingIdentity(identity);
7809 }
7810 }
7811
7812 /**
7813 * Get the full emergency number list for test mode.
7814 */
7815 @Override
7816 public List<String> getEmergencyNumberListTestMode() {
7817 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7818 "getEmergencyNumberListTestMode");
7819
7820 final long identity = Binder.clearCallingIdentity();
7821 try {
7822 Set<String> emergencyNumbers = new HashSet<>();
7823 for (Phone phone: PhoneFactory.getPhones()) {
7824 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7825 if (tracker != null) {
7826 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7827 emergencyNumbers.add(num.getNumber());
7828 }
7829 }
7830 }
7831 return new ArrayList<>(emergencyNumbers);
7832 } finally {
7833 Binder.restoreCallingIdentity(identity);
7834 }
7835 }
7836
chen xud6b45bd2018-10-30 22:27:10 -07007837 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007838 public int getEmergencyNumberDbVersion(int subId) {
7839 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7840
7841 final long identity = Binder.clearCallingIdentity();
7842 try {
7843 final Phone phone = getPhone(subId);
7844 if (phone == null) {
7845 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7846 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7847 }
7848 return phone.getEmergencyNumberDbVersion();
7849 } finally {
7850 Binder.restoreCallingIdentity(identity);
7851 }
7852 }
7853
7854 @Override
7855 public void notifyOtaEmergencyNumberDbInstalled() {
7856 enforceModifyPermission();
7857
7858 final long identity = Binder.clearCallingIdentity();
7859 try {
7860 for (Phone phone: PhoneFactory.getPhones()) {
7861 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7862 if (tracker != null) {
7863 tracker.updateOtaEmergencyNumberDatabase();
7864 }
7865 }
7866 } finally {
7867 Binder.restoreCallingIdentity(identity);
7868 }
7869 }
7870
7871 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08007872 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08007873 enforceActiveEmergencySessionPermission();
7874
7875 final long identity = Binder.clearCallingIdentity();
7876 try {
7877 for (Phone phone: PhoneFactory.getPhones()) {
7878 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7879 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08007880 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7881 }
7882 }
7883 } finally {
7884 Binder.restoreCallingIdentity(identity);
7885 }
7886 }
7887
7888 @Override
7889 public void resetOtaEmergencyNumberDbFilePath() {
7890 enforceActiveEmergencySessionPermission();
7891
7892 final long identity = Binder.clearCallingIdentity();
7893 try {
7894 for (Phone phone: PhoneFactory.getPhones()) {
7895 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7896 if (tracker != null) {
7897 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08007898 }
7899 }
7900 } finally {
7901 Binder.restoreCallingIdentity(identity);
7902 }
7903 }
7904
7905 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007906 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7907 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7908 Phone phone = getPhone(subId);
7909 if (phone == null) {
7910 return null;
7911 }
7912 final long identity = Binder.clearCallingIdentity();
7913 try {
7914 UiccProfile profile = UiccController.getInstance()
7915 .getUiccProfileForPhone(phone.getPhoneId());
7916 if (profile != null) {
7917 return profile.getCertsFromCarrierPrivilegeAccessRules();
7918 }
7919 } finally {
7920 Binder.restoreCallingIdentity(identity);
7921 }
7922 return null;
7923 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007924
7925 /**
7926 * Enable or disable a modem stack.
7927 */
7928 @Override
7929 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7930 enforceModifyPermission();
7931
7932 final long identity = Binder.clearCallingIdentity();
7933 try {
7934 Phone phone = PhoneFactory.getPhone(slotIndex);
7935 if (phone == null) {
7936 return false;
7937 } else {
7938 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7939 }
7940 } finally {
7941 Binder.restoreCallingIdentity(identity);
7942 }
7943 }
Michelecea4cf22018-12-21 15:00:11 -08007944
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007945 /**
7946 * Whether a modem stack is enabled or not.
7947 */
7948 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007949 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7950 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007951 Phone phone = PhoneFactory.getPhone(slotIndex);
7952 if (phone == null) return false;
7953
7954 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007955 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7956 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007957 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7958 }
7959
7960 final long identity = Binder.clearCallingIdentity();
7961 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007962 try {
7963 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7964 } catch (NoSuchElementException ex) {
7965 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7966 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007967 } finally {
7968 Binder.restoreCallingIdentity(identity);
7969 }
7970 }
7971
Michelecea4cf22018-12-21 15:00:11 -08007972 @Override
Michele0ea7d782019-03-19 14:58:42 -07007973 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007974 enforceModifyPermission();
7975
7976 final long identity = Binder.clearCallingIdentity();
7977 try {
7978 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007979 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007980 .commit();
7981 } finally {
7982 Binder.restoreCallingIdentity(identity);
7983 }
7984 }
7985
7986 @Override
Michele0ea7d782019-03-19 14:58:42 -07007987 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007988 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007990 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7991 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007992 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007993 }
Michelecea4cf22018-12-21 15:00:11 -08007994
7995 final long identity = Binder.clearCallingIdentity();
7996 try {
Michele0ea7d782019-03-19 14:58:42 -07007997 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007998 } finally {
7999 Binder.restoreCallingIdentity(identity);
8000 }
8001 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008002
Michele0ea7d782019-03-19 14:58:42 -07008003 @TelephonyManager.IsMultiSimSupportedResult
8004 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008005 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8006 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8007 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008008 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8009 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008010 }
8011 // Check if the hardware supports multisim functionality. If usage of multisim is not
8012 // supported by the modem, indicate that it is restricted.
8013 PhoneCapability staticCapability =
8014 mPhoneConfigurationManager.getStaticPhoneCapability();
8015 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008016 loge("isMultiSimSupportedInternal: no static configuration available");
8017 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008018 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008019 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008020 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8021 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008022 }
8023 // Check if support of multiple SIMs is restricted by carrier
8024 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008025 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008026 }
8027
Michele0ea7d782019-03-19 14:58:42 -07008028 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008029 }
8030
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008031 /**
8032 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008033 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8034 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8035 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008036 * @param numOfSims number of active sims we want to switch to
8037 */
8038 @Override
8039 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008040 if (numOfSims == 1) {
8041 enforceModifyPermission();
8042 } else {
8043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8044 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8045 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008046 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008047
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008048 try {
Michele30b57b22019-03-01 12:01:14 -08008049 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008050 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008051 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8052 return;
8053 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008054 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8055 } finally {
8056 Binder.restoreCallingIdentity(identity);
8057 }
8058 }
8059
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008060 @Override
8061 public boolean isApplicationOnUicc(int subId, int appType) {
8062 enforceReadPrivilegedPermission("isApplicationOnUicc");
8063 Phone phone = getPhone(subId);
8064 if (phone == null) {
8065 return false;
8066 }
8067 final long identity = Binder.clearCallingIdentity();
8068 try {
8069 UiccCard uiccCard = phone.getUiccCard();
8070 if (uiccCard == null) {
8071 return false;
8072 }
8073 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8074 if (uiccProfile == null) {
8075 return false;
8076 }
8077 if (TelephonyManager.APPTYPE_SIM <= appType
8078 && appType <= TelephonyManager.APPTYPE_ISIM) {
8079 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8080 }
8081 return false;
8082 } finally {
8083 Binder.restoreCallingIdentity(identity);
8084 }
8085 }
8086
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008087 /**
chen xub4baa772019-04-03 10:23:41 -07008088 * Get whether making changes to modem configurations will trigger reboot.
8089 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008090 */
8091 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008092 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8093 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008094 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008095 mApp, subId, callingPackage, callingFeatureId,
8096 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008097 return false;
8098 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008099 final long identity = Binder.clearCallingIdentity();
8100 try {
8101 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8102 } finally {
8103 Binder.restoreCallingIdentity(identity);
8104 }
8105 }
8106
Nathan Harold29f5f052019-02-15 13:41:57 -08008107 private void updateModemStateMetrics() {
8108 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8109 // TODO: check the state for each modem if the api is ready.
8110 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8111 }
8112
Pengquan Meng3889a572019-01-23 11:16:29 -08008113 @Override
8114 public int[] getSlotsMapping() {
8115 enforceReadPrivilegedPermission("getSlotsMapping");
8116
8117 final long identity = Binder.clearCallingIdentity();
8118 try {
8119 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8120 // All logical slots should have a mapping to a physical slot.
8121 int[] logicalSlotsMapping = new int[phoneCount];
8122 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8123 for (int i = 0; i < slotInfos.length; i++) {
8124 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8125 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8126 }
8127 }
8128 return logicalSlotsMapping;
8129 } finally {
8130 Binder.restoreCallingIdentity(identity);
8131 }
8132 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008133
8134 /**
8135 * Get the IRadio HAL Version
8136 */
8137 @Override
8138 public int getRadioHalVersion() {
8139 Phone phone = getDefaultPhone();
8140 if (phone == null) return -1;
8141 HalVersion hv = phone.getHalVersion();
8142 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8143 return hv.major * 100 + hv.minor;
8144 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008145
8146 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008147 * Get the current calling package name.
8148 * @return the current calling package name
8149 */
8150 @Override
8151 public String getCurrentPackageName() {
8152 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8153 }
8154
8155 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008156 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8157 * corresponding network requests on a subId.
8158 *
8159 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008160 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008161 * 2) APN is un-metered for this subscription, or
8162 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008163 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008164 *
8165 * @return whether data is allowed for a apn type.
8166 *
8167 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008168 */
8169 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008170 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008171 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8172 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008173
8174 // Now that all security checks passes, perform the operation as ourselves.
8175 final long identity = Binder.clearCallingIdentity();
8176 try {
8177 Phone phone = getPhone(subId);
8178 if (phone == null) return false;
8179
Jack Yu41407ee2019-05-13 16:54:09 -07008180 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008181 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8182 } finally {
8183 Binder.restoreCallingIdentity(identity);
8184 }
8185 }
8186
8187 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008188 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008189 enforceReadPrivilegedPermission("isApnMetered");
8190
8191 // Now that all security checks passes, perform the operation as ourselves.
8192 final long identity = Binder.clearCallingIdentity();
8193 try {
8194 Phone phone = getPhone(subId);
8195 if (phone == null) return true; // By default return true.
8196
Jack Yu41407ee2019-05-13 16:54:09 -07008197 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008198 } finally {
8199 Binder.restoreCallingIdentity(identity);
8200 }
8201 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008202
8203 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008204 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8205 int subscriptionId, IBooleanConsumer resultCallback) {
8206 enforceModifyPermission();
8207 long token = Binder.clearCallingIdentity();
8208 try {
8209 Phone phone = getPhone(subscriptionId);
8210 if (phone == null) {
8211 try {
8212 if (resultCallback != null) {
8213 resultCallback.accept(false);
8214 }
8215 } catch (RemoteException e) {
8216 // ignore
8217 }
8218 return;
8219 }
8220 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8221 Pair.create(specifiers, (x) -> {
8222 try {
8223 if (resultCallback != null) {
8224 resultCallback.accept(x);
8225 }
8226 } catch (RemoteException e) {
8227 // ignore
8228 }
8229 });
8230 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8231 } finally {
8232 Binder.restoreCallingIdentity(token);
8233 }
8234 }
8235
8236 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008237 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8238 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8239 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8240 if (iccRecords == null) {
8241 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8242 return false;
8243 }
8244 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8245 }
8246
8247 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008248 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8249 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008250 if (callingPackage == null) {
8251 callingPackage = getCurrentPackageName();
8252 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008253 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8254 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008255 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8256 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008257 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8258 }
8259 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8260 Intent intent = new Intent();
8261 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8262 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8263 // Bring up choose default SMS subscription dialog right now
8264 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8265 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8266 mApp.startActivity(intent);
8267 }
chen xud5ca2d52019-05-28 15:20:57 -07008268
8269 @Override
8270 public String getMmsUAProfUrl(int subId) {
8271 //TODO investigate if this API should require proper permission check in R b/133791609
8272 final long identity = Binder.clearCallingIdentity();
8273 try {
8274 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8275 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8276 } finally {
8277 Binder.restoreCallingIdentity(identity);
8278 }
8279 }
8280
8281 @Override
8282 public String getMmsUserAgent(int subId) {
8283 //TODO investigate if this API should require proper permission check in R b/133791609
8284 final long identity = Binder.clearCallingIdentity();
8285 try {
8286 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8287 .getString(com.android.internal.R.string.config_mms_user_agent);
8288 } finally {
8289 Binder.restoreCallingIdentity(identity);
8290 }
8291 }
Jack Yub07d4972019-05-28 16:12:25 -07008292
8293 @Override
8294 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8295 enforceModifyPermission();
8296
8297 // Now that all security checks passes, perform the operation as ourselves.
8298 final long identity = Binder.clearCallingIdentity();
8299 try {
8300 Phone phone = getPhone(subId);
8301 if (phone == null) return false;
8302
8303 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8304 } finally {
8305 Binder.restoreCallingIdentity(identity);
8306 }
8307 }
8308
8309 @Override
8310 public boolean isDataAllowedInVoiceCall(int subId) {
8311 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8312
8313 // Now that all security checks passes, perform the operation as ourselves.
8314 final long identity = Binder.clearCallingIdentity();
8315 try {
8316 Phone phone = getPhone(subId);
8317 if (phone == null) return false;
8318
8319 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8320 } finally {
8321 Binder.restoreCallingIdentity(identity);
8322 }
8323 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008324
changbetty97defcf2019-12-24 15:40:37 +08008325 @Override
8326 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8327 enforceModifyPermission();
8328
8329 // Now that all security checks passes, perform the operation as ourselves.
8330 final long identity = Binder.clearCallingIdentity();
8331 try {
8332 Phone phone = getPhone(subId);
8333 if (phone == null) return false;
8334
8335 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8336 } finally {
8337 Binder.restoreCallingIdentity(identity);
8338 }
8339 }
8340
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008341 /**
8342 * Updates whether conference event pacakge handling is enabled.
8343 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8344 * otherwise.
8345 */
8346 @Override
8347 public void setCepEnabled(boolean isCepEnabled) {
8348 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8349
8350 final long identity = Binder.clearCallingIdentity();
8351 try {
8352 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8353 for (Phone phone : PhoneFactory.getPhones()) {
8354 Phone defaultPhone = phone.getImsPhone();
8355 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8356 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8357 ImsPhoneCallTracker imsPhoneCallTracker =
8358 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8359 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8360 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8361 + imsPhone.getMsisdn());
8362 }
8363 }
8364 } finally {
8365 Binder.restoreCallingIdentity(identity);
8366 }
8367 }
allenwtsu46dcc572020-01-08 18:24:03 +08008368
8369 /**
8370 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8371 *
8372 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8373 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8374 * before being read.
8375 */
8376 @Override
8377 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8378 isCompressed) {
8379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8380 mApp, subId, "notifyRcsAutoConfigurationReceived");
8381 try {
8382 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8383 if (configBinder == null) {
8384 Rlog.e(LOG_TAG, "null result for getImsConfig");
8385 } else {
8386 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8387 }
8388 } catch (RemoteException e) {
8389 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8390 }
8391 }
zoey chenf95ca592019-12-30 16:11:23 +08008392
8393 @Override
8394 public boolean isIccLockEnabled(int subId) {
8395 enforceReadPrivilegedPermission("isIccLockEnabled");
8396
8397 // Now that all security checks passes, perform the operation as ourselves.
8398 final long identity = Binder.clearCallingIdentity();
8399 try {
8400 Phone phone = getPhone(subId);
8401 if (phone != null && phone.getIccCard() != null) {
8402 return phone.getIccCard().getIccLockEnabled();
8403 } else {
8404 return false;
8405 }
8406 } finally {
8407 Binder.restoreCallingIdentity(identity);
8408 }
8409 }
8410
8411 /**
8412 * Set the ICC pin lock enabled or disabled..
8413 *
8414 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8415 * 0 or a positive integer as the attempts remaining value.
8416 *
8417 */
8418 @Override
8419 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8420 enforceModifyPermission();
8421
8422 Phone phone = getPhone(subId);
8423 if (phone == null) {
8424 return 0;
8425 }
8426 // Now that all security checks passes, perform the operation as ourselves.
8427 final long identity = Binder.clearCallingIdentity();
8428 try {
8429 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8430 new Pair<Boolean, String>(enabled, password), phone, null);
8431 return attemptsRemaining;
8432
8433 } catch (Exception e) {
8434 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8435 } finally {
8436 Binder.restoreCallingIdentity(identity);
8437 }
8438 return 0;
8439 }
8440
8441 /**
8442 * Change the ICC password used in ICC pin lock.
8443 *
8444 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8445 * 0 or a positive integer as the attempts remaining value.
8446 *
8447 */
8448 @Override
8449 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8450 enforceModifyPermission();
8451
8452 Phone phone = getPhone(subId);
8453 if (phone == null) {
8454 return 0;
8455 }
8456 // Now that all security checks passes, perform the operation as ourselves.
8457 final long identity = Binder.clearCallingIdentity();
8458 try {
8459 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8460 new Pair<String, String>(oldPassword, newPassword), phone, null);
8461 return attemptsRemaining;
8462
8463 } catch (Exception e) {
8464 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8465 } finally {
8466 Binder.restoreCallingIdentity(identity);
8467 }
8468 return 0;
8469 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008470
8471 @Override
8472 public boolean canConnectTo5GInDsdsMode() {
8473 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8474 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008475}