blob: 05bb96ab07c5242574dfc40c40b38d2c40952615 [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
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001932 /**
1933 * This method has been removed due to privacy and stability concerns.
1934 */
1935 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001937 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
1938 return;
Wink Saville36469e72014-06-11 15:17:00 -07001939 }
1940
Nathan Harold1f889d82020-06-04 17:05:26 -07001941 @Override
1942 public void updateServiceLocationWithPackageName(String callingPackage) {
1943 mApp.getSystemService(AppOpsManager.class)
1944 .checkPackage(Binder.getCallingUid(), callingPackage);
1945
1946 final int targetSdk = getTargetSdk(callingPackage);
1947 if (targetSdk > android.os.Build.VERSION_CODES.R) {
1948 // Callers targeting S have no business invoking this method.
1949 return;
1950 }
1951
1952 LocationAccessPolicy.LocationPermissionResult locationResult =
1953 LocationAccessPolicy.checkLocationPermission(mApp,
1954 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1955 .setCallingPackage(callingPackage)
1956 .setCallingFeatureId(null)
1957 .setCallingPid(Binder.getCallingPid())
1958 .setCallingUid(Binder.getCallingUid())
1959 .setMethod("updateServiceLocation")
1960 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
1961 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1962 .build());
1963 // Apps that lack location permission have no business calling this method;
1964 // however, because no permission was declared in the public API, denials must
1965 // all be "soft".
1966 switch (locationResult) {
1967 case DENIED_HARD: /* fall through */
1968 case DENIED_SOFT:
1969 return;
1970 }
1971
1972 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001973 final long identity = Binder.clearCallingIdentity();
1974 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07001975 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001976 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07001977 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001978 }
1979 } finally {
1980 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 }
1983
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001984 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001985 @Override
1986 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001987 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001988 }
1989
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001990 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001991 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1992 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1993 callingFeatureId);
1994 }
1995
1996 @Deprecated
1997 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001998 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001999 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2000 }
2001
2002 @Override
2003 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2004 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002005 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002006 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002007 return false;
2008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002009
2010 final long identity = Binder.clearCallingIdentity();
2011 try {
2012 return isRadioOnForSubscriber(subId);
2013 } finally {
2014 Binder.restoreCallingIdentity(identity);
2015 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002016 }
2017
2018 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002019 final long identity = Binder.clearCallingIdentity();
2020 try {
2021 final Phone phone = getPhone(subId);
2022 if (phone != null) {
2023 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2024 } else {
2025 return false;
2026 }
2027 } finally {
2028 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 }
2031
2032 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002033 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 }
Wink Saville36469e72014-06-11 15:17:00 -07002035
Wink Savilleb564aae2014-10-23 10:18:09 -07002036 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002037 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002038
2039 final long identity = Binder.clearCallingIdentity();
2040 try {
2041 final Phone phone = getPhone(subId);
2042 if (phone != null) {
2043 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2044 }
2045 } finally {
2046 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002047 }
Wink Saville36469e72014-06-11 15:17:00 -07002048 }
2049
2050 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002051 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002052 }
2053
Wink Savilleb564aae2014-10-23 10:18:09 -07002054 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002055 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002056
2057 final long identity = Binder.clearCallingIdentity();
2058 try {
2059 final Phone phone = getPhone(subId);
2060 if (phone == null) {
2061 return false;
2062 }
2063 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2064 toggleRadioOnOffForSubscriber(subId);
2065 }
2066 return true;
2067 } finally {
2068 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002069 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002070 }
Wink Saville36469e72014-06-11 15:17:00 -07002071
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002072 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002073 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002074 /*
2075 * If any of the Radios are available, it will need to be
2076 * shutdown. So return true if any Radio is available.
2077 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 final long identity = Binder.clearCallingIdentity();
2079 try {
2080 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2081 Phone phone = PhoneFactory.getPhone(i);
2082 if (phone != null && phone.isRadioAvailable()) return true;
2083 }
2084 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2085 return false;
2086 } finally {
2087 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002088 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002089 }
2090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002091 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002092 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002093 enforceModifyPermission();
2094
2095 final long identity = Binder.clearCallingIdentity();
2096 try {
2097 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2098 logv("Shutting down Phone " + i);
2099 shutdownRadioUsingPhoneId(i);
2100 }
2101 } finally {
2102 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002103 }
2104 }
2105
2106 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002107 Phone phone = PhoneFactory.getPhone(phoneId);
2108 if (phone != null && phone.isRadioAvailable()) {
2109 phone.shutdownRadio();
2110 }
2111 }
2112
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002114 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002115
2116 final long identity = Binder.clearCallingIdentity();
2117 try {
2118 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2119 if (defaultPhone != null) {
2120 defaultPhone.setRadioPower(turnOn);
2121 return true;
2122 } else {
2123 loge("There's no default phone.");
2124 return false;
2125 }
2126 } finally {
2127 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002128 }
Wink Saville36469e72014-06-11 15:17:00 -07002129 }
2130
Wink Savilleb564aae2014-10-23 10:18:09 -07002131 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002133
2134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 final Phone phone = getPhone(subId);
2137 if (phone != null) {
2138 phone.setRadioPower(turnOn);
2139 return true;
2140 } else {
2141 return false;
2142 }
2143 } finally {
2144 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002145 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146 }
2147
Wink Saville36469e72014-06-11 15:17:00 -07002148 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002149 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 public boolean enableDataConnectivity() {
2151 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002152
2153 final long identity = Binder.clearCallingIdentity();
2154 try {
2155 int subId = mSubscriptionController.getDefaultDataSubId();
2156 final Phone phone = getPhone(subId);
2157 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002158 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002159 return true;
2160 } else {
2161 return false;
2162 }
2163 } finally {
2164 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
2167
Wink Saville36469e72014-06-11 15:17:00 -07002168 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002169 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 public boolean disableDataConnectivity() {
2171 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002172
2173 final long identity = Binder.clearCallingIdentity();
2174 try {
2175 int subId = mSubscriptionController.getDefaultDataSubId();
2176 final Phone phone = getPhone(subId);
2177 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002178 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002179 return true;
2180 } else {
2181 return false;
2182 }
2183 } finally {
2184 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002185 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002186 }
2187
Sanket Padawe356d7632015-06-22 14:03:32 -07002188 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002189 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002190 final long identity = Binder.clearCallingIdentity();
2191 try {
2192 final Phone phone = getPhone(subId);
2193 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002194 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002195 } else {
2196 return false;
2197 }
2198 } finally {
2199 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 }
2202
2203 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002204 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002205 }
2206
pkanwarae03a6b2016-11-06 20:37:09 -08002207 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002208 enforceCallPermission();
2209
2210 final long identity = Binder.clearCallingIdentity();
2211 try {
2212 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2213 return;
2214 }
2215 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2216 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2217 } finally {
2218 Binder.restoreCallingIdentity(identity);
2219 }
pkanwar32d516d2016-10-14 19:37:38 -07002220 };
2221
Wink Savilleb564aae2014-10-23 10:18:09 -07002222 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002224
2225 final long identity = Binder.clearCallingIdentity();
2226 try {
2227 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2228 return false;
2229 }
2230 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2231 } finally {
2232 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002233 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 }
2235
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002237 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002238 }
2239
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002240 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002241 final long identity = Binder.clearCallingIdentity();
2242 try {
2243 Phone phone = PhoneFactory.getPhone(slotIndex);
2244 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2245 PhoneConstantConversions.convertCallState(phone.getState());
2246 } finally {
2247 Binder.restoreCallingIdentity(identity);
2248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 }
2250
Sanket Padawe356d7632015-06-22 14:03:32 -07002251 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002252 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002253 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2254 }
2255
2256 @Override
2257 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002258 final long identity = Binder.clearCallingIdentity();
2259 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002260 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002261 if (phone != null) {
2262 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2263 } else {
2264 return PhoneConstantConversions.convertDataState(
2265 PhoneConstants.DataState.DISCONNECTED);
2266 }
2267 } finally {
2268 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 }
2271
Sanket Padawe356d7632015-06-22 14:03:32 -07002272 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002273 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002274 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2275 }
2276
2277 @Override
2278 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002279 final long identity = Binder.clearCallingIdentity();
2280 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002281 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002282 if (phone != null) {
2283 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2284 } else {
2285 return TelephonyManager.DATA_ACTIVITY_NONE;
2286 }
2287 } finally {
2288 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290 }
2291
2292 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002293 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002294 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002295 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002296
2297 LocationAccessPolicy.LocationPermissionResult locationResult =
2298 LocationAccessPolicy.checkLocationPermission(mApp,
2299 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2300 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002301 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002302 .setCallingPid(Binder.getCallingPid())
2303 .setCallingUid(Binder.getCallingUid())
2304 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002305 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002306 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2307 .build());
2308 switch (locationResult) {
2309 case DENIED_HARD:
2310 throw new SecurityException("Not allowed to access cell location");
2311 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002312 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2313 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 }
2315
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002316 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002317 final long identity = Binder.clearCallingIdentity();
2318 try {
2319 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002320 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002321 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002322 } finally {
2323 Binder.restoreCallingIdentity(identity);
2324 }
Svetoslav64fad262015-04-14 14:35:21 -07002325 }
2326
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 @Override
Jack Yu01425032020-02-22 19:38:58 -08002328 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002329 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2330 // registered cell info, so return a NULL country instead.
2331 final long identity = Binder.clearCallingIdentity();
2332 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002333 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2334 // Get default phone in this case.
2335 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2336 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002337 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002338 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002339 if (phone == null) return "";
2340 ServiceStateTracker sst = phone.getServiceStateTracker();
2341 if (sst == null) return "";
2342 LocaleTracker lt = sst.getLocaleTracker();
2343 if (lt == null) return "";
2344 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2345 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2346 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002347 } finally {
2348 Binder.restoreCallingIdentity(identity);
2349 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002350 }
2351
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002352 /**
2353 * This method was removed due to potential issues caused by performing partial
2354 * updates of service state, and lack of a credible use case.
2355 *
2356 * This has the ability to break the telephony implementation by disabling notification of
2357 * changes in device connectivity. DO NOT USE THIS!
2358 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002359 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 public void enableLocationUpdates() {
2361 mApp.enforceCallingOrSelfPermission(
2362 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 }
2364
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002365 /**
2366 * This method was removed due to potential issues caused by performing partial
2367 * updates of service state, and lack of a credible use case.
2368 *
2369 * This has the ability to break the telephony implementation by disabling notification of
2370 * changes in device connectivity. DO NOT USE THIS!
2371 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 @Override
2373 public void disableLocationUpdates() {
2374 mApp.enforceCallingOrSelfPermission(
2375 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 }
2377
Nathan Harold31d7ff32018-10-15 20:20:30 -07002378 /**
2379 * Returns the target SDK version number for a given package name.
2380 *
Nathan Haroldec184742019-07-10 17:04:16 -07002381 * This call MUST be invoked before clearing the calling UID.
2382 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002383 * @return target SDK if the package is found or INT_MAX.
2384 */
2385 private int getTargetSdk(String packageName) {
2386 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002387 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002388 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002389 if (ai != null) return ai.targetSdkVersion;
2390 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002391 loge("Failed to get package info for pkg="
2392 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002393 }
2394 return Integer.MAX_VALUE;
2395 }
2396
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 @Override
2398 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002399 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2400 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002401 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002402 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2403 throw new SecurityException(
2404 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2405 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002406
Jordan Liu1617b712019-07-10 15:06:26 -07002407 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2409 return null;
2410 }
Svetoslav64fad262015-04-14 14:35:21 -07002411
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002412 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002414 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002415 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416
Nathan Haroldf180aac2018-06-01 18:43:55 -07002417 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2418 for (CellInfo ci : info) {
2419 if (ci instanceof CellInfoGsm) {
2420 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2421 } else if (ci instanceof CellInfoWcdma) {
2422 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002425 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 }
2427
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002428 private List<CellInfo> getCachedCellInfo() {
2429 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2430 for (Phone phone : PhoneFactory.getPhones()) {
2431 List<CellInfo> info = phone.getAllCellInfo();
2432 if (info != null) cellInfos.addAll(info);
2433 }
2434 return cellInfos;
2435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436
2437 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002438 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002439 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002440 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002441
2442 LocationAccessPolicy.LocationPermissionResult locationResult =
2443 LocationAccessPolicy.checkLocationPermission(mApp,
2444 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2445 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002446 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002447 .setCallingPid(Binder.getCallingPid())
2448 .setCallingUid(Binder.getCallingUid())
2449 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002450 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002451 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2452 .build());
2453 switch (locationResult) {
2454 case DENIED_HARD:
2455 throw new SecurityException("Not allowed to access cell info");
2456 case DENIED_SOFT:
2457 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 }
2459
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002460 final int targetSdk = getTargetSdk(callingPackage);
2461 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2462 return getCachedCellInfo();
2463 }
2464
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002465 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002466 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002467 final long identity = Binder.clearCallingIdentity();
2468 try {
2469 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2470 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002471 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002472 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002473 if (info != null) cellInfos.addAll(info);
2474 }
2475 return cellInfos;
2476 } finally {
2477 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 }
2479 }
2480
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002481 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002482 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2483 String callingFeatureId) {
2484 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2485 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002486 }
2487
2488 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002489 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2490 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002491 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002492 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002493 }
2494
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002495 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2496 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002497 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002498 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002499
2500 LocationAccessPolicy.LocationPermissionResult locationResult =
2501 LocationAccessPolicy.checkLocationPermission(mApp,
2502 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2503 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002504 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002505 .setCallingPid(Binder.getCallingPid())
2506 .setCallingUid(Binder.getCallingUid())
2507 .setMethod("requestCellInfoUpdate")
2508 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2509 .build());
2510 switch (locationResult) {
2511 case DENIED_HARD:
2512 throw new SecurityException("Not allowed to access cell info");
2513 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002514 try {
2515 cb.onCellInfo(new ArrayList<CellInfo>());
2516 } catch (RemoteException re) {
2517 // Drop without consequences
2518 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002519 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002520 }
2521
Nathan Harolda939a962019-05-09 10:13:47 -07002522
2523 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002524 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2525
2526 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2527 }
2528
2529 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002530 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002531 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002532 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533
2534 final long identity = Binder.clearCallingIdentity();
2535 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002536 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002537 } finally {
2538 Binder.restoreCallingIdentity(identity);
2539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540 }
2541
Shishir Agrawala9f32182016-04-12 12:00:16 -07002542 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002543 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002544 Phone phone = PhoneFactory.getPhone(slotIndex);
2545 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002546 return null;
2547 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002548 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002549 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002550 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002551 return null;
2552 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002553
2554 final long identity = Binder.clearCallingIdentity();
2555 try {
2556 return phone.getImei();
2557 } finally {
2558 Binder.restoreCallingIdentity(identity);
2559 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002560 }
2561
2562 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002563 public String getTypeAllocationCodeForSlot(int slotIndex) {
2564 Phone phone = PhoneFactory.getPhone(slotIndex);
2565 String tac = null;
2566 if (phone != null) {
2567 String imei = phone.getImei();
2568 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2569 }
2570 return tac;
2571 }
2572
2573 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002574 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002575 Phone phone = PhoneFactory.getPhone(slotIndex);
2576 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002577 return null;
2578 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002579
Jeff Davidson913390f2018-02-23 17:11:49 -08002580 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002581 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002582 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002583 return null;
2584 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002585
2586 final long identity = Binder.clearCallingIdentity();
2587 try {
2588 return phone.getMeid();
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
2591 }
Jack Yu2af8d712017-03-15 17:14:14 -07002592 }
2593
2594 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002595 public String getManufacturerCodeForSlot(int slotIndex) {
2596 Phone phone = PhoneFactory.getPhone(slotIndex);
2597 String manufacturerCode = null;
2598 if (phone != null) {
2599 String meid = phone.getMeid();
2600 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2601 }
2602 return manufacturerCode;
2603 }
2604
2605 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002606 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2607 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002608 Phone phone = PhoneFactory.getPhone(slotIndex);
2609 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002610 return null;
2611 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002612 int subId = phone.getSubId();
2613 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002614 mApp, subId, callingPackage, callingFeatureId,
2615 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002616 return null;
2617 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618
2619 final long identity = Binder.clearCallingIdentity();
2620 try {
2621 return phone.getDeviceSvn();
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
2624 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002625 }
2626
fionaxu43304da2017-11-27 22:51:16 -08002627 @Override
2628 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629 final long identity = Binder.clearCallingIdentity();
2630 try {
2631 final Phone phone = getPhone(subId);
2632 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
fionaxu43304da2017-11-27 22:51:16 -08002636 }
2637
2638 @Override
2639 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640 final long identity = Binder.clearCallingIdentity();
2641 try {
2642 final Phone phone = getPhone(subId);
2643 return phone == null ? null : phone.getCarrierName();
2644 } finally {
2645 Binder.restoreCallingIdentity(identity);
2646 }
fionaxu43304da2017-11-27 22:51:16 -08002647 }
2648
calvinpanffe225e2018-11-01 19:43:06 +08002649 @Override
chen xu0026ca62019-03-06 15:28:50 -08002650 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002651 final long identity = Binder.clearCallingIdentity();
2652 try {
2653 final Phone phone = getPhone(subId);
2654 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002655 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002656 } finally {
2657 Binder.restoreCallingIdentity(identity);
2658 }
2659 }
2660
2661 @Override
chen xu0026ca62019-03-06 15:28:50 -08002662 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002666 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002667 } finally {
2668 Binder.restoreCallingIdentity(identity);
2669 }
2670 }
2671
chen xu651eec72018-11-11 19:03:44 -08002672 @Override
chen xu864e11c2018-12-06 22:10:03 -08002673 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2674 if (!isSubscriptionMccMnc) {
2675 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2676 }
chen xu651eec72018-11-11 19:03:44 -08002677 final Phone phone = PhoneFactory.getPhone(slotIndex);
2678 if (phone == null) {
2679 return TelephonyManager.UNKNOWN_CARRIER_ID;
2680 }
2681 final long identity = Binder.clearCallingIdentity();
2682 try {
2683 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2684 } finally {
2685 Binder.restoreCallingIdentity(identity);
2686 }
2687 }
2688
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689 //
2690 // Internal helper methods.
2691 //
2692
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002693 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2695 *
2696 * @throws SecurityException if the caller does not have the required permission
2697 */
2698 private void enforceModifyPermission() {
2699 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2700 }
2701
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002702 /**
2703 * Make sure the caller is system.
2704 *
2705 * @throws SecurityException if the caller is not system.
2706 */
2707 private void enforceSystemCaller() {
2708 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2709 throw new SecurityException("Caller must be system");
2710 }
2711 }
2712
Shuo Qianf2b2df42019-11-13 17:43:31 -08002713 private void enforceActiveEmergencySessionPermission() {
2714 mApp.enforceCallingOrSelfPermission(
2715 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2716 }
2717
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 /**
2719 * Make sure the caller has the CALL_PHONE permission.
2720 *
2721 * @throws SecurityException if the caller does not have the required permission
2722 */
2723 private void enforceCallPermission() {
2724 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2725 }
2726
paulhu423b5f22019-08-23 19:17:33 +08002727 private void enforceSettingsPermission() {
2728 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002729 }
2730
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731 private String createTelUrl(String number) {
2732 if (TextUtils.isEmpty(number)) {
2733 return null;
2734 }
2735
Jake Hambye994d462014-02-03 13:10:13 -08002736 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737 }
2738
Ihab Awadf9e92732013-12-05 18:02:52 -08002739 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002740 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2741 }
2742
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002743 private static void logv(String msg) {
2744 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2745 }
2746
Ihab Awadf9e92732013-12-05 18:02:52 -08002747 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2749 }
2750
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002751 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002752 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002753 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002754 }
2755
Sanket Padawe356d7632015-06-22 14:03:32 -07002756 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002757 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758 final long identity = Binder.clearCallingIdentity();
2759 try {
2760 final Phone phone = PhoneFactory.getPhone(slotIndex);
2761 if (phone == null) {
2762 return PhoneConstants.PHONE_TYPE_NONE;
2763 } else {
2764 return phone.getPhoneType();
2765 }
2766 } finally {
2767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 }
2770
2771 /**
2772 * Returns the CDMA ERI icon index to display
2773 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002774 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002775 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2776 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2777 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002778 }
2779
Sanket Padawe356d7632015-06-22 14:03:32 -07002780 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002781 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2782 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002784 mApp, subId, callingPackage, callingFeatureId,
2785 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002786 return -1;
2787 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788
2789 final long identity = Binder.clearCallingIdentity();
2790 try {
2791 final Phone phone = getPhone(subId);
2792 if (phone != null) {
2793 return phone.getCdmaEriIconIndex();
2794 } else {
2795 return -1;
2796 }
2797 } finally {
2798 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002799 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002800 }
2801
2802 /**
2803 * Returns the CDMA ERI icon mode,
2804 * 0 - ON
2805 * 1 - FLASHING
2806 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002807 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002808 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2809 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2810 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002811 }
2812
Sanket Padawe356d7632015-06-22 14:03:32 -07002813 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002814 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2815 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002816 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002817 mApp, subId, callingPackage, callingFeatureId,
2818 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002819 return -1;
2820 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821
2822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 final Phone phone = getPhone(subId);
2825 if (phone != null) {
2826 return phone.getCdmaEriIconMode();
2827 } else {
2828 return -1;
2829 }
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002832 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002833 }
2834
2835 /**
2836 * Returns the CDMA ERI text,
2837 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002838 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002839 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2840 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2841 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002842 }
2843
Sanket Padawe356d7632015-06-22 14:03:32 -07002844 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002845 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2846 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002847 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002848 mApp, subId, callingPackage, callingFeatureId,
2849 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002850 return null;
2851 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852
2853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 final Phone phone = getPhone(subId);
2856 if (phone != null) {
2857 return phone.getCdmaEriText();
2858 } else {
2859 return null;
2860 }
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002863 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002864 }
2865
2866 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002867 * Returns the CDMA MDN.
2868 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002869 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002870 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2872 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002873
2874 final long identity = Binder.clearCallingIdentity();
2875 try {
2876 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002877 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878 return phone.getLine1Number();
2879 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002880 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881 return null;
2882 }
2883 } finally {
2884 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002885 }
2886 }
2887
2888 /**
2889 * Returns the CDMA MIN.
2890 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002891 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002892 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2894 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002895
2896 final long identity = Binder.clearCallingIdentity();
2897 try {
2898 final Phone phone = getPhone(subId);
2899 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2900 return phone.getCdmaMin();
2901 } else {
2902 return null;
2903 }
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002906 }
2907 }
2908
Hall Liud892bec2018-11-30 14:51:45 -08002909 @Override
2910 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2911 INumberVerificationCallback callback, String callingPackage) {
2912 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2913 != PERMISSION_GRANTED) {
2914 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2915 }
2916 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2917
2918 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2919 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2920 throw new SecurityException("Calling package must be configured in the device config");
2921 }
2922
2923 if (range == null) {
2924 throw new NullPointerException("Range must be non-null");
2925 }
2926
2927 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002928 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002929
2930 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2931 }
2932
Junda Liuca05d5d2014-08-14 22:36:34 -07002933 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002934 * Returns true if CDMA provisioning needs to run.
2935 */
2936 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 final long identity = Binder.clearCallingIdentity();
2938 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002939 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002940 } finally {
2941 Binder.restoreCallingIdentity(identity);
2942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002943 }
2944
2945 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002946 * Sets the voice mail number of a given subId.
2947 */
2948 @Override
2949 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002950 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2951 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002952
2953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2956 new Pair<String, String>(alphaTag, number), new Integer(subId));
2957 return success;
2958 } finally {
2959 Binder.restoreCallingIdentity(identity);
2960 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002961 }
2962
Ta-wei Yen87c49842016-05-13 21:19:52 -07002963 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002964 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2965 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002966 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2967 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002968 if (!TextUtils.equals(callingPackage, systemDialer)) {
2969 throw new SecurityException("caller must be system dialer");
2970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002971
2972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2975 if (phoneAccountHandle == null) {
2976 return null;
2977 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002978 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979 } finally {
2980 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002981 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002982 }
2983
2984 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002985 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2986 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002987 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002988 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002989 mApp, subId, callingPackage, callingFeatureId,
2990 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002991 return null;
2992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002993
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002994 final long identity = Binder.clearCallingIdentity();
2995 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002996 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002997 } finally {
2998 Binder.restoreCallingIdentity(identity);
2999 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003000 }
3001
3002 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003003 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3004 VisualVoicemailSmsFilterSettings settings) {
3005 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006
3007 final long identity = Binder.clearCallingIdentity();
3008 try {
3009 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003010 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003014 }
3015
3016 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003017 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3018 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019
3020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003023 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003027 }
3028
3029 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003030 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3031 String callingPackage, int subId) {
3032 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003033
3034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003037 mApp, callingPackage, subId);
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 Yen30a69c82016-12-27 14:52:32 -08003044 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003045 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003046
3047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003050 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051 } finally {
3052 Binder.restoreCallingIdentity(identity);
3053 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003054 }
3055
3056 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003057 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3058 String callingAttributionTag, int subId, String number, int port, String text,
3059 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003060 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003061 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003062 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003063 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003064 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3065 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003066 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003067
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003068 /**
fionaxu0152e512016-11-14 13:36:14 -08003069 * Sets the voice activation state of a given subId.
3070 */
3071 @Override
3072 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3074 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003075
3076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 final Phone phone = getPhone(subId);
3079 if (phone != null) {
3080 phone.setVoiceActivationState(activationState);
3081 } else {
3082 loge("setVoiceActivationState fails with invalid subId: " + subId);
3083 }
3084 } finally {
3085 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003086 }
3087 }
3088
3089 /**
3090 * Sets the data activation state of a given subId.
3091 */
3092 @Override
3093 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3095 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003096
3097 final long identity = Binder.clearCallingIdentity();
3098 try {
3099 final Phone phone = getPhone(subId);
3100 if (phone != null) {
3101 phone.setDataActivationState(activationState);
3102 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003103 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003104 }
3105 } finally {
3106 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003107 }
3108 }
3109
3110 /**
3111 * Returns the voice activation state of a given subId.
3112 */
3113 @Override
3114 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003115 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116
fionaxu0152e512016-11-14 13:36:14 -08003117 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 if (phone != null) {
3121 return phone.getVoiceActivationState();
3122 } else {
3123 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3124 }
3125 } finally {
3126 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003127 }
3128 }
3129
3130 /**
3131 * Returns the data activation state of a given subId.
3132 */
3133 @Override
3134 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003135 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003136
fionaxu0152e512016-11-14 13:36:14 -08003137 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138 final long identity = Binder.clearCallingIdentity();
3139 try {
3140 if (phone != null) {
3141 return phone.getDataActivationState();
3142 } else {
3143 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3144 }
3145 } finally {
3146 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003147 }
3148 }
3149
3150 /**
Wink Saville36469e72014-06-11 15:17:00 -07003151 * Returns the unread count of voicemails for a subId
3152 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003153 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003154 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3155 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003157 mApp, subId, callingPackage, callingFeatureId,
3158 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003159 return 0;
3160 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003161 final long identity = Binder.clearCallingIdentity();
3162 try {
3163 final Phone phone = getPhone(subId);
3164 if (phone != null) {
3165 return phone.getVoiceMessageCount();
3166 } else {
3167 return 0;
3168 }
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003172 }
3173
3174 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003175 * returns true, if the device is in a state where both voice and data
3176 * are supported simultaneously. This can change based on location or network condition.
3177 */
3178 @Override
3179 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003180 final long identity = Binder.clearCallingIdentity();
3181 try {
3182 final Phone phone = getPhone(subId);
3183 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3184 } finally {
3185 Binder.restoreCallingIdentity(identity);
3186 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003187 }
3188
3189 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003190 * Send the dialer code if called from the current default dialer or the caller has
3191 * carrier privilege.
3192 * @param inputCode The dialer code to send
3193 */
3194 @Override
3195 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003196 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003197 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003198 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3199 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003200 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003201 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003202 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204
3205 final long identity = Binder.clearCallingIdentity();
3206 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003207 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003208 } finally {
3209 Binder.restoreCallingIdentity(identity);
3210 }
fionaxu235cc5e2017-03-06 22:25:57 -08003211 }
3212
Pengquan Menga1bb6272018-09-06 09:59:22 -07003213 @Override
3214 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003215 TelephonyPermissions
3216 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3217 mApp, subId, "getNetworkSelectionMode");
3218 final long identity = Binder.clearCallingIdentity();
3219 try {
3220 if (!isActiveSubscription(subId)) {
3221 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3222 }
3223 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3224 } finally {
3225 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003226 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003227 }
3228
Brad Ebinger35c841c2018-10-01 10:40:55 -07003229 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003230 public boolean isInEmergencySmsMode() {
3231 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3232 final long identity = Binder.clearCallingIdentity();
3233 try {
3234 for (Phone phone : PhoneFactory.getPhones()) {
3235 if (phone.isInEmergencySmsMode()) {
3236 return true;
3237 }
3238 }
3239 } finally {
3240 Binder.restoreCallingIdentity(identity);
3241 }
3242 return false;
3243 }
3244
shilu366312e2019-12-17 09:28:10 -08003245 /**
3246 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3247 * @param subId The subscription to use to check the configuration.
3248 * @param c The callback that will be used to send the result.
3249 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003250 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003251 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3252 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003253 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3254 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003255
Brad Ebinger77b832e2019-10-17 17:03:22 -07003256 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3257 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3258 "IMS not available on device.");
3259 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003260 final long token = Binder.clearCallingIdentity();
3261 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003262 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003263 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003264 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003265 } catch (ImsException e) {
3266 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003267 } finally {
3268 Binder.restoreCallingIdentity(token);
3269 }
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 Ebinger35c841c2018-10-01 10:40:55 -07003277 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003278 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003279 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3280 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003281 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3282 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3283 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003284 final long token = Binder.clearCallingIdentity();
3285 try {
3286 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3287 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3288 .removeRegistrationCallbackForSubscription(c, subId);
3289 } catch (ImsException e) {
3290 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3291 + "is inactive, ignoring unregister.");
3292 // If the subscription is no longer active, just return, since the callback
3293 // will already have been removed internally.
3294 } finally {
3295 Binder.restoreCallingIdentity(token);
3296 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003297 }
3298
Brad Ebinger774ba362019-10-22 17:36:18 -07003299 /**
3300 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3301 */
3302 @Override
3303 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3304 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3305 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3306 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3307 "IMS not available on device.");
3308 }
3309 final long token = Binder.clearCallingIdentity();
3310 try {
3311 Phone phone = getPhone(subId);
3312 if (phone == null) {
3313 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3314 + subId + "'");
3315 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3316 }
3317 phone.getImsRegistrationState(regState -> {
3318 try {
3319 consumer.accept((regState == null)
3320 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3321 } catch (RemoteException e) {
3322 // Ignore if the remote process is no longer available to call back.
3323 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3324 }
3325 });
3326 } finally {
3327 Binder.restoreCallingIdentity(token);
3328 }
3329 }
3330
3331 /**
3332 * Get the transport type for the IMS service registration state.
3333 */
3334 @Override
3335 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003336 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3337 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003338 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3339 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3340 "IMS not available on device.");
3341 }
3342 final long token = Binder.clearCallingIdentity();
3343 try {
3344 Phone phone = getPhone(subId);
3345 if (phone == null) {
3346 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3347 + subId + "'");
3348 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3349 }
3350 phone.getImsRegistrationTech(regTech -> {
3351 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3352 int regTechConverted = (regTech == null)
3353 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3354 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3355 regTechConverted);
3356 try {
3357 consumer.accept(regTechConverted);
3358 } catch (RemoteException e) {
3359 // Ignore if the remote process is no longer available to call back.
3360 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3361 }
3362 });
3363 } finally {
3364 Binder.restoreCallingIdentity(token);
3365 }
3366 }
3367
shilu366312e2019-12-17 09:28:10 -08003368 /**
3369 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3370 * @param subId The subscription to use to check the configuration.
3371 * @param c The callback that will be used to send the result.
3372 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003373 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003374 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3375 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003376 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3377 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003378 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3379 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3380 "IMS not available on device.");
3381 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003382 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3383 final long token = Binder.clearCallingIdentity();
3384 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003385 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003386 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003387 } catch (ImsException e) {
3388 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003389 } finally {
3390 Binder.restoreCallingIdentity(token);
3391 }
3392 }
3393
shilu366312e2019-12-17 09:28:10 -08003394 /**
3395 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3396 * @param subId The subscription to use to check the configuration.
3397 * @param c The callback that will be used to send the result.
3398 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003399 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003400 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003401 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3402 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003403 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3404 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3405 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003406
3407 final long token = Binder.clearCallingIdentity();
3408 try {
3409 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3410 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003411 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003412 } catch (ImsException e) {
3413 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3414 + "is inactive, ignoring unregister.");
3415 // If the subscription is no longer active, just return, since the callback
3416 // will already have been removed internally.
3417 } finally {
3418 Binder.restoreCallingIdentity(token);
3419 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003420 }
3421
3422 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003423 public boolean isCapable(int subId, int capability, int regTech) {
3424 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003425 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3426 final long token = Binder.clearCallingIdentity();
3427 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003428 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003429 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003430 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003431 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3432 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003433 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003434 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3435 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003436 } finally {
3437 Binder.restoreCallingIdentity(token);
3438 }
3439 }
3440
3441 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003442 public boolean isAvailable(int subId, int capability, int regTech) {
3443 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003444 final long token = Binder.clearCallingIdentity();
3445 try {
3446 Phone phone = getPhone(subId);
3447 if (phone == null) return false;
3448 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003449 } catch (com.android.ims.ImsException e) {
3450 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3451 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003452 } finally {
3453 Binder.restoreCallingIdentity(token);
3454 }
3455 }
3456
Brad Ebinger77b832e2019-10-17 17:03:22 -07003457 /**
3458 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3459 * subscription.
3460 * @param subId The subscription to use to check the configuration.
3461 * @param callback The callback that will be used to send the result.
3462 * @param capability The MmTelFeature capability that will be used to send the result.
3463 * @param transportType The transport type of the MmTelFeature capability.
3464 */
3465 @Override
3466 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3467 int transportType) {
3468 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3469 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3470 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3471 "IMS not available on device.");
3472 }
3473 final long token = Binder.clearCallingIdentity();
3474 try {
3475 int slotId = getSlotIndex(subId);
3476 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3477 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3478 + subId + "'");
3479 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3480 }
3481 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3482 transportType, aBoolean -> {
3483 try {
3484 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3485 } catch (RemoteException e) {
3486 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3487 + "running. Ignore");
3488 }
3489 });
3490 } finally {
3491 Binder.restoreCallingIdentity(token);
3492 }
3493 }
3494
shilu366312e2019-12-17 09:28:10 -08003495 /**
3496 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3497 * @param subId The subscription to use to check the configuration.
3498 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003499 @Override
3500 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003501 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3502 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003503
Brad Ebinger35c841c2018-10-01 10:40:55 -07003504 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3505 final long token = Binder.clearCallingIdentity();
3506 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003507 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003508 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003509 } catch (ImsException e) {
3510 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003511 } finally {
3512 Binder.restoreCallingIdentity(token);
3513 }
3514 }
3515
3516 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003517 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003518 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003519 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003520 final long identity = Binder.clearCallingIdentity();
3521 try {
3522 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003523 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003524 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003525 } catch (ImsException e) {
3526 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
3530 }
3531
shilu366312e2019-12-17 09:28:10 -08003532 /**
3533 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3534 * @param subId The subscription to use to check the configuration.
3535 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003536 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003537 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003538 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3539 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003540 final long identity = Binder.clearCallingIdentity();
3541 try {
3542 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003543 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3544 } catch (ImsException e) {
3545 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003546 } finally {
3547 Binder.restoreCallingIdentity(identity);
3548 }
3549 }
3550
3551 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003552 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003554 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003558 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003559 } catch (ImsException e) {
3560 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003561 } finally {
3562 Binder.restoreCallingIdentity(identity);
3563 }
3564 }
3565
shilu366312e2019-12-17 09:28:10 -08003566 /**
3567 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3568 * @param subId The subscription to use to check the configuration.
3569 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003570 @Override
3571 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003572 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3573 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003577 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003578 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003579 } catch (ImsException e) {
3580 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003581 } finally {
3582 Binder.restoreCallingIdentity(identity);
3583 }
3584 }
3585
3586 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003587 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003589 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003590 final long identity = Binder.clearCallingIdentity();
3591 try {
3592 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003593 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003594 } catch (ImsException e) {
3595 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 } finally {
3597 Binder.restoreCallingIdentity(identity);
3598 }
3599 }
3600
shilu366312e2019-12-17 09:28:10 -08003601 /**
3602 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3603 * @param subId The subscription to use to check the configuration.
3604 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003605 @Override
3606 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003607 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3608 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003612 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003613 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003614 } catch (ImsException e) {
3615 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003616 } finally {
3617 Binder.restoreCallingIdentity(identity);
3618 }
3619 }
3620
3621 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003622 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003623 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003624 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003625 final long identity = Binder.clearCallingIdentity();
3626 try {
3627 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003628 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003629 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003630 } catch (ImsException e) {
3631 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003632 } finally {
3633 Binder.restoreCallingIdentity(identity);
3634 }
3635 }
3636
3637 @Override
3638 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3640 "setVoWiFiNonPersistent");
3641 final long identity = Binder.clearCallingIdentity();
3642 try {
3643 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003644 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003645 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003646 } catch (ImsException e) {
3647 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003648 } finally {
3649 Binder.restoreCallingIdentity(identity);
3650 }
3651 }
3652
shilu366312e2019-12-17 09:28:10 -08003653 /**
3654 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3655 * @param subId The subscription to use to check the configuration.
3656 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003657 @Override
3658 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003659 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3660 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003661 final long identity = Binder.clearCallingIdentity();
3662 try {
3663 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003664 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003665 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003666 } catch (ImsException e) {
3667 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
3671 }
3672
3673 @Override
3674 public void setVoWiFiModeSetting(int subId, int mode) {
3675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3676 "setVoWiFiModeSetting");
3677 final long identity = Binder.clearCallingIdentity();
3678 try {
3679 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003680 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003681 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003682 } catch (ImsException e) {
3683 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003684 } finally {
3685 Binder.restoreCallingIdentity(identity);
3686 }
3687 }
3688
3689 @Override
3690 public int getVoWiFiRoamingModeSetting(int subId) {
3691 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3692 final long identity = Binder.clearCallingIdentity();
3693 try {
3694 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003695 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003696 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003697 } catch (ImsException e) {
3698 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003699 } finally {
3700 Binder.restoreCallingIdentity(identity);
3701 }
3702 }
3703
3704 @Override
3705 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3707 "setVoWiFiRoamingModeSetting");
3708 final long identity = Binder.clearCallingIdentity();
3709 try {
3710 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003711 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003712 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003713 } catch (ImsException e) {
3714 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003715 } finally {
3716 Binder.restoreCallingIdentity(identity);
3717 }
3718 }
3719
3720 @Override
3721 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3723 "setRttCapabilityEnabled");
3724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003727 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3728 } catch (ImsException e) {
3729 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003730 } finally {
3731 Binder.restoreCallingIdentity(identity);
3732 }
3733 }
3734
shilu366312e2019-12-17 09:28:10 -08003735 /**
3736 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3737 * @param subId The subscription to use to check the configuration.
3738 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003739 @Override
3740 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003741 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3742 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003746 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003748 } catch (ImsException e) {
3749 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003750 } finally {
3751 Binder.restoreCallingIdentity(identity);
3752 }
3753 }
3754
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003755 @Override
3756 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3757 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3758 final long identity = Binder.clearCallingIdentity();
3759 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003760 if (!isImsAvailableOnDevice()) {
3761 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3762 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003763 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003764 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003765 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003766 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003767 } catch (ImsException e) {
3768 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003769 } finally {
3770 Binder.restoreCallingIdentity(identity);
3771 }
3772 }
3773
3774 @Override
3775 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3776 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3777 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003778 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3779 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3780 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003781 try {
3782 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003783 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003784 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003785 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003786 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3787 + "is inactive, ignoring unregister.");
3788 // If the subscription is no longer active, just return, since the callback will already
3789 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003790 } finally {
3791 Binder.restoreCallingIdentity(identity);
3792 }
3793 }
3794
allenwtsu99c623b2020-01-03 18:24:23 +08003795
3796 private void checkModifyPhoneStatePermission(int subId, String message) {
3797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3798 message);
3799 }
3800
3801 private boolean isImsProvisioningRequired(int subId, int capability,
3802 boolean isMmtelCapability) {
3803 Phone phone = getPhone(subId);
3804 if (phone == null) {
3805 loge("phone instance null for subid " + subId);
3806 return false;
3807 }
3808 if (isMmtelCapability) {
3809 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3810 return false;
3811 }
3812 } else {
3813 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3814 return false;
3815 }
3816 }
3817 return true;
3818 }
3819
3820 @Override
3821 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3822 boolean isProvisioned) {
3823 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3824
3825 final long identity = Binder.clearCallingIdentity();
3826 try {
3827 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3828 if (!isImsProvisioningRequired(subId, capability, false)) {
3829 return;
3830 }
3831
3832 // this capability requires provisioning, route to the correct API.
3833 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3834 switch (capability) {
3835 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3836 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3837 ims.setEabProvisioned(isProvisioned);
3838 break;
3839 default: {
3840 throw new IllegalArgumentException("Tried to set provisioning for "
3841 + "rcs capability '" + capability + "', which does not require "
3842 + "provisioning.");
3843 }
3844 }
3845 } finally {
3846 Binder.restoreCallingIdentity(identity);
3847 }
3848
3849 }
3850
3851
3852 @Override
3853 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3854 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3855 final long identity = Binder.clearCallingIdentity();
3856 try {
3857 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3858 if (!isImsProvisioningRequired(subId, capability, false)) {
3859 return true;
3860 }
3861
3862 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3863 switch (capability) {
3864 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3865 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3866 return ims.isEabProvisionedOnDevice();
3867
3868 default: {
3869 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3870 + "capability '" + capability + "', which does not require "
3871 + "provisioning.");
3872 }
3873 }
3874
3875 } finally {
3876 Binder.restoreCallingIdentity(identity);
3877 }
3878 }
3879
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003880 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003881 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3882 boolean isProvisioned) {
3883 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3884 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3885 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3886 }
allenwtsu99c623b2020-01-03 18:24:23 +08003887 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003888 final long identity = Binder.clearCallingIdentity();
3889 try {
3890 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003891 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003892 return;
3893 }
3894
3895 // this capability requires provisioning, route to the correct API.
3896 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3897 switch (capability) {
3898 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3899 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3900 ims.setVolteProvisioned(isProvisioned);
3901 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3902 ims.setWfcProvisioned(isProvisioned);
3903 }
3904 break;
3905 }
3906 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3907 // There is currently no difference in VT provisioning type.
3908 ims.setVtProvisioned(isProvisioned);
3909 break;
3910 }
3911 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3912 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3913 // change the capability of the feature instead if needed.
3914 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3915 == isProvisioned) {
3916 // No change in provisioning.
3917 return;
3918 }
3919 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3920 try {
3921 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003922 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003923 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3924 + ", Exception" + e.getMessage());
3925 }
3926 break;
3927 }
3928 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003929 throw new IllegalArgumentException("Tried to set provisioning for "
3930 + "MmTel capability '" + capability + "', which does not require "
3931 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003932 }
3933 }
3934
3935 } finally {
3936 Binder.restoreCallingIdentity(identity);
3937 }
3938 }
3939
3940 @Override
3941 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3942 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3943 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3944 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3945 }
3946 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3947 final long identity = Binder.clearCallingIdentity();
3948 try {
3949 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003950 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003951 return true;
3952 }
3953
3954 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3955 switch (capability) {
3956 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3957 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3958 return ims.isVolteProvisionedOnDevice();
3959 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3960 return ims.isWfcProvisionedOnDevice();
3961 }
3962 // This should never happen, since we are checking tech above to make sure it
3963 // is either LTE or IWLAN.
3964 throw new IllegalArgumentException("Invalid radio technology for voice "
3965 + "capability.");
3966 }
3967 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3968 // There is currently no difference in VT provisioning type.
3969 return ims.isVtProvisionedOnDevice();
3970 }
3971 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3972 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3973 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3974 }
3975 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003976 throw new IllegalArgumentException(
3977 "Tried to get provisioning for MmTel capability '" + capability
3978 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003979 }
3980 }
3981
3982 } finally {
3983 Binder.restoreCallingIdentity(identity);
3984 }
3985 }
3986
3987 @Override
3988 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3989 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3990 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3991 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3992 }
3993 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3994 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3995 return (provisionedBits & capability) > 0;
3996 }
3997
3998 @Override
3999 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4000 boolean isProvisioned) {
4001 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4002 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4003 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4004 }
4005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4006 "setProvisioningStatusForCapability");
4007 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4008 // If the current provisioning status for capability already matches isProvisioned,
4009 // do nothing.
4010 if (((provisionedBits & capability) > 0) == isProvisioned) {
4011 return;
4012 }
4013 if (isProvisioned) {
4014 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4015 } else {
4016 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4017 }
4018 }
4019
4020 /**
4021 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4022 * technology. The bitfield should mirror the bitfield defined by
4023 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4024 */
4025 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4026 String key = getMmTelProvisioningKey(subId, tech);
4027 // Default is no capabilities are provisioned.
4028 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4029 }
4030
4031 /**
4032 * Sets the MmTel capability provisioning bitfield (defined by
4033 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4034 * technology specified.
4035 *
4036 * Note: This is a synchronous command and should not be called on UI thread.
4037 */
4038 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4039 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4040 String key = getMmTelProvisioningKey(subId, tech);
4041 editor.putInt(key, newField);
4042 editor.commit();
4043 }
4044
4045 private static String getMmTelProvisioningKey(int subId, int tech) {
4046 // resulting key is provision_ims_mmtel_{subId}_{tech}
4047 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4048 }
4049
4050 /**
4051 * Query CarrierConfig to see if the specified capability requires provisioning for the
4052 * carrier associated with the subscription id.
4053 */
4054 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4055 int capability) {
4056 CarrierConfigManager configManager = new CarrierConfigManager(context);
4057 PersistableBundle c = configManager.getConfigForSubId(subId);
4058 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004059 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004060 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4061 false);
4062 boolean requireVoiceVtProvisioning = c.getBoolean(
4063 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4064
4065 // First check to make sure that the capability requires provisioning.
4066 switch (capability) {
4067 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4068 // intentional fallthrough
4069 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4070 if (requireVoiceVtProvisioning) {
4071 // Voice and Video requires provisioning
4072 return true;
4073 }
4074 break;
4075 }
4076 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4077 if (requireUtProvisioning) {
4078 // UT requires provisioning
4079 return true;
4080 }
4081 break;
4082 }
4083 }
4084 return false;
4085 }
4086
allenwtsu99c623b2020-01-03 18:24:23 +08004087 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4088 int capability) {
4089 CarrierConfigManager configManager = new CarrierConfigManager(context);
4090 PersistableBundle c = configManager.getConfigForSubId(subId);
4091
4092 boolean requireRcsProvisioning = c.getBoolean(
4093 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4094
4095 // First check to make sure that the capability requires provisioning.
4096 switch (capability) {
4097 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4098 // intentional fallthrough
4099 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4100 if (requireRcsProvisioning) {
4101 // OPTION or PRESENCE requires provisioning
4102 return true;
4103 }
4104 break;
4105 }
4106 }
4107 return false;
4108 }
4109
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004110 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004111 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004112 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4113 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4114 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004115 enforceReadPrivilegedPermission("getImsProvisioningInt");
4116 final long identity = Binder.clearCallingIdentity();
4117 try {
4118 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004119 int slotId = getSlotIndex(subId);
4120 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4121 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4122 + subId + "' for key:" + key);
4123 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4124 }
4125 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004126 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004127 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4128 + subId + "' for key:" + key);
4129 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004130 } finally {
4131 Binder.restoreCallingIdentity(identity);
4132 }
4133 }
4134
4135 @Override
4136 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004137 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4138 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4139 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004140 enforceReadPrivilegedPermission("getImsProvisioningString");
4141 final long identity = Binder.clearCallingIdentity();
4142 try {
4143 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004144 int slotId = getSlotIndex(subId);
4145 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4146 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4147 + subId + "' for key:" + key);
4148 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4149 }
4150 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004151 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004152 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4153 + subId + "' for key:" + key);
4154 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004155 } finally {
4156 Binder.restoreCallingIdentity(identity);
4157 }
4158 }
4159
4160 @Override
4161 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004162 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4163 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4164 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4166 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004167 final long identity = Binder.clearCallingIdentity();
4168 try {
4169 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004170 int slotId = getSlotIndex(subId);
4171 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4172 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4173 + subId + "' for key:" + key);
4174 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4175 }
4176 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004177 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004178 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4179 + "' for key:" + key);
4180 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004181 } finally {
4182 Binder.restoreCallingIdentity(identity);
4183 }
4184 }
4185
4186 @Override
4187 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004188 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4189 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4190 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4192 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004193 final long identity = Binder.clearCallingIdentity();
4194 try {
4195 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004196 int slotId = getSlotIndex(subId);
4197 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4198 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4199 + subId + "' for key:" + key);
4200 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4201 }
4202 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004203 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004204 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4205 + "' for key:" + key);
4206 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004207 } finally {
4208 Binder.restoreCallingIdentity(identity);
4209 }
4210 }
4211
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004212 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 int slotId = SubscriptionManager.getSlotIndex(subId);
4214 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004215 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4216 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004217 }
4218 return slotId;
4219 }
4220
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004221 private int getSlotIndex(int subId) {
4222 int slotId = SubscriptionManager.getSlotIndex(subId);
4223 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4224 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4225 }
4226 return slotId;
4227 }
4228
Wink Saville36469e72014-06-11 15:17:00 -07004229 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004230 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004231 */
4232 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004233 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4234 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004235 final int targetSdk = getTargetSdk(callingPackage);
4236 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004237 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004238 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004239 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004240 mApp, subId, callingPackage, callingFeatureId,
4241 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004242 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4243 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004245 final long identity = Binder.clearCallingIdentity();
4246 try {
4247 final Phone phone = getPhone(subId);
4248 if (phone != null) {
4249 return phone.getServiceState().getDataNetworkType();
4250 } else {
4251 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4252 }
4253 } finally {
4254 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004256 }
4257
4258 /**
4259 * Returns the data network type
4260 */
4261 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004262 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4263 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4264 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004265 }
4266
4267 /**
4268 * Returns the data network type for a subId
4269 */
4270 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004271 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4272 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004273 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004274 mApp, subId, callingPackage, callingFeatureId,
4275 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004276 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4277 }
4278
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004279 final long identity = Binder.clearCallingIdentity();
4280 try {
4281 final Phone phone = getPhone(subId);
4282 if (phone != null) {
4283 return phone.getServiceState().getDataNetworkType();
4284 } else {
4285 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4286 }
4287 } finally {
4288 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004290 }
4291
4292 /**
Wink Saville36469e72014-06-11 15:17:00 -07004293 * Returns the Voice network type for a subId
4294 */
4295 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004296 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4297 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004298 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004299 mApp, subId, callingPackage, callingFeatureId,
4300 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004301 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4302 }
4303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004304 final long identity = Binder.clearCallingIdentity();
4305 try {
4306 final Phone phone = getPhone(subId);
4307 if (phone != null) {
4308 return phone.getServiceState().getVoiceNetworkType();
4309 } else {
4310 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4311 }
4312 } finally {
4313 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004315 }
4316
4317 /**
4318 * @return true if a ICC card is present
4319 */
4320 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004321 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004322 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4323 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004324 }
4325
4326 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004327 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004328 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004329 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004330 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004331 final long identity = Binder.clearCallingIdentity();
4332 try {
4333 final Phone phone = PhoneFactory.getPhone(slotIndex);
4334 if (phone != null) {
4335 return phone.getIccCard().hasIccCard();
4336 } else {
4337 return false;
4338 }
4339 } finally {
4340 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004342 }
4343
4344 /**
4345 * Return if the current radio is LTE on CDMA. This
4346 * is a tri-state return value as for a period of time
4347 * the mode may be unknown.
4348 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004349 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004350 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004351 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004352 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004353 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004354 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4355 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4356 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004357 }
4358
Sanket Padawe356d7632015-06-22 14:03:32 -07004359 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004360 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4361 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004362 try {
4363 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4364 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004365 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4366 }
4367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368 final long identity = Binder.clearCallingIdentity();
4369 try {
4370 final Phone phone = getPhone(subId);
4371 if (phone == null) {
4372 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4373 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004374 return TelephonyProperties.lte_on_cdma_device()
4375 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376 }
4377 } finally {
4378 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004379 }
Wink Saville36469e72014-06-11 15:17:00 -07004380 }
4381
Wink Saville36469e72014-06-11 15:17:00 -07004382 /**
4383 * {@hide}
4384 * Returns Default subId, 0 in the case of single standby.
4385 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004386 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004387 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004388 }
4389
Shishir Agrawala9f32182016-04-12 12:00:16 -07004390 private int getSlotForDefaultSubscription() {
4391 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4392 }
4393
Wink Savilleb564aae2014-10-23 10:18:09 -07004394 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004395 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004396 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004397
Pengquan Menge92a50d2018-09-21 15:54:48 -07004398 private boolean isActiveSubscription(int subId) {
4399 return mSubscriptionController.isActiveSubId(subId);
4400 }
4401
Ihab Awadf2177b72013-11-25 13:33:23 -08004402 /**
4403 * @see android.telephony.TelephonyManager.WifiCallingChoices
4404 */
4405 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406 final long identity = Binder.clearCallingIdentity();
4407 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004408 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4410 getWhenToMakeWifiCallsDefaultPreference());
4411 } finally {
4412 Binder.restoreCallingIdentity(identity);
4413 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004414 }
4415
4416 /**
4417 * @see android.telephony.TelephonyManager.WifiCallingChoices
4418 */
4419 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420 final long identity = Binder.clearCallingIdentity();
4421 try {
4422 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004423 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004424 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4425 } finally {
4426 Binder.restoreCallingIdentity(identity);
4427 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004428 }
4429
Sailesh Nepald1e68152013-12-12 19:08:02 -08004430 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004431 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004432 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004433 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004434
Jordan Liu4c733742019-02-28 12:03:40 -08004435 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4436 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4437 if (phoneId == -1) {
4438 throw new IllegalArgumentException("Given slot index: " + slotIndex
4439 + " does not correspond to an active phone");
4440 }
4441 return PhoneFactory.getPhone(phoneId);
4442 }
4443
Shishir Agrawal566b7612013-10-28 14:41:00 -07004444 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004445 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4446 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4448 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004450 if (DBG) {
4451 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4452 }
4453 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4454 p2);
4455 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004456
Jordan Liu4c733742019-02-28 12:03:40 -08004457
4458 @Override
4459 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4460 int slotIndex, String callingPackage, String aid, int p2) {
4461 enforceModifyPermission();
4462 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4463 if (DBG) {
4464 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4465 }
4466 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4467 callingPackage, aid, p2);
4468 }
4469
4470 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4471 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 final long identity = Binder.clearCallingIdentity();
4473 try {
4474 if (TextUtils.equals(ISDR_AID, aid)) {
4475 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004476 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4477 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 if (bestComponent == null
4479 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4480 loge("The calling package is not allowed to access ISD-R.");
4481 throw new SecurityException(
4482 "The calling package is not allowed to access ISD-R.");
4483 }
Derek Tan740e1672017-06-27 14:56:27 -07004484 }
Derek Tan740e1672017-06-27 14:56:27 -07004485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004486 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004487 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4488 null /* workSource */);
4489 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004490 return response;
4491 } finally {
4492 Binder.restoreCallingIdentity(identity);
4493 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004494 }
4495
4496 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004497 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4499 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004500 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4501 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4502 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004503
Jordan Liu4c733742019-02-28 12:03:40 -08004504 @Override
4505 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4506 enforceModifyPermission();
4507 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4508 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4509 channel);
4510 }
4511
4512 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004513 final long identity = Binder.clearCallingIdentity();
4514 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004515 if (channel < 0) {
4516 return false;
4517 }
Jordan Liu4c733742019-02-28 12:03:40 -08004518 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4519 null /* workSource */);
4520 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004521 return success;
4522 } finally {
4523 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004524 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004525 }
4526
4527 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004528 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004529 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4531 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004532 if (DBG) {
4533 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4534 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4535 + p3 + " data=" + data);
4536 }
4537 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4538 command, p1, p2, p3, data);
4539 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004540
Jordan Liu4c733742019-02-28 12:03:40 -08004541 @Override
4542 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4543 int command, int p1, int p2, int p3, String data) {
4544 enforceModifyPermission();
4545 if (DBG) {
4546 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4547 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4548 + p3 + " data=" + data);
4549 }
4550 return iccTransmitApduLogicalChannelWithPermission(
4551 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4552 data);
4553 }
4554
4555 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4556 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004557 final long identity = Binder.clearCallingIdentity();
4558 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004559 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004560 return "";
4561 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004563 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004564 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4565 null /* workSource */);
4566 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004567
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568 // Append the returned status code to the end of the response payload.
4569 String s = Integer.toHexString(
4570 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4571 if (response.payload != null) {
4572 s = IccUtils.bytesToHexString(response.payload) + s;
4573 }
4574 return s;
4575 } finally {
4576 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004577 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004578 }
Jake Hambye994d462014-02-03 13:10:13 -08004579
Evan Charltonc66da362014-05-16 14:06:40 -07004580 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004581 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4582 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4584 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004585 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004586 if (DBG) {
4587 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4588 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4589 }
4590 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4591 cla, command, p1, p2, p3, data);
4592 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004593
Jordan Liu4c733742019-02-28 12:03:40 -08004594 @Override
4595 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4596 int command, int p1, int p2, int p3, String data) {
4597 enforceModifyPermission();
4598 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4599 if (DBG) {
4600 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4601 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4602 + " data=" + data);
4603 }
4604
4605 return iccTransmitApduBasicChannelWithPermission(
4606 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4607 p2, p3, data);
4608 }
4609
4610 // open APDU basic channel assuming the caller has sufficient permissions
4611 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4612 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004613 final long identity = Binder.clearCallingIdentity();
4614 try {
4615 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4616 && TextUtils.equals(ISDR_AID, data)) {
4617 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004618 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4619 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004620 if (bestComponent == null
4621 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4622 loge("The calling package is not allowed to select ISD-R.");
4623 throw new SecurityException(
4624 "The calling package is not allowed to select ISD-R.");
4625 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004626 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004628 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004629 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4630 null /* workSource */);
4631 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004633 // Append the returned status code to the end of the response payload.
4634 String s = Integer.toHexString(
4635 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4636 if (response.payload != null) {
4637 s = IccUtils.bytesToHexString(response.payload) + s;
4638 }
4639 return s;
4640 } finally {
4641 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004642 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004643 }
4644
4645 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004646 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004647 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4649 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004650
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651 final long identity = Binder.clearCallingIdentity();
4652 try {
4653 if (DBG) {
4654 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4655 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4656 }
4657
4658 IccIoResult response =
4659 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4660 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4661 subId);
4662
4663 if (DBG) {
4664 log("Exchange SIM_IO [R]" + response);
4665 }
4666
4667 byte[] result = null;
4668 int length = 2;
4669 if (response.payload != null) {
4670 length = 2 + response.payload.length;
4671 result = new byte[length];
4672 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4673 } else {
4674 result = new byte[length];
4675 }
4676
4677 result[length - 1] = (byte) response.sw2;
4678 result[length - 2] = (byte) response.sw1;
4679 return result;
4680 } finally {
4681 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004682 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004683 }
4684
Nathan Haroldb3014052017-01-25 15:57:32 -08004685 /**
4686 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4687 * on a particular subscription
4688 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004689 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4690 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004691 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004692 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004693 return null;
4694 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004695
4696 final long identity = Binder.clearCallingIdentity();
4697 try {
4698 if (appType != TelephonyManager.APPTYPE_USIM
4699 && appType != TelephonyManager.APPTYPE_SIM) {
4700 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4701 return null;
4702 }
4703 Object response = sendRequest(
4704 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4705 if (response instanceof String[]) {
4706 return (String[]) response;
4707 }
yincheng zhaod698b842019-09-06 17:06:54 -07004708 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004709 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004710 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711 } finally {
4712 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004713 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004714 }
4715
yincheng zhaod698b842019-09-06 17:06:54 -07004716 /**
4717 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4718 * subscription.
4719 *
4720 * @param subId the id of the subscription.
4721 * @param appType the uicc app type, must be USIM or SIM.
4722 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4723 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004724 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004725 * @return number of fplmns that is successfully written to the SIM.
4726 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004727 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4728 String callingFeatureId) {
4729 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4730 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004731 if (DBG) logv("no permissions for setForbiddenplmns");
4732 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4733 }
4734 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4735 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4736 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4737 }
4738 if (fplmns == null) {
4739 throw new IllegalArgumentException("Fplmn List provided is null");
4740 }
4741 for (String fplmn : fplmns) {
4742 if (!CellIdentity.isValidPlmn(fplmn)) {
4743 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4744 }
4745 }
4746 final long identity = Binder.clearCallingIdentity();
4747 try {
4748 Object response = sendRequest(
4749 CMD_SET_FORBIDDEN_PLMNS,
4750 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4751 subId);
4752 return (int) response;
4753 } finally {
4754 Binder.restoreCallingIdentity(identity);
4755 }
4756 }
4757
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004758 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004759 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4761 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763 final long identity = Binder.clearCallingIdentity();
4764 try {
4765 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4766 if (response.payload == null) {
4767 return "";
4768 }
Evan Charltonc66da362014-05-16 14:06:40 -07004769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004770 // Append the returned status code to the end of the response payload.
4771 String s = Integer.toHexString(
4772 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4773 s = IccUtils.bytesToHexString(response.payload) + s;
4774 return s;
4775 } finally {
4776 Binder.restoreCallingIdentity(identity);
4777 }
Evan Charltonc66da362014-05-16 14:06:40 -07004778 }
4779
Jake Hambye994d462014-02-03 13:10:13 -08004780 /**
4781 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4782 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4783 *
4784 * @param itemID the ID of the item to read
4785 * @return the NV item as a String, or null on error.
4786 */
4787 @Override
4788 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004789 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4791 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792
4793 final long identity = Binder.clearCallingIdentity();
4794 try {
4795 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004796 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004797 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4798 return value;
4799 } finally {
4800 Binder.restoreCallingIdentity(identity);
4801 }
Jake Hambye994d462014-02-03 13:10:13 -08004802 }
4803
4804 /**
4805 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4806 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4807 *
4808 * @param itemID the ID of the item to read
4809 * @param itemValue the value to write, as a String
4810 * @return true on success; false on any failure
4811 */
4812 @Override
4813 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004814 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4816 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817
4818 final long identity = Binder.clearCallingIdentity();
4819 try {
4820 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4821 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004822 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004823 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4824 return success;
4825 } finally {
4826 Binder.restoreCallingIdentity(identity);
4827 }
Jake Hambye994d462014-02-03 13:10:13 -08004828 }
4829
4830 /**
4831 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4832 * Used for device configuration by some CDMA operators.
4833 *
4834 * @param preferredRoamingList byte array containing the new PRL
4835 * @return true on success; false on any failure
4836 */
4837 @Override
4838 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4840 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004841
4842 final long identity = Binder.clearCallingIdentity();
4843 try {
4844 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4845 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4846 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4847 return success;
4848 } finally {
4849 Binder.restoreCallingIdentity(identity);
4850 }
Jake Hambye994d462014-02-03 13:10:13 -08004851 }
4852
4853 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004854 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004855 * Used for device configuration by some CDMA operators.
4856 *
chen xu6dac5ab2018-10-26 17:39:23 -07004857 * @param slotIndex - device slot.
4858 *
Jake Hambye994d462014-02-03 13:10:13 -08004859 * @return true on success; false on any failure
4860 */
4861 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004862 public boolean resetModemConfig(int slotIndex) {
4863 Phone phone = PhoneFactory.getPhone(slotIndex);
4864 if (phone != null) {
4865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4866 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004867
chen xu6dac5ab2018-10-26 17:39:23 -07004868 final long identity = Binder.clearCallingIdentity();
4869 try {
4870 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4871 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4872 return success;
4873 } finally {
4874 Binder.restoreCallingIdentity(identity);
4875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004876 }
chen xu6dac5ab2018-10-26 17:39:23 -07004877 return false;
4878 }
4879
4880 /**
4881 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4882 *
4883 * @param slotIndex - device slot.
4884 *
4885 * @return true on success; false on any failure
4886 */
4887 @Override
4888 public boolean rebootModem(int slotIndex) {
4889 Phone phone = PhoneFactory.getPhone(slotIndex);
4890 if (phone != null) {
4891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4892 mApp, phone.getSubId(), "rebootModem");
4893
4894 final long identity = Binder.clearCallingIdentity();
4895 try {
4896 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4897 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4898 return success;
4899 } finally {
4900 Binder.restoreCallingIdentity(identity);
4901 }
4902 }
4903 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004904 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004905
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004906 public String[] getPcscfAddress(String apnType, String callingPackage,
4907 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004908 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004909 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4910 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004911 return new String[0];
4912 }
4913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914 final long identity = Binder.clearCallingIdentity();
4915 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004916 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917 } finally {
4918 Binder.restoreCallingIdentity(identity);
4919 }
Wink Saville36469e72014-06-11 15:17:00 -07004920 }
4921
Brad Ebinger51f743a2017-01-23 13:50:20 -08004922 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004923 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4924 * {@link #disableIms(int)}.
4925 * @param slotIndex device slot.
4926 */
4927 public void resetIms(int slotIndex) {
4928 enforceModifyPermission();
4929
4930 final long identity = Binder.clearCallingIdentity();
4931 try {
4932 if (mImsResolver == null) {
4933 // may happen if the does not support IMS.
4934 return;
4935 }
4936 mImsResolver.disableIms(slotIndex);
4937 mImsResolver.enableIms(slotIndex);
4938 } finally {
4939 Binder.restoreCallingIdentity(identity);
4940 }
4941 }
4942
4943 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004944 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4945 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004946 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004947 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004948 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949
4950 final long identity = Binder.clearCallingIdentity();
4951 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004952 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004953 // may happen if the device does not support IMS.
4954 return;
4955 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004956 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004957 } finally {
4958 Binder.restoreCallingIdentity(identity);
4959 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004960 }
4961
4962 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004963 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4964 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004965 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004966 public void disableIms(int slotId) {
4967 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968
4969 final long identity = Binder.clearCallingIdentity();
4970 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004971 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004972 // may happen if the device does not support IMS.
4973 return;
4974 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004975 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004976 } finally {
4977 Binder.restoreCallingIdentity(identity);
4978 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004979 }
4980
4981 /**
4982 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4983 * feature or {@link null} if the service is not available. If the feature is available, the
4984 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4985 */
4986 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004987 IImsServiceFeatureCallback callback) {
4988 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989
4990 final long identity = Binder.clearCallingIdentity();
4991 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004992 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004993 // may happen if the device does not support IMS.
4994 return null;
4995 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004996 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004997 } finally {
4998 Binder.restoreCallingIdentity(identity);
4999 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005000 }
5001
5002 /**
5003 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5004 * feature during emergency calling or {@link null} if the service is not available. If the
5005 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5006 * listener for feature updates.
5007 */
5008 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5009 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010
5011 final long identity = Binder.clearCallingIdentity();
5012 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005013 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005014 // may happen if the device does not support IMS.
5015 return null;
5016 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005017 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018 } finally {
5019 Binder.restoreCallingIdentity(identity);
5020 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005021 }
5022
Brad Ebinger5f64b052017-12-14 14:26:15 -08005023 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005024 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5025 */
5026 public void unregisterImsFeatureCallback(int slotId, int featureType,
5027 IImsServiceFeatureCallback callback) {
5028 enforceModifyPermission();
5029
5030 final long identity = Binder.clearCallingIdentity();
5031 try {
5032 if (mImsResolver == null) return;
5033 mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback);
5034 } finally {
5035 Binder.restoreCallingIdentity(identity);
5036 }
5037 }
5038
5039 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005040 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005041 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005042 */
5043 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5044 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045
5046 final long identity = Binder.clearCallingIdentity();
5047 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005048 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005049 // may happen if the device does not support IMS.
5050 return null;
5051 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005052 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005053 } finally {
5054 Binder.restoreCallingIdentity(identity);
5055 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005056 }
5057
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005058 /**
5059 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005060 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005061 */
5062 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5063 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005064
5065 final long identity = Binder.clearCallingIdentity();
5066 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005067 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005068 // may happen if the device does not support IMS.
5069 return null;
5070 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005071 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005072 } finally {
5073 Binder.restoreCallingIdentity(identity);
5074 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005075 }
5076
Brad Ebinger884c07b2018-02-15 16:17:40 -08005077 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005078 * Sets the ImsService Package Name that Telephony will bind to.
5079 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005080 * @param slotIndex the slot ID that the ImsService should bind for.
5081 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005082 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005083 * @param featureTypes An integer array of feature types associated with a packageName.
5084 * @param packageName The name of the package that the current configuration will be replaced
5085 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005086 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005087 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005088 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5089 int[] featureTypes, String packageName) {
5090 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5091 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5093 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005094 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096 final long identity = Binder.clearCallingIdentity();
5097 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005098 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005099 // may happen if the device does not support IMS.
5100 return false;
5101 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005102 Map<Integer, String> featureConfig = new HashMap<>();
5103 for (int featureType : featureTypes) {
5104 featureConfig.put(featureType, packageName);
5105 }
5106 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5107 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005108 } finally {
5109 Binder.restoreCallingIdentity(identity);
5110 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005111 }
5112
5113 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005114 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005115 *
5116 * @param slotId The slot that the ImsService is associated with.
5117 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5118 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005119 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005120 * @return the package name of the ImsService configuration.
5121 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005122 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5123 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005124 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005125 TelephonyPermissions
5126 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5127 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5128 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005130 final long identity = Binder.clearCallingIdentity();
5131 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005132 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005133 // may happen if the device does not support IMS.
5134 return "";
5135 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005136 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005137 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5138 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139 } finally {
5140 Binder.restoreCallingIdentity(identity);
5141 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005142 }
5143
Brad Ebinger77b832e2019-10-17 17:03:22 -07005144 /**
5145 * Get the MmTelFeature state associated with the requested subscription id.
5146 * @param subId The subscription that the MmTelFeature is associated with.
5147 * @param callback A callback with an integer containing the
5148 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5149 */
5150 @Override
5151 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5152 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5153 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5154 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5155 "IMS not available on device.");
5156 }
5157 final long token = Binder.clearCallingIdentity();
5158 try {
5159 int slotId = getSlotIndex(subId);
5160 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5161 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5162 + subId + "'");
5163 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5164 }
5165 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5166 try {
5167 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5168 } catch (RemoteException e) {
5169 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5170 + "Ignore");
5171 }
5172 });
5173 } finally {
5174 Binder.restoreCallingIdentity(token);
5175 }
5176 }
5177
Wink Saville36469e72014-06-11 15:17:00 -07005178 public void setImsRegistrationState(boolean registered) {
5179 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180
5181 final long identity = Binder.clearCallingIdentity();
5182 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005183 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184 } finally {
5185 Binder.restoreCallingIdentity(identity);
5186 }
Wink Saville36469e72014-06-11 15:17:00 -07005187 }
5188
5189 /**
Stuart Scott54788802015-03-30 13:18:01 -07005190 * Set the network selection mode to automatic.
5191 *
5192 */
5193 @Override
5194 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5196 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005197
5198 final long identity = Binder.clearCallingIdentity();
5199 try {
shilufc958392020-01-20 11:36:01 -08005200 if (!isActiveSubscription(subId)) {
5201 return;
5202 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005203 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5204 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
Stuart Scott54788802015-03-30 13:18:01 -07005208 }
5209
Pengquan Mengea84e042018-09-20 14:57:26 -07005210 /**
5211 * Ask the radio to connect to the input network and change selection mode to manual.
5212 *
5213 * @param subId the id of the subscription.
5214 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5215 * the operator to attach to.
5216 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5217 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5218 * normal network selection next time.
5219 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005220 */
5221 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005222 public boolean setNetworkSelectionModeManual(
5223 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005224 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5225 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005226
5227 if (!isActiveSubscription(subId)) {
5228 return false;
5229 }
5230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 final long identity = Binder.clearCallingIdentity();
5232 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005233 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005234 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005235 if (DBG) {
5236 log("setNetworkSelectionModeManual: subId: " + subId
5237 + " operator: " + operatorInfo);
5238 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005243 }
5244
5245 /**
5246 * Scans for available networks.
5247 */
5248 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005249 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5250 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5252 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005253 LocationAccessPolicy.LocationPermissionResult locationResult =
5254 LocationAccessPolicy.checkLocationPermission(mApp,
5255 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5256 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005257 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005258 .setCallingPid(Binder.getCallingPid())
5259 .setCallingUid(Binder.getCallingUid())
5260 .setMethod("getCellNetworkScanResults")
5261 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5262 .build());
5263 switch (locationResult) {
5264 case DENIED_HARD:
5265 throw new SecurityException("Not allowed to access scan results -- location");
5266 case DENIED_SOFT:
5267 return null;
5268 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269
Pengquan Menga1bb6272018-09-06 09:59:22 -07005270 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005271 try {
5272 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005273 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005278 }
5279
5280 /**
sqian80370722020-01-29 15:02:51 -08005281 * Get the call forwarding info, given the call forwarding reason.
5282 */
5283 @Override
5284 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5285 enforceReadPrivilegedPermission("getCallForwarding");
5286 long identity = Binder.clearCallingIdentity();
5287 try {
5288 if (DBG) {
5289 log("getCallForwarding: subId " + subId
5290 + " callForwardingReason" + callForwardingReason);
5291 }
5292 return (CallForwardingInfo) sendRequest(
5293 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
5297 }
5298
5299 /**
5300 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5301 * reason, the number to forward, and the timeout before the forwarding is attempted.
5302 */
5303 @Override
5304 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5305 enforceModifyPermission();
5306 long identity = Binder.clearCallingIdentity();
5307 try {
5308 if (DBG) {
5309 log("setCallForwarding: subId " + subId
5310 + " callForwardingInfo" + callForwardingInfo);
5311 }
5312 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
5316 }
5317
5318 /**
5319 * Get the call forwarding info, given the call forwarding reason.
5320 */
5321 @Override
5322 public int getCallWaitingStatus(int subId) {
5323 enforceReadPrivilegedPermission("getCallForwarding");
5324 long identity = Binder.clearCallingIdentity();
5325 try {
5326 if (DBG) log("getCallWaitingStatus: subId " + subId);
5327 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5328 } finally {
5329 Binder.restoreCallingIdentity(identity);
5330 }
5331 }
5332
5333 /**
5334 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5335 * reason, the number to forward, and the timeout before the forwarding is attempted.
5336 */
5337 @Override
5338 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5339 enforceModifyPermission();
5340 long identity = Binder.clearCallingIdentity();
5341 try {
5342 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5343 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5344 } finally {
5345 Binder.restoreCallingIdentity(identity);
5346 }
5347 }
5348
5349 /**
yinxub1bed742017-04-17 11:45:04 -07005350 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005351 *
yinxub1bed742017-04-17 11:45:04 -07005352 * @param subId id of the subscription
5353 * @param request contains the radio access networks with bands/channels to scan
5354 * @param messenger callback messenger for scan results or errors
5355 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005356 * @return the id of the requested scan which can be used to stop the scan.
5357 */
5358 @Override
5359 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005360 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5362 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005363 LocationAccessPolicy.LocationPermissionResult locationResult =
5364 LocationAccessPolicy.checkLocationPermission(mApp,
5365 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5366 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005367 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005368 .setCallingPid(Binder.getCallingPid())
5369 .setCallingUid(Binder.getCallingUid())
5370 .setMethod("requestNetworkScan")
5371 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5372 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005373 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005374 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005375 if (e != null) {
5376 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5377 throw e;
5378 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005379 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005380 return TelephonyScanManager.INVALID_SCAN_ID;
5381 }
5382 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383 }
Hall Liu912dfd32019-04-25 14:02:26 -07005384 int callingUid = Binder.getCallingUid();
5385 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005386 final long identity = Binder.clearCallingIdentity();
5387 try {
5388 return mNetworkScanRequestTracker.startNetworkScan(
5389 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005390 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005391 } finally {
5392 Binder.restoreCallingIdentity(identity);
5393 }
yinxu504e1392017-04-12 16:03:22 -07005394 }
5395
Hall Liub2ac8ef2019-02-28 15:56:23 -08005396 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005397 NetworkScanRequest request, int subId) {
5398 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5399 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5400 boolean hasNetworkScanPermission =
5401 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5402 == PERMISSION_GRANTED;
5403
5404 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5405 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5406 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005407 }
5408
5409 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5410 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005411 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5412 return new SecurityException("Specific channels must not be"
5413 + " scanned without location access.");
5414 }
5415 }
5416 }
5417
Hall Liub2ac8ef2019-02-28 15:56:23 -08005418 return null;
5419 }
5420
yinxu504e1392017-04-12 16:03:22 -07005421 /**
5422 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005423 *
5424 * @param subId id of the subscription
5425 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005426 */
5427 @Override
5428 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5430 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431
Hall Liu912dfd32019-04-25 14:02:26 -07005432 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433 final long identity = Binder.clearCallingIdentity();
5434 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005435 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005436 } finally {
5437 Binder.restoreCallingIdentity(identity);
5438 }
yinxu504e1392017-04-12 16:03:22 -07005439 }
5440
5441 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005442 * Get the calculated preferred network type.
5443 * Used for debugging incorrect network type.
5444 *
5445 * @return the preferred network type, defined in RILConstants.java.
5446 */
5447 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005448 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005449 final Phone defaultPhone = getDefaultPhone();
5450 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005451 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005452 return RILConstants.PREFERRED_NETWORK_MODE;
5453 }
5454
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005455 final long identity = Binder.clearCallingIdentity();
5456 try {
5457 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005458 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 } finally {
5460 Binder.restoreCallingIdentity(identity);
5461 }
Junda Liu84d15a22014-07-02 11:21:04 -07005462 }
5463
5464 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005465 * Get the preferred network type.
5466 * Used for device configuration by some CDMA operators.
5467 *
5468 * @return the preferred network type, defined in RILConstants.java.
5469 */
5470 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005471 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005472 TelephonyPermissions
5473 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5474 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475
5476 final long identity = Binder.clearCallingIdentity();
5477 try {
5478 if (DBG) log("getPreferredNetworkType");
5479 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5480 int networkType = (result != null ? result[0] : -1);
5481 if (DBG) log("getPreferredNetworkType: " + networkType);
5482 return networkType;
5483 } finally {
5484 Binder.restoreCallingIdentity(identity);
5485 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005486 }
5487
5488 /**
5489 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005490 *
5491 * @param networkType the preferred network type, defined in RILConstants.java.
5492 * @return true on success; false on any failure.
5493 */
5494 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005495 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5497 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005498
5499 final long identity = Binder.clearCallingIdentity();
5500 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005501 Settings.Global.putInt(mApp.getContentResolver(),
5502 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005503
5504 Boolean success = (Boolean) sendRequest(
5505 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5506 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5507 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508 } finally {
5509 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005510 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005511 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005512
5513 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005514 * Get the allowed network types that store in the telephony provider.
5515 *
5516 * @param subId the id of the subscription.
5517 * @return allowedNetworkTypes the allowed network types.
5518 */
5519 @Override
5520 public long getAllowedNetworkTypes(int subId) {
5521 TelephonyPermissions
5522 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5523 mApp, subId, "getAllowedNetworkTypes");
5524
5525 final long identity = Binder.clearCallingIdentity();
5526 try {
5527 return SubscriptionManager.getLongSubscriptionProperty(
5528 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5529 } finally {
5530 Binder.restoreCallingIdentity(identity);
5531 }
5532 }
5533
5534 /**
5535 * Set the allowed network types.
5536 *
5537 * @param subId the id of the subscription.
5538 * @param allowedNetworkTypes the allowed network types.
5539 * @return true on success; false on any failure.
5540 */
5541 @Override
5542 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5544 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005545
calvinpan089c2a62020-03-12 14:17:55 +08005546 SubscriptionManager.setSubscriptionProperty(subId,
5547 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5548 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005549
calvinpan089c2a62020-03-12 14:17:55 +08005550 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5551 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5552 RILConstants.PREFERRED_NETWORK_MODE);
5553 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005554 }
5555
5556 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005557 * Get the allowed network types for certain reason.
5558 *
5559 * @param subId the id of the subscription.
5560 * @param reason the reason the allowed network type change is taking place
5561 * @return the allowed network types.
5562 */
5563 @Override
5564 public long getAllowedNetworkTypesForReason(int subId,
5565 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5566 TelephonyPermissions
5567 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5568 mApp, subId, "getAllowedNetworkTypesForReason");
5569 final long identity = Binder.clearCallingIdentity();
5570 try {
5571 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5572 } finally {
5573 Binder.restoreCallingIdentity(identity);
5574 }
5575 }
5576
5577 /**
5578 * Get the effective allowed network types on the device.
5579 * This API will return an intersection of allowed network types for all reasons,
5580 * including the configuration done through setAllowedNetworkTypes
5581 *
5582 * @param subId the id of the subscription.
5583 * @return the allowed network types
5584 */
5585 @Override
5586 public long getEffectiveAllowedNetworkTypes(int subId) {
5587 TelephonyPermissions
5588 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5589 mApp, subId, "getEffectiveAllowedNetworkTypes");
5590 final long identity = Binder.clearCallingIdentity();
5591 try {
5592 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5593 } finally {
5594 Binder.restoreCallingIdentity(identity);
5595 }
5596 }
5597
5598 /**
5599 * Set the allowed network types of the device and
5600 * provide the reason triggering the allowed network change.
5601 *
5602 * @param subId the id of the subscription.
5603 * @param reason the reason the allowed network type change is taking place
5604 * @param allowedNetworkTypes the allowed network types.
5605 * @return true on success; false on any failure.
5606 */
5607 @Override
5608 public boolean setAllowedNetworkTypesForReason(int subId,
5609 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5611 mApp, subId, "setAllowedNetworkTypesForReason");
5612 final long identity = Binder.clearCallingIdentity();
5613 try {
5614 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5615 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5616 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5617 RILConstants.PREFERRED_NETWORK_MODE);
5618 return setPreferredNetworkType(subId, preferredNetworkMode);
5619 } finally {
5620 Binder.restoreCallingIdentity(identity);
5621 }
5622 }
5623
5624 /**
Miaoa84611c2019-03-15 09:21:10 +08005625 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005626 *
Miaoa84611c2019-03-15 09:21:10 +08005627 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005628 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005629 * @hide
5630 */
5631 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005632 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005633 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005634 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005635 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636 try {
Miaoa84611c2019-03-15 09:21:10 +08005637 if (phone != null) {
5638 return phone.hasMatchedTetherApnSetting();
5639 } else {
5640 return false;
5641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 } finally {
5643 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005644 }
Junda Liu475951f2014-11-07 16:45:03 -08005645 }
5646
5647 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005648 * Set mobile data enabled
5649 * Used by the user through settings etc to turn on/off mobile data
5650 *
5651 * @param enable {@code true} turn turn data on, else {@code false}
5652 */
5653 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005654 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5656 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657
5658 final long identity = Binder.clearCallingIdentity();
5659 try {
5660 int phoneId = mSubscriptionController.getPhoneId(subId);
5661 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5662 Phone phone = PhoneFactory.getPhone(phoneId);
5663 if (phone != null) {
5664 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005665 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005667 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668 }
5669 } finally {
5670 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005671 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005672 }
5673
5674 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005675 * Enable or disable always reporting signal strength changes from radio.
5676 *
5677 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5678 */
5679 @Override
5680 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5681 enforceModifyPermission();
5682 enforceSystemCaller();
5683
5684 final long identity = Binder.clearCallingIdentity();
5685 final Phone phone = getPhone(subId);
5686 try {
5687 if (phone != null) {
5688 if (DBG) {
5689 log("setAlwaysReportSignalStrength: subId=" + subId
5690 + " isEnable=" + isEnable);
5691 }
5692 phone.setAlwaysReportSignalStrength(isEnable);
5693 } else {
5694 loge("setAlwaysReportSignalStrength: no phone found for subId="
5695 + subId);
5696 }
5697 } finally {
5698 Binder.restoreCallingIdentity(identity);
5699 }
5700 }
5701
5702 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005703 * Get the user enabled state of Mobile Data.
5704 *
5705 * TODO: remove and use isUserDataEnabled.
5706 * This can't be removed now because some vendor codes
5707 * calls through ITelephony directly while they should
5708 * use TelephonyManager.
5709 *
5710 * @return true on enabled
5711 */
5712 @Override
5713 public boolean getDataEnabled(int subId) {
5714 return isUserDataEnabled(subId);
5715 }
5716
5717 /**
5718 * Get whether mobile data is enabled per user setting.
5719 *
5720 * There are other factors deciding whether mobile data is actually enabled, but they are
5721 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005722 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005723 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005724 *
5725 * @return {@code true} if data is enabled else {@code false}
5726 */
5727 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005728 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005729 try {
5730 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5731 null);
5732 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5734 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736
5737 final long identity = Binder.clearCallingIdentity();
5738 try {
5739 int phoneId = mSubscriptionController.getPhoneId(subId);
5740 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5741 Phone phone = PhoneFactory.getPhone(phoneId);
5742 if (phone != null) {
5743 boolean retVal = phone.isUserDataEnabled();
5744 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5745 return retVal;
5746 } else {
5747 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5748 return false;
5749 }
5750 } finally {
5751 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005752 }
5753 }
5754
5755 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005756 * Checks if the device is capable of mobile data by considering whether whether the
5757 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5758 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005759 *
Shuo Qian985d1232020-01-08 14:30:06 -08005760 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005761 */
5762 @Override
5763 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005764 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765
5766 final long identity = Binder.clearCallingIdentity();
5767 try {
5768 int phoneId = mSubscriptionController.getPhoneId(subId);
5769 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5770 Phone phone = PhoneFactory.getPhone(phoneId);
5771 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005772 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5774 return retVal;
5775 } else {
5776 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5777 return false;
5778 }
5779 } finally {
5780 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005781 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005782 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005783
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005784 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005785 Phone phone) {
5786 //load access rules from carrier configs, and check those as well: b/139133814
5787 SubscriptionController subController = SubscriptionController.getInstance();
5788 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5789 || subController == null) return privilegeFromSim;
5790
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005791 PackageManager pkgMgr = phone.getContext().getPackageManager();
5792 String[] packages = pkgMgr.getPackagesForUid(uid);
5793
5794 final long identity = Binder.clearCallingIdentity();
5795 try {
5796 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5797 SubscriptionManager subManager = (SubscriptionManager)
5798 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5799 for (String pkg : packages) {
5800 if (subManager.canManageSubscription(subInfo, pkg)) {
5801 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5802 }
5803 }
5804 return privilegeFromSim;
5805 } finally {
5806 Binder.restoreCallingIdentity(identity);
5807 }
5808 }
5809
5810 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5811 String pkgName) {
5812 //load access rules from carrier configs, and check those as well: b/139133814
5813 SubscriptionController subController = SubscriptionController.getInstance();
5814 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5815 || subController == null) return privilegeFromSim;
5816
5817 final long identity = Binder.clearCallingIdentity();
5818 try {
5819 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5820 SubscriptionManager subManager = (SubscriptionManager)
5821 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5822 return subManager.canManageSubscription(subInfo, pkgName)
5823 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5824 } finally {
5825 Binder.restoreCallingIdentity(identity);
5826 }
5827 }
5828
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005829 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005830 public int getCarrierPrivilegeStatus(int subId) {
5831 final Phone phone = getPhone(subId);
5832 if (phone == null) {
5833 loge("getCarrierPrivilegeStatus: Invalid subId");
5834 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5835 }
5836 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005837 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005838 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005839 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5840 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005841
5842 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5843 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005844 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005845 }
Junda Liu29340342014-07-10 15:23:27 -07005846
5847 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005848 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005849 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005850 final Phone phone = getPhone(subId);
5851 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005852 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005853 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5854 }
5855 UiccProfile profile =
5856 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5857 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005858 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005859 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5860 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005861 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005862 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005863 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005864 }
5865
5866 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005867 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5868 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005869 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005870 }
5871
5872 int phoneId = SubscriptionManager.getPhoneId(subId);
5873 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005874 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005875 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005876 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5877 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005878 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5879 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5880 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005881 }
5882
5883 @Override
5884 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005885 if (TextUtils.isEmpty(pkgName))
5886 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005887 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5888 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5889 UiccCard card = UiccController.getInstance().getUiccCard(i);
5890 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005891 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005892 continue;
5893 }
5894
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005895 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5896 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5897 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005898 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5899 break;
5900 }
5901 }
5902
5903 return result;
Junda Liu29340342014-07-10 15:23:27 -07005904 }
Derek Tan89e89d42014-07-08 17:00:10 -07005905
5906 @Override
Junda Liue64de782015-04-16 17:19:16 -07005907 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5908 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5909 loge("phoneId " + phoneId + " is not valid.");
5910 return null;
5911 }
5912 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005913 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005914 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005915 return null ;
5916 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005917 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005918 }
5919
Amith Yamasani6e118872016-02-19 12:53:51 -08005920 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005921 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005922 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005923 List<String> privilegedPackages = new ArrayList<>();
5924 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005925 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5926 // has UICC in that slot.
5927 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005928 if (card.hasCarrierPrivilegeRules()) {
5929 if (packages == null) {
5930 // Only check packages in user 0 for now
5931 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005932 PackageManager.MATCH_DISABLED_COMPONENTS
5933 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005934 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005935 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005936 }
5937 for (int p = packages.size() - 1; p >= 0; p--) {
5938 PackageInfo pkgInfo = packages.get(p);
5939 if (pkgInfo != null && pkgInfo.packageName != null
5940 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005941 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005942 privilegedPackages.add(pkgInfo.packageName);
5943 }
5944 }
5945 }
5946 }
5947 return privilegedPackages;
5948 }
5949
chen xuf7e9fe82019-05-09 19:31:02 -07005950 @Override
5951 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005952 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5953
5954 final long identity = Binder.clearCallingIdentity();
5955
chen xuf7e9fe82019-05-09 19:31:02 -07005956 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005957 try {
5958 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5959 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5960 }
5961 } finally {
5962 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005963 }
5964 return privilegedPackages;
5965 }
5966
Wink Savilleb564aae2014-10-23 10:18:09 -07005967 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005968 final Phone phone = getPhone(subId);
5969 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005970 if (card == null) {
5971 loge("getIccId: No UICC");
5972 return null;
5973 }
5974 String iccId = card.getIccId();
5975 if (TextUtils.isEmpty(iccId)) {
5976 loge("getIccId: ICC ID is null or empty.");
5977 return null;
5978 }
5979 return iccId;
5980 }
5981
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005982 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005983 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5984 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005985 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005986 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 final long identity = Binder.clearCallingIdentity();
5989 try {
5990 final String iccId = getIccId(subId);
5991 final Phone phone = getPhone(subId);
5992 if (phone == null) {
5993 return false;
5994 }
5995 final String subscriberId = phone.getSubscriberId();
5996
5997 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005998 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 + subscriberId + " to " + number);
6000 }
6001
6002 if (TextUtils.isEmpty(iccId)) {
6003 return false;
6004 }
6005
6006 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6007
6008 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6009 if (alphaTag == null) {
6010 editor.remove(alphaTagPrefKey);
6011 } else {
6012 editor.putString(alphaTagPrefKey, alphaTag);
6013 }
6014
6015 // Record both the line number and IMSI for this ICCID, since we need to
6016 // track all merged IMSIs based on line number
6017 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6018 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6019 if (number == null) {
6020 editor.remove(numberPrefKey);
6021 editor.remove(subscriberPrefKey);
6022 } else {
6023 editor.putString(numberPrefKey, number);
6024 editor.putString(subscriberPrefKey, subscriberId);
6025 }
6026
6027 editor.commit();
6028 return true;
6029 } finally {
6030 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006031 }
Derek Tan7226c842014-07-02 17:42:23 -07006032 }
6033
6034 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006035 public String getLine1NumberForDisplay(int subId, String callingPackage,
6036 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006037 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006039 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006040 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006041 return null;
6042 }
Derek Tan97ebb422014-09-05 16:55:38 -07006043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 final long identity = Binder.clearCallingIdentity();
6045 try {
6046 String iccId = getIccId(subId);
6047 if (iccId != null) {
6048 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6049 if (DBG_MERGE) {
6050 log("getLine1NumberForDisplay returning "
6051 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6052 }
6053 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006054 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6056 return null;
6057 } finally {
6058 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006059 }
Derek Tan7226c842014-07-02 17:42:23 -07006060 }
6061
6062 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006063 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6064 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006066 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006067 return null;
6068 }
Derek Tan97ebb422014-09-05 16:55:38 -07006069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 final long identity = Binder.clearCallingIdentity();
6071 try {
6072 String iccId = getIccId(subId);
6073 if (iccId != null) {
6074 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6075 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6076 }
6077 return null;
6078 } finally {
6079 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006080 }
Derek Tan7226c842014-07-02 17:42:23 -07006081 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006082
6083 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006084 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6085 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006086 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6087 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006089 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006090 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006091 return null;
6092 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006093
Jordan Liub49b04b2019-05-06 14:45:15 -07006094 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6095 // the process, where TelephonyManager was instantiated.
6096 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006097 final long identity = Binder.clearCallingIdentity();
6098 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006099 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100 final TelephonyManager tele = TelephonyManager.from(context);
6101 final SubscriptionManager sub = SubscriptionManager.from(context);
6102
6103 // Figure out what subscribers are currently active
6104 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006105
Jordan Liub49b04b2019-05-06 14:45:15 -07006106 // Only consider subs which match the current subId
6107 // This logic can be simplified. See b/131189269 for progress.
6108 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006109 activeSubscriberIds.add(tele.getSubscriberId(subId));
6110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111
6112 // First pass, find a number override for an active subscriber
6113 String mergeNumber = null;
6114 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6115 for (String key : prefs.keySet()) {
6116 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6117 final String subscriberId = (String) prefs.get(key);
6118 if (activeSubscriberIds.contains(subscriberId)) {
6119 final String iccId = key.substring(
6120 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6121 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6122 mergeNumber = (String) prefs.get(numberKey);
6123 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006124 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006125 + " for active subscriber " + subscriberId);
6126 }
6127 if (!TextUtils.isEmpty(mergeNumber)) {
6128 break;
6129 }
6130 }
6131 }
6132 }
6133
6134 // Shortcut when no active merged subscribers
6135 if (TextUtils.isEmpty(mergeNumber)) {
6136 return null;
6137 }
6138
6139 // Second pass, find all subscribers under that line override
6140 final ArraySet<String> result = new ArraySet<>();
6141 for (String key : prefs.keySet()) {
6142 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6143 final String number = (String) prefs.get(key);
6144 if (mergeNumber.equals(number)) {
6145 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6146 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6147 final String subscriberId = (String) prefs.get(subscriberKey);
6148 if (!TextUtils.isEmpty(subscriberId)) {
6149 result.add(subscriberId);
6150 }
6151 }
6152 }
6153 }
6154
6155 final String[] resultArray = result.toArray(new String[result.size()]);
6156 Arrays.sort(resultArray);
6157 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006158 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6160 }
6161 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006162 } finally {
6163 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006164 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006165 }
6166
6167 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006168 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6169 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6170
6171 final long identity = Binder.clearCallingIdentity();
6172 try {
6173 final TelephonyManager telephonyManager = mApp.getSystemService(
6174 TelephonyManager.class);
6175 String subscriberId = telephonyManager.getSubscriberId(subId);
6176 if (subscriberId == null) {
6177 if (DBG) {
6178 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6179 + subId);
6180 }
6181 return null;
6182 }
6183
6184 final SubscriptionInfo info = SubscriptionController.getInstance()
6185 .getSubscriptionInfo(subId);
6186 final ParcelUuid groupUuid = info.getGroupUuid();
6187 // If it doesn't belong to any group, return just subscriberId of itself.
6188 if (groupUuid == null) {
6189 return new String[]{subscriberId};
6190 }
6191
6192 // Get all subscriberIds from the group.
6193 final List<String> mergedSubscriberIds = new ArrayList<>();
6194 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006195 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6196 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006197 for (SubscriptionInfo subInfo : groupInfos) {
6198 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6199 if (subscriberId != null) {
6200 mergedSubscriberIds.add(subscriberId);
6201 }
6202 }
6203
6204 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6205 } finally {
6206 Binder.restoreCallingIdentity(identity);
6207
6208 }
6209 }
6210
6211 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006212 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006213 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006214 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006215
6216 final long identity = Binder.clearCallingIdentity();
6217 try {
6218 final Phone phone = getPhone(subId);
6219 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6220 } finally {
6221 Binder.restoreCallingIdentity(identity);
6222 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006223 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006224
6225 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006226 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006227 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6228 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006229 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6230 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231
6232 final long identity = Binder.clearCallingIdentity();
6233 try {
6234 final Phone phone = getPhone(subId);
6235 if (phone == null) {
6236 return false;
6237 }
6238 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6239 cdmaNonRoamingList);
6240 } finally {
6241 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006242 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006243 }
6244
6245 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006246 @Deprecated
6247 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6248 enforceModifyPermission();
6249
6250 int returnValue = 0;
6251 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006252 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006253 if(result.exception == null) {
6254 if (result.result != null) {
6255 byte[] responseData = (byte[])(result.result);
6256 if(responseData.length > oemResp.length) {
6257 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6258 responseData.length + "bytes. Buffer Size is " +
6259 oemResp.length + "bytes.");
6260 }
6261 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6262 returnValue = responseData.length;
6263 }
6264 } else {
6265 CommandException ex = (CommandException) result.exception;
6266 returnValue = ex.getCommandError().ordinal();
6267 if(returnValue > 0) returnValue *= -1;
6268 }
6269 } catch (RuntimeException e) {
6270 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6271 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6272 if(returnValue > 0) returnValue *= -1;
6273 }
6274
6275 return returnValue;
6276 }
6277
6278 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006279 public void setRadioCapability(RadioAccessFamily[] rafs) {
6280 try {
6281 ProxyController.getInstance().setRadioCapability(rafs);
6282 } catch (RuntimeException e) {
6283 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6284 }
6285 }
6286
6287 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006288 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006289 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006290 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006291 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006292 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294 final long identity = Binder.clearCallingIdentity();
6295 try {
chen xub97461a2018-10-26 14:17:57 -07006296 TelephonyPermissions
6297 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6298 mApp, phone.getSubId(), "getRadioAccessFamily");
6299 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300 } finally {
6301 Binder.restoreCallingIdentity(identity);
6302 }
chen xub97461a2018-10-26 14:17:57 -07006303 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006304 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006305
6306 @Override
6307 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006308 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006309 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310
6311 final long identity = Binder.clearCallingIdentity();
6312 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006313 ImsManager.getInstance(defaultPhone.getContext(),
6314 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 } finally {
6316 Binder.restoreCallingIdentity(identity);
6317 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006318 }
6319
6320 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006321 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006322 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6324 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006325 return false;
6326 }
Svet Ganovb320e182015-04-16 12:30:10 -07006327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328 final long identity = Binder.clearCallingIdentity();
6329 try {
6330 // Check the user preference and the system-level IMS setting. Even if the user has
6331 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6332 // In the long run, we may instead need to check if there exists a connection service
6333 // which can support video calling.
6334 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006335 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006336 return imsManager.isVtEnabledByPlatform()
6337 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6338 && imsManager.isVtEnabledByUser();
6339 } finally {
6340 Binder.restoreCallingIdentity(identity);
6341 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006342 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006343
Andrew Leea1239f22015-03-02 17:44:07 -08006344 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006345 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6346 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006347 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006348 mApp, subId, callingPackage, callingFeatureId,
6349 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006350 return false;
6351 }
6352
6353 final long identity = Binder.clearCallingIdentity();
6354 try {
6355 CarrierConfigManager configManager =
6356 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006357 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6359 } finally {
6360 Binder.restoreCallingIdentity(identity);
6361 }
Andrew Leea1239f22015-03-02 17:44:07 -08006362 }
6363
6364 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006365 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006366 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006367 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 return false;
6369 }
6370
6371 final long identity = Binder.clearCallingIdentity();
6372 try {
6373 CarrierConfigManager configManager =
6374 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006375 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6377 } finally {
6378 Binder.restoreCallingIdentity(identity);
6379 }
Andrew Leea1239f22015-03-02 17:44:07 -08006380 }
6381
Andrew Lee9431b832015-03-09 18:46:45 -07006382 @Override
6383 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006384 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006385 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006386 }
6387
6388 @Override
6389 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390 final long identity = Binder.clearCallingIdentity();
6391 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006392 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006393 } finally {
6394 Binder.restoreCallingIdentity(identity);
6395 }
Andrew Lee9431b832015-03-09 18:46:45 -07006396 }
6397
Hall Liuf6668912018-10-31 17:05:23 -07006398 /**
6399 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6400 * support for the feature and device firmware support.
6401 *
6402 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6403 */
6404 @Override
6405 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006407 final Phone phone = getPhone(subscriptionId);
6408 if (phone == null) {
6409 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6410 return false;
6411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006413 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6415 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006416 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 return isCarrierSupported && isDeviceSupported;
6418 } finally {
6419 Binder.restoreCallingIdentity(identity);
6420 }
Hall Liu98187582018-01-22 19:15:32 -08006421 }
6422
Hall Liuf6668912018-10-31 17:05:23 -07006423 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006424 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6425 * RTT setting, will return true if the device and carrier both support RTT.
6426 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006427 */
6428 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429 final long identity = Binder.clearCallingIdentity();
6430 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006431 boolean isRttSupported = isRttSupported(subscriptionId);
6432 boolean isUserRttSettingOn = Settings.Secure.getInt(
6433 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6434 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6435 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6436 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006437 } finally {
6438 Binder.restoreCallingIdentity(identity);
6439 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006440 }
6441
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006442 @Deprecated
6443 @Override
6444 public String getDeviceId(String callingPackage) {
6445 return getDeviceIdWithFeature(callingPackage, null);
6446 }
6447
Sanket Padawe7310cc72015-01-14 09:53:20 -08006448 /**
6449 * Returns the unique device ID of phone, for example, the IMEI for
6450 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6451 *
6452 * <p>Requires Permission:
6453 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6454 */
6455 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006456 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006457 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006458 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006459 return null;
6460 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006461 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006462 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006463 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006464 return null;
6465 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006466
6467 final long identity = Binder.clearCallingIdentity();
6468 try {
6469 return phone.getDeviceId();
6470 } finally {
6471 Binder.restoreCallingIdentity(identity);
6472 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006473 }
6474
Ping Sunc67b7c22016-03-02 19:16:45 +08006475 /**
6476 * {@hide}
6477 * Returns the IMS Registration Status on a particular subid
6478 *
6479 * @param subId
6480 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006481 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006482 Phone phone = getPhone(subId);
6483 if (phone != null) {
6484 return phone.isImsRegistered();
6485 } else {
6486 return false;
6487 }
6488 }
6489
Santos Cordon7a1885b2015-02-03 11:15:19 -08006490 @Override
6491 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006492 final long identity = Binder.clearCallingIdentity();
6493 try {
6494 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6495 } finally {
6496 Binder.restoreCallingIdentity(identity);
6497 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006498 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006499
Tyler Gunnf70ed162019-04-03 15:28:53 -07006500 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006501 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006502 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006503 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006504 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006505 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6506 }
6507 final long identity = Binder.clearCallingIdentity();
6508 try {
6509 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6510 } finally {
6511 Binder.restoreCallingIdentity(identity);
6512 }
6513 }
6514
6515 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006516 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6517 final long identity = Binder.clearCallingIdentity();
6518 try {
6519 Phone phone = getPhone(subscriptionId);
6520 if (phone == null) {
6521 return null;
6522 }
6523 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6524 } finally {
6525 Binder.restoreCallingIdentity(identity);
6526 }
6527 }
6528
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006529 /**
6530 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006531 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006532 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006533 final long identity = Binder.clearCallingIdentity();
6534 try {
6535 Phone phone = getPhone(subId);
6536 if (phone != null) {
6537 return phone.isWifiCallingEnabled();
6538 } else {
6539 return false;
6540 }
6541 } finally {
6542 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006543 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006544 }
6545
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006546 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006547 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006548 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006549 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550 final long identity = Binder.clearCallingIdentity();
6551 try {
6552 Phone phone = getPhone(subId);
6553 if (phone != null) {
6554 return phone.isVideoEnabled();
6555 } else {
6556 return false;
6557 }
6558 } finally {
6559 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006560 }
6561 }
6562
6563 /**
6564 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6565 * defined in {@link ImsRegistrationImplBase}.
6566 */
6567 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 final long identity = Binder.clearCallingIdentity();
6569 try {
6570 Phone phone = getPhone(subId);
6571 if (phone != null) {
6572 return phone.getImsRegistrationTech();
6573 } else {
6574 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6575 }
6576 } finally {
6577 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006578 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006579 }
6580
Stuart Scott8eef64f2015-04-08 15:13:54 -07006581 @Override
6582 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006583 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006584 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6585 return;
6586 }
6587
Svet Ganovcc087f82015-05-12 20:35:54 -07006588 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006589
Svet Ganovcc087f82015-05-12 20:35:54 -07006590 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006591 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6592 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006593 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006594 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006595 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006596 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6597 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006598 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006599 // There has been issues when Sms raw table somehow stores orphan
6600 // fragments. They lead to garbled message when new fragments come
6601 // in and combined with those stale ones. In case this happens again,
6602 // user can reset all network settings which will clean up this table.
6603 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006604 // Clean up IMS settings as well here.
6605 int slotId = getSlotIndex(subId);
6606 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6607 ImsManager.getInstance(mApp, slotId).factoryReset();
6608 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006609
6610 // Erase modem config if erase modem on network setting is enabled.
6611 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6612 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6613 if (configValue != null && Boolean.parseBoolean(configValue)) {
6614 sendEraseModemConfig(getDefaultPhone());
6615 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006616 } finally {
6617 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006618 }
6619 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006620
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006621 private void cleanUpSmsRawTable(Context context) {
6622 ContentResolver resolver = context.getContentResolver();
6623 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6624 resolver.delete(uri, null, null);
6625 }
6626
Narayan Kamath1c496c22015-04-16 14:40:19 +01006627 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006628 public String getSimLocaleForSubscriber(int subId) {
6629 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6630 final Phone phone = getPhone(subId);
6631 if (phone == null) {
6632 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006633 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006634 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006635 final long identity = Binder.clearCallingIdentity();
6636 try {
chen xu5d3637b2019-01-21 23:31:38 -08006637 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006638 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006639 if (info == null) {
6640 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6641 return null;
6642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643 // Try and fetch the locale from the carrier properties or from the SIM language
6644 // preferences (EF-PL and EF-LI)...
6645 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006646 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006647 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6648 if (localeFromDefaultSim != null) {
6649 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6650 if (DBG) log("Using locale from subId: " + subId + " locale: "
6651 + localeFromDefaultSim);
6652 return localeFromDefaultSim.toLanguageTag();
6653 } else {
6654 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006655 }
6656 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006658 // The SIM language preferences only store a language (e.g. fr = French), not an
6659 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6660 // the SIM and carrier preferences does not include a country we add the country
6661 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006662 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006663 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006664 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665 return mccLocale.toLanguageTag();
6666 }
6667
6668 if (DBG) log("No locale found - returning null");
6669 return null;
6670 } finally {
6671 Binder.restoreCallingIdentity(identity);
6672 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006673 }
6674
6675 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006676 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6677 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006678 }
6679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006680 /**
6681 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6682 */
6683 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006684 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6685 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006686 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006687
Chenjie Yu1ba97252018-01-11 18:16:20 -08006688 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006689 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006690
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006691 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006692 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6693 * representing the state of the modem.
6694 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006695 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6696 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006697 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006698 */
6699 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006700 public void requestModemActivityInfo(ResultReceiver result) {
6701 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006702 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703
6704 final long identity = Binder.clearCallingIdentity();
6705 try {
sqian1a1be542020-03-05 11:37:28 -08006706 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006707 } finally {
6708 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006709 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006710 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006711
Siddharth Rayb8114062018-06-17 15:02:38 -07006712 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6713 // less than total activity duration.
6714 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6715 if (info == null) {
6716 return false;
6717 }
6718 int activityDurationMs =
6719 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6720 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006721 int[] txTimeMs = info.getTransmitTimeMillis();
6722 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6723 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006724 }
6725 return (info.isValid()
6726 && (info.getSleepTimeMillis() <= activityDurationMs)
6727 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006728 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006729 && (totalTxTimeMs <= activityDurationMs));
6730 }
6731
Jack Yu85bd38a2015-11-09 11:34:32 -08006732 /**
6733 * {@hide}
6734 * Returns the service state information on specified subscription.
6735 */
6736 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006737 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6738 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006739 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006740 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006741 return null;
6742 }
6743
Hall Liuf19c44f2018-11-27 14:38:17 -08006744 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6745 LocationAccessPolicy.checkLocationPermission(mApp,
6746 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6747 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006748 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006749 .setCallingPid(Binder.getCallingPid())
6750 .setCallingUid(Binder.getCallingUid())
6751 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006752 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006753 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6754 .build());
6755
6756 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6757 LocationAccessPolicy.checkLocationPermission(mApp,
6758 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6759 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006760 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006761 .setCallingPid(Binder.getCallingPid())
6762 .setCallingUid(Binder.getCallingUid())
6763 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006764 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006765 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6766 .build());
6767 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6768 boolean hasFinePermission =
6769 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6770 boolean hasCoarsePermission =
6771 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6772
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006773 final long identity = Binder.clearCallingIdentity();
6774 try {
6775 final Phone phone = getPhone(subId);
6776 if (phone == null) {
6777 return null;
6778 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006779
Hall Liuf19c44f2018-11-27 14:38:17 -08006780 ServiceState ss = phone.getServiceState();
6781
6782 // Scrub out the location info in ServiceState depending on what level of access
6783 // the caller has.
6784 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006785 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6786 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 } finally {
6788 Binder.restoreCallingIdentity(identity);
6789 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006790 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006791
6792 /**
6793 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6794 *
6795 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6796 * voicemail ringtone.
6797 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6798 * PhoneAccount.
6799 */
6800 @Override
6801 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006802 final long identity = Binder.clearCallingIdentity();
6803 try {
6804 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6805 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006806 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006807 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006809 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6810 } finally {
6811 Binder.restoreCallingIdentity(identity);
6812 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006813 }
6814
6815 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006816 * Sets the per-account voicemail ringtone.
6817 *
6818 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6819 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6820 *
6821 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6822 * voicemail ringtone.
6823 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6824 * PhoneAccount.
6825 */
6826 @Override
6827 public void setVoicemailRingtoneUri(String callingPackage,
6828 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006829 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006830 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006831 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6832 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6834 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6835 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006836 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006837
6838 final long identity = Binder.clearCallingIdentity();
6839 try {
6840 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6841 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006842 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006843 }
6844 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6845 } finally {
6846 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006847 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006848 }
6849
6850 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006851 * Returns whether vibration is set for voicemail notification in Phone settings.
6852 *
6853 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6854 * voicemail vibration setting.
6855 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6856 */
6857 @Override
6858 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006859 final long identity = Binder.clearCallingIdentity();
6860 try {
6861 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6862 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006863 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006864 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006865
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006866 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6867 } finally {
6868 Binder.restoreCallingIdentity(identity);
6869 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006870 }
6871
Youhan Wange64578a2016-05-02 15:32:42 -07006872 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006873 * Sets the per-account voicemail vibration.
6874 *
6875 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6876 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6877 *
6878 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6879 * voicemail vibration setting.
6880 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6881 * specific PhoneAccount.
6882 */
6883 @Override
6884 public void setVoicemailVibrationEnabled(String callingPackage,
6885 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006886 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006887 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006888 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6889 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6891 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6892 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006893 }
6894
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895 final long identity = Binder.clearCallingIdentity();
6896 try {
6897 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6898 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006899 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006900 }
6901 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6902 } finally {
6903 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006904 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006905 }
6906
6907 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006908 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6909 *
6910 * @throws SecurityException if the caller does not have the required permission
6911 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006912 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006913 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006914 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006915 }
6916
6917 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006918 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6919 * permission.
6920 *
6921 * @throws SecurityException if the caller does not have the required permission
6922 */
6923 private void enforceSendSmsPermission() {
6924 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6925 }
6926
6927 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006928 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006929 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006930 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006931 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006932 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006933 final long identity = Binder.clearCallingIdentity();
6934 try {
6935 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006936 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006937 if (componentName == null) {
6938 throw new SecurityException(
6939 "Caller not current active visual voicemail package[null]");
6940 }
6941 String vvmPackage = componentName.getPackageName();
6942 if (!callingPackage.equals(vvmPackage)) {
6943 throw new SecurityException("Caller not current active visual voicemail package["
6944 + vvmPackage + "]");
6945 }
6946 } finally {
6947 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006948 }
6949 }
6950
6951 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006952 * Return the application ID for the app type.
6953 *
6954 * @param subId the subscription ID that this request applies to.
6955 * @param appType the uicc app type.
6956 * @return Application ID for specificied app type, or null if no uicc.
6957 */
6958 @Override
6959 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006960 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006961 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006962
6963 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006964 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965 if (phone == null) {
6966 return null;
6967 }
6968 String aid = null;
6969 try {
6970 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6971 .getApplicationByType(appType).getAid();
6972 } catch (Exception e) {
6973 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6974 }
6975 return aid;
6976 } finally {
6977 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006978 }
Youhan Wange64578a2016-05-02 15:32:42 -07006979 }
6980
Youhan Wang4001d252016-05-11 10:29:41 -07006981 /**
6982 * Return the Electronic Serial Number.
6983 *
6984 * @param subId the subscription ID that this request applies to.
6985 * @return ESN or null if error.
6986 */
6987 @Override
6988 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006989 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006990 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006991
6992 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006993 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006994 if (phone == null) {
6995 return null;
6996 }
6997 String esn = null;
6998 try {
6999 esn = phone.getEsn();
7000 } catch (Exception e) {
7001 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7002 }
7003 return esn;
7004 } finally {
7005 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007006 }
Youhan Wang4001d252016-05-11 10:29:41 -07007007 }
7008
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007009 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007010 * Return the Preferred Roaming List Version.
7011 *
7012 * @param subId the subscription ID that this request applies to.
7013 * @return PRLVersion or null if error.
7014 */
7015 @Override
7016 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007017 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007018 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019
7020 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007021 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022 if (phone == null) {
7023 return null;
7024 }
7025 String cdmaPrlVersion = null;
7026 try {
7027 cdmaPrlVersion = phone.getCdmaPrlVersion();
7028 } catch (Exception e) {
7029 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7030 }
7031 return cdmaPrlVersion;
7032 } finally {
7033 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007034 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007035 }
7036
7037 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007038 * Get snapshot of Telephony histograms
7039 * @return List of Telephony histograms
7040 * @hide
7041 */
7042 @Override
7043 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7045 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046
7047 final long identity = Binder.clearCallingIdentity();
7048 try {
7049 return RIL.getTelephonyRILTimingHistograms();
7050 } finally {
7051 Binder.restoreCallingIdentity(identity);
7052 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007053 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007054
7055 /**
7056 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007057 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7058 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007059 * Require system privileges. In the future we may add this to carrier APIs.
7060 *
Michele Berionne482f8202018-11-27 18:57:59 -08007061 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007062 */
7063 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007064 @TelephonyManager.SetCarrierRestrictionResult
7065 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007066 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007067 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007068
Michele Berionne482f8202018-11-27 18:57:59 -08007069 if (carrierRestrictionRules == null) {
7070 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007071 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 final long identity = Binder.clearCallingIdentity();
7074 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007075 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007076 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007077 } finally {
7078 Binder.restoreCallingIdentity(identity);
7079 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007080 }
7081
7082 /**
7083 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007084 * Get the allowed carrier list and the excluded carrier list, including the priority between
7085 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007086 * Require system privileges. In the future we may add this to carrier APIs.
7087 *
Michele Berionne482f8202018-11-27 18:57:59 -08007088 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007089 */
7090 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007091 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007092 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007093 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094
7095 final long identity = Binder.clearCallingIdentity();
7096 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007097 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7098 if (response instanceof CarrierRestrictionRules) {
7099 return (CarrierRestrictionRules) response;
7100 }
7101 // Response is an Exception of some kind,
7102 // which is signalled to the user as a NULL retval
7103 return null;
7104 } catch (Exception e) {
7105 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7106 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107 } finally {
7108 Binder.restoreCallingIdentity(identity);
7109 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007110 }
7111
fionaxu59545b42016-05-25 15:53:37 -07007112 /**
7113 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7114 * @param subId the subscription ID that this action applies to.
7115 * @param enabled control enable or disable metered apns.
7116 * {@hide}
7117 */
7118 @Override
7119 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7120 enforceModifyPermission();
7121 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122
7123 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007124 if (phone == null) {
7125 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7126 return;
7127 }
7128 try {
7129 phone.carrierActionSetMeteredApnsEnabled(enabled);
7130 } catch (Exception e) {
7131 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007132 } finally {
7133 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007134 }
7135 }
7136
7137 /**
7138 * Action set from carrier signalling broadcast receivers to enable/disable radio
7139 * @param subId the subscription ID that this action applies to.
7140 * @param enabled control enable or disable radio.
7141 * {@hide}
7142 */
7143 @Override
7144 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7145 enforceModifyPermission();
7146 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147
7148 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007149 if (phone == null) {
7150 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7151 return;
7152 }
7153 try {
7154 phone.carrierActionSetRadioEnabled(enabled);
7155 } catch (Exception e) {
7156 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007157 } finally {
7158 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007159 }
7160 }
7161
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007162 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007163 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7164 * network status based on which carrier apps could apply actions accordingly,
7165 * enable/disable default url handler for example.
7166 *
7167 * @param subId the subscription ID that this action applies to.
7168 * @param report control start/stop reporting the default network status.
7169 * {@hide}
7170 */
7171 @Override
7172 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7173 enforceModifyPermission();
7174 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007175
7176 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007177 if (phone == null) {
7178 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7179 return;
7180 }
7181 try {
7182 phone.carrierActionReportDefaultNetworkStatus(report);
7183 } catch (Exception e) {
7184 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007185 } finally {
7186 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007187 }
7188 }
7189
7190 /**
fionaxud9622282017-07-17 17:51:30 -07007191 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7192 * @param subId the subscription ID that this action applies to.
7193 * {@hide}
7194 */
7195 @Override
7196 public void carrierActionResetAll(int subId) {
7197 enforceModifyPermission();
7198 final Phone phone = getPhone(subId);
7199 if (phone == null) {
7200 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7201 return;
7202 }
7203 try {
7204 phone.carrierActionResetAll();
7205 } catch (Exception e) {
7206 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7207 }
7208 }
7209
7210 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007211 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7212 * bug report is being generated.
7213 */
7214 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007215 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007216 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7217 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007218 writer.println("Permission Denial: can't dump Phone from pid="
7219 + Binder.getCallingPid()
7220 + ", uid=" + Binder.getCallingUid()
7221 + "without permission "
7222 + android.Manifest.permission.DUMP);
7223 return;
7224 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007225 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007226 }
Jack Yueb89b242016-06-22 13:27:47 -07007227
Brad Ebingerdac2f002018-04-03 15:17:52 -07007228 @Override
7229 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7230 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7231 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007232 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7233 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007234 }
7235
Jack Yueb89b242016-06-22 13:27:47 -07007236 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007237 * Policy control of data connection. Usually used when data limit is passed.
7238 * @param enabled True if enabling the data, otherwise disabling.
7239 * @param subId Subscription index
7240 * {@hide}
7241 */
7242 @Override
7243 public void setPolicyDataEnabled(boolean enabled, int subId) {
7244 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007245
7246 final long identity = Binder.clearCallingIdentity();
7247 try {
7248 Phone phone = getPhone(subId);
7249 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007250 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251 }
7252 } finally {
7253 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007254 }
7255 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007256
7257 /**
7258 * Get Client request stats
7259 * @return List of Client Request Stats
7260 * @hide
7261 */
7262 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007263 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7264 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007266 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007267 return null;
7268 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007269 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007270
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007271 final long identity = Binder.clearCallingIdentity();
7272 try {
7273 if (phone != null) {
7274 return phone.getClientRequestStats();
7275 }
7276
7277 return null;
7278 } finally {
7279 Binder.restoreCallingIdentity(identity);
7280 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007281 }
7282
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007283 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007284 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007285 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007286 }
Jack Yueb4124c2017-02-16 15:32:43 -08007287
7288 /**
Grace Chen70990072017-03-24 17:21:30 -07007289 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007290 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007291 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007292 * @param state State of SIM (power down, power up, pass through)
7293 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7294 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7295 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007296 *
7297 **/
7298 @Override
Grace Chen70990072017-03-24 17:21:30 -07007299 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007300 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007301 Phone phone = PhoneFactory.getPhone(slotIndex);
7302
vagdeviaf9a5b92018-08-15 16:01:53 -07007303 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007308 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007309 }
7310 } finally {
7311 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007312 }
7313 }
Shuo Qiandd210312017-04-12 22:11:33 +00007314
Tyler Gunn65d45c22017-06-05 11:22:26 -07007315 private boolean isUssdApiAllowed(int subId) {
7316 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007317 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007318 if (configManager == null) {
7319 return false;
7320 }
7321 PersistableBundle pb = configManager.getConfigForSubId(subId);
7322 if (pb == null) {
7323 return false;
7324 }
7325 return pb.getBoolean(
7326 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7327 }
7328
Shuo Qiandd210312017-04-12 22:11:33 +00007329 /**
7330 * Check if phone is in emergency callback mode
7331 * @return true if phone is in emergency callback mode
7332 * @param subId sub id
7333 */
goneil9c5f4872017-12-05 14:07:56 -08007334 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007335 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007336 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007337 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007338
7339 final long identity = Binder.clearCallingIdentity();
7340 try {
7341 if (phone != null) {
7342 return phone.isInEcm();
7343 } else {
7344 return false;
7345 }
7346 } finally {
7347 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007348 }
7349 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007350
7351 /**
7352 * Get the current signal strength information for the given subscription.
7353 * Because this information is not updated when the device is in a low power state
7354 * it should not be relied-upon to be current.
7355 * @param subId Subscription index
7356 * @return the most recent cached signal strength info from the modem
7357 */
7358 @Override
7359 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360 final long identity = Binder.clearCallingIdentity();
7361 try {
7362 Phone p = getPhone(subId);
7363 if (p == null) {
7364 return null;
7365 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007366
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 return p.getSignalStrength();
7368 } finally {
7369 Binder.restoreCallingIdentity(identity);
7370 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007371 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007372
Pengquan Meng77b7f132018-08-22 14:49:57 -07007373 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007374 * Get the current modem radio state for the given slot.
7375 * @param slotIndex slot index.
7376 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007377 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007378 * @return the current radio power state from the modem
7379 */
7380 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007381 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007382 Phone phone = PhoneFactory.getPhone(slotIndex);
7383 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7385 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007386 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7387 }
7388
7389 final long identity = Binder.clearCallingIdentity();
7390 try {
7391 return phone.getRadioPowerState();
7392 } finally {
7393 Binder.restoreCallingIdentity(identity);
7394 }
7395 }
7396 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7397 }
7398
7399 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007400 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7401 *
7402 * <p>Requires one of the following permissions:
7403 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7404 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7405 * privileges.
7406 *
7407 * @param subId subscription id
7408 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7409 * {@code false}.
7410 */
7411 @Override
7412 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007413 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7414 null /* message */);
7415
Pengquan Menga1bb6272018-09-06 09:59:22 -07007416 boolean isEnabled = false;
7417 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007418 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007419 Phone phone = getPhone(subId);
7420 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007421 } catch (Exception e) {
7422 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7423 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007424 } finally {
7425 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007426 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007427 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007428 }
7429
7430
7431 /**
7432 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7433 *
7434 * <p> Requires permission:
7435 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7436 * privileges.
7437 *
7438 * @param subId subscription id
7439 * @param isEnabled {@code true} means enable, {@code false} means disable.
7440 */
7441 @Override
7442 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7444 mApp, subId, "setDataRoamingEnabled");
7445
Pengquan Menga1bb6272018-09-06 09:59:22 -07007446 final long identity = Binder.clearCallingIdentity();
7447 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007448 Phone phone = getPhone(subId);
7449 if (phone != null) {
7450 phone.setDataRoamingEnabled(isEnabled);
7451 }
7452 } finally {
7453 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007454 }
7455 }
7456
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007457 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007458 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007459 TelephonyPermissions
7460 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007461 mApp, subId, "isManualNetworkSelectionAllowed");
7462
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007463 boolean isAllowed = true;
7464 final long identity = Binder.clearCallingIdentity();
7465 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007466 Phone phone = getPhone(subId);
7467 if (phone != null) {
7468 isAllowed = phone.isCspPlmnEnabled();
7469 }
7470 } finally {
7471 Binder.restoreCallingIdentity(identity);
7472 }
7473 return isAllowed;
7474 }
7475
7476 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007477 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007478 // Verify that tha callingPackage belongs to the calling UID
7479 mApp.getSystemService(AppOpsManager.class)
7480 .checkPackage(Binder.getCallingUid(), callingPackage);
7481
Jordan Liu1e142fc2019-04-22 15:10:43 -07007482 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007483 try {
7484 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007485 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007486 } catch (SecurityException e) {
7487 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7488 // has carrier privileges on an active UICC
7489 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7490 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007491 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007492 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007493 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007494
7495 final long identity = Binder.clearCallingIdentity();
7496 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007497 UiccController uiccController = UiccController.getInstance();
7498 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007499 if (hasReadPermission) {
7500 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007501 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007502
7503 // Remove private info if the caller doesn't have access
7504 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7505 for (UiccCardInfo cardInfo : cardInfos) {
7506 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7507 // is available
7508 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7509 if (card == null || card.getUiccProfile() == null) {
7510 // assume no access if the card or profile is unavailable
7511 filteredInfos.add(cardInfo.getUnprivileged());
7512 continue;
7513 }
7514 UiccProfile profile = card.getUiccProfile();
7515 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7516 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7517 filteredInfos.add(cardInfo);
7518 } else {
7519 filteredInfos.add(cardInfo.getUnprivileged());
7520 }
7521 }
7522 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007523 } finally {
7524 Binder.restoreCallingIdentity(identity);
7525 }
7526 }
7527
7528 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007529 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007530 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007531
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 final long identity = Binder.clearCallingIdentity();
7533 try {
7534 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7535 if (slots == null) {
7536 Rlog.i(LOG_TAG, "slots is null.");
7537 return null;
7538 }
7539
7540 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7541 for (int i = 0; i < slots.length; i++) {
7542 UiccSlot slot = slots[i];
7543 if (slot == null) {
7544 continue;
7545 }
7546
Jordan Liu7be7e652019-05-06 18:55:02 +00007547 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 UiccCard card = slot.getUiccCard();
7549 if (card != null) {
7550 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007551 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007552 cardId = slot.getEid();
7553 if (TextUtils.isEmpty(cardId)) {
7554 cardId = slot.getIccId();
7555 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556 }
7557
Jordan Liu857451f2019-05-09 16:35:35 -07007558 if (cardId != null) {
7559 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7560 // if cardId is an EID, it's all digits so this is fine
7561 cardId = IccUtils.stripTrailingFs(cardId);
7562 }
7563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 int cardState = 0;
7565 switch (slot.getCardState()) {
7566 case CARDSTATE_ABSENT:
7567 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7568 break;
7569 case CARDSTATE_PRESENT:
7570 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7571 break;
7572 case CARDSTATE_ERROR:
7573 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7574 break;
7575 case CARDSTATE_RESTRICTED:
7576 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7577 break;
7578 default:
7579 break;
7580
7581 }
7582
7583 infos[i] = new UiccSlotInfo(
7584 slot.isActive(),
7585 slot.isEuicc(),
7586 cardId,
7587 cardState,
7588 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007589 slot.isExtendedApduSupported(),
7590 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591 }
7592 return infos;
7593 } finally {
7594 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007595 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007596 }
7597
7598 @Override
7599 public boolean switchSlots(int[] physicalSlots) {
7600 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007601
7602 final long identity = Binder.clearCallingIdentity();
7603 try {
7604 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7605 } finally {
7606 Binder.restoreCallingIdentity(identity);
7607 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007608 }
Jack Yu4c988042018-02-27 15:30:01 -08007609
7610 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007611 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007612 final long identity = Binder.clearCallingIdentity();
7613 try {
7614 return UiccController.getInstance().getCardIdForDefaultEuicc();
7615 } finally {
7616 Binder.restoreCallingIdentity(identity);
7617 }
7618 }
7619
Pengquan Meng85728fb2018-03-12 16:31:21 -07007620 /**
goneil47ffb6e2018-04-06 15:40:58 -07007621 * A test API to reload the UICC profile.
7622 *
7623 * <p>Requires that the calling app has permission
7624 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7625 * @hide
7626 */
7627 @Override
7628 public void refreshUiccProfile(int subId) {
7629 enforceModifyPermission();
7630
7631 final long identity = Binder.clearCallingIdentity();
7632 try {
7633 Phone phone = getPhone(subId);
7634 if (phone == null) {
7635 return;
7636 }
7637 UiccCard uiccCard = phone.getUiccCard();
7638 if (uiccCard == null) {
7639 return;
7640 }
7641 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7642 if (uiccProfile == null) {
7643 return;
7644 }
7645 uiccProfile.refresh();
7646 } finally {
7647 Binder.restoreCallingIdentity(identity);
7648 }
7649 }
7650
7651 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007652 * Returns false if the mobile data is disabled by default, otherwise return true.
7653 */
7654 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007655 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007656 }
7657
7658 /**
7659 * Returns true if the data roaming is enabled by default, i.e the system property
7660 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7661 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7662 */
7663 private boolean getDefaultDataRoamingEnabled(int subId) {
7664 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007665 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07007666 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007667 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7668 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7669 return isDataRoamingEnabled;
7670 }
7671
7672 /**
7673 * Returns the default network type for the given {@code subId}, if the default network type is
7674 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7675 */
7676 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007677 List<Integer> list = TelephonyProperties.default_network();
7678 int phoneId = mSubscriptionController.getPhoneId(subId);
7679 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7680 return list.get(phoneId);
7681 }
7682 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007683 }
fionaxua13278b2018-03-21 00:08:13 -07007684
7685 @Override
7686 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007687 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007688 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007689
7690 final long identity = Binder.clearCallingIdentity();
7691 try {
7692 final Phone phone = getPhone(subId);
7693 if (phone == null) {
7694 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7695 return;
7696 }
chen xueaba88a2019-03-15 13:15:10 -07007697 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7698 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 } finally {
7700 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007701 }
fionaxua13278b2018-03-21 00:08:13 -07007702 }
7703
7704 @Override
7705 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007706 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007707
7708 final long identity = Binder.clearCallingIdentity();
7709 try {
7710 final Phone phone = getPhone(subId);
7711 if (phone == null) {
7712 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7713 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7714 }
7715 return phone.getCarrierIdListVersion();
7716 } finally {
7717 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007718 }
fionaxua13278b2018-03-21 00:08:13 -07007719 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007720
7721 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007722 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7723 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007725 mApp, subId, callingPackage, callingFeatureId,
7726 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007727 return -1;
7728 }
7729
7730 final long identity = Binder.clearCallingIdentity();
7731 try {
7732 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7733 } finally {
7734 Binder.restoreCallingIdentity(identity);
7735 }
7736 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007737
7738 @Override
7739 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007740 TelephonyPermissions
7741 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007742 mApp, subId, "getCdmaRoamingMode");
7743
7744 final long identity = Binder.clearCallingIdentity();
7745 try {
7746 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7747 } finally {
7748 Binder.restoreCallingIdentity(identity);
7749 }
7750 }
7751
7752 @Override
7753 public boolean setCdmaRoamingMode(int subId, int mode) {
7754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7755 mApp, subId, "setCdmaRoamingMode");
7756
7757 final long identity = Binder.clearCallingIdentity();
7758 try {
7759 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7760 } finally {
7761 Binder.restoreCallingIdentity(identity);
7762 }
7763 }
7764
7765 @Override
7766 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7768 mApp, subId, "setCdmaSubscriptionMode");
7769
7770 final long identity = Binder.clearCallingIdentity();
7771 try {
7772 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7773 } finally {
7774 Binder.restoreCallingIdentity(identity);
7775 }
7776 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007777
sqianc5eccab2018-10-19 18:46:41 -07007778 @Override
sqian8c685422019-02-22 15:55:18 -08007779 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007780 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007781 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007782 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7783 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007784 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7785 }
7786 final long identity = Binder.clearCallingIdentity();
7787 try {
sqian854d44b2018-12-12 16:48:18 -08007788 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7789 for (Phone phone: PhoneFactory.getPhones()) {
7790 if (phone.getEmergencyNumberTracker() != null
7791 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7792 emergencyNumberListInternal.put(
7793 phone.getSubId(),
7794 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7795 }
sqian11b7a0e2018-12-05 18:48:28 -08007796 }
sqian854d44b2018-12-12 16:48:18 -08007797 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007798 } finally {
7799 Binder.restoreCallingIdentity(identity);
7800 }
sqianc5eccab2018-10-19 18:46:41 -07007801 }
7802
7803 @Override
sqian8c685422019-02-22 15:55:18 -08007804 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007805 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007806 if (!exactMatch) {
7807 TelephonyPermissions
7808 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007809 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007810 }
7811 final long identity = Binder.clearCallingIdentity();
7812 try {
sqian854d44b2018-12-12 16:48:18 -08007813 for (Phone phone: PhoneFactory.getPhones()) {
7814 if (phone.getEmergencyNumberTracker() != null
7815 && phone.getEmergencyNumberTracker() != null) {
7816 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7817 number, exactMatch)) {
7818 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007819 }
7820 }
sqian11b7a0e2018-12-05 18:48:28 -08007821 }
7822 return false;
7823 } finally {
7824 Binder.restoreCallingIdentity(identity);
7825 }
7826 }
7827
sqianf4ca7ed2019-01-15 18:32:07 -08007828 /**
7829 * Update emergency number list for test mode.
7830 */
7831 @Override
7832 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7833 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7834 "updateEmergencyNumberListTestMode");
7835
7836 final long identity = Binder.clearCallingIdentity();
7837 try {
7838 for (Phone phone: PhoneFactory.getPhones()) {
7839 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7840 if (tracker != null) {
7841 tracker.executeEmergencyNumberTestModeCommand(action, num);
7842 }
7843 }
7844 } finally {
7845 Binder.restoreCallingIdentity(identity);
7846 }
7847 }
7848
7849 /**
7850 * Get the full emergency number list for test mode.
7851 */
7852 @Override
7853 public List<String> getEmergencyNumberListTestMode() {
7854 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7855 "getEmergencyNumberListTestMode");
7856
7857 final long identity = Binder.clearCallingIdentity();
7858 try {
7859 Set<String> emergencyNumbers = new HashSet<>();
7860 for (Phone phone: PhoneFactory.getPhones()) {
7861 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7862 if (tracker != null) {
7863 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7864 emergencyNumbers.add(num.getNumber());
7865 }
7866 }
7867 }
7868 return new ArrayList<>(emergencyNumbers);
7869 } finally {
7870 Binder.restoreCallingIdentity(identity);
7871 }
7872 }
7873
chen xud6b45bd2018-10-30 22:27:10 -07007874 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007875 public int getEmergencyNumberDbVersion(int subId) {
7876 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7877
7878 final long identity = Binder.clearCallingIdentity();
7879 try {
7880 final Phone phone = getPhone(subId);
7881 if (phone == null) {
7882 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7883 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7884 }
7885 return phone.getEmergencyNumberDbVersion();
7886 } finally {
7887 Binder.restoreCallingIdentity(identity);
7888 }
7889 }
7890
7891 @Override
7892 public void notifyOtaEmergencyNumberDbInstalled() {
7893 enforceModifyPermission();
7894
7895 final long identity = Binder.clearCallingIdentity();
7896 try {
7897 for (Phone phone: PhoneFactory.getPhones()) {
7898 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7899 if (tracker != null) {
7900 tracker.updateOtaEmergencyNumberDatabase();
7901 }
7902 }
7903 } finally {
7904 Binder.restoreCallingIdentity(identity);
7905 }
7906 }
7907
7908 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08007909 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08007910 enforceActiveEmergencySessionPermission();
7911
7912 final long identity = Binder.clearCallingIdentity();
7913 try {
7914 for (Phone phone: PhoneFactory.getPhones()) {
7915 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7916 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08007917 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7918 }
7919 }
7920 } finally {
7921 Binder.restoreCallingIdentity(identity);
7922 }
7923 }
7924
7925 @Override
7926 public void resetOtaEmergencyNumberDbFilePath() {
7927 enforceActiveEmergencySessionPermission();
7928
7929 final long identity = Binder.clearCallingIdentity();
7930 try {
7931 for (Phone phone: PhoneFactory.getPhones()) {
7932 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7933 if (tracker != null) {
7934 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08007935 }
7936 }
7937 } finally {
7938 Binder.restoreCallingIdentity(identity);
7939 }
7940 }
7941
7942 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007943 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7944 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7945 Phone phone = getPhone(subId);
7946 if (phone == null) {
7947 return null;
7948 }
7949 final long identity = Binder.clearCallingIdentity();
7950 try {
7951 UiccProfile profile = UiccController.getInstance()
7952 .getUiccProfileForPhone(phone.getPhoneId());
7953 if (profile != null) {
7954 return profile.getCertsFromCarrierPrivilegeAccessRules();
7955 }
7956 } finally {
7957 Binder.restoreCallingIdentity(identity);
7958 }
7959 return null;
7960 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007961
7962 /**
7963 * Enable or disable a modem stack.
7964 */
7965 @Override
7966 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7967 enforceModifyPermission();
7968
7969 final long identity = Binder.clearCallingIdentity();
7970 try {
7971 Phone phone = PhoneFactory.getPhone(slotIndex);
7972 if (phone == null) {
7973 return false;
7974 } else {
7975 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7976 }
7977 } finally {
7978 Binder.restoreCallingIdentity(identity);
7979 }
7980 }
Michelecea4cf22018-12-21 15:00:11 -08007981
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007982 /**
7983 * Whether a modem stack is enabled or not.
7984 */
7985 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007986 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7987 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007988 Phone phone = PhoneFactory.getPhone(slotIndex);
7989 if (phone == null) return false;
7990
7991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007992 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7993 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007994 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7995 }
7996
7997 final long identity = Binder.clearCallingIdentity();
7998 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007999 try {
8000 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8001 } catch (NoSuchElementException ex) {
8002 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8003 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008004 } finally {
8005 Binder.restoreCallingIdentity(identity);
8006 }
8007 }
8008
Michelecea4cf22018-12-21 15:00:11 -08008009 @Override
Michele0ea7d782019-03-19 14:58:42 -07008010 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008011 enforceModifyPermission();
8012
8013 final long identity = Binder.clearCallingIdentity();
8014 try {
8015 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008016 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008017 .commit();
8018 } finally {
8019 Binder.restoreCallingIdentity(identity);
8020 }
8021 }
8022
8023 @Override
Michele0ea7d782019-03-19 14:58:42 -07008024 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008025 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008026 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008027 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8028 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008029 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008030 }
Michelecea4cf22018-12-21 15:00:11 -08008031
8032 final long identity = Binder.clearCallingIdentity();
8033 try {
Michele0ea7d782019-03-19 14:58:42 -07008034 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008035 } finally {
8036 Binder.restoreCallingIdentity(identity);
8037 }
8038 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008039
Michele0ea7d782019-03-19 14:58:42 -07008040 @TelephonyManager.IsMultiSimSupportedResult
8041 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008042 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8043 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8044 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008045 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8046 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008047 }
8048 // Check if the hardware supports multisim functionality. If usage of multisim is not
8049 // supported by the modem, indicate that it is restricted.
8050 PhoneCapability staticCapability =
8051 mPhoneConfigurationManager.getStaticPhoneCapability();
8052 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008053 loge("isMultiSimSupportedInternal: no static configuration available");
8054 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008055 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008056 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008057 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8058 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008059 }
8060 // Check if support of multiple SIMs is restricted by carrier
8061 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008062 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008063 }
8064
Michele0ea7d782019-03-19 14:58:42 -07008065 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008066 }
8067
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008068 /**
8069 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008070 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8071 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8072 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008073 * @param numOfSims number of active sims we want to switch to
8074 */
8075 @Override
8076 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008077 if (numOfSims == 1) {
8078 enforceModifyPermission();
8079 } else {
8080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8081 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8082 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008083 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008084
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008085 try {
Michele30b57b22019-03-01 12:01:14 -08008086 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008087 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008088 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8089 return;
8090 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008091 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8092 } finally {
8093 Binder.restoreCallingIdentity(identity);
8094 }
8095 }
8096
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008097 @Override
8098 public boolean isApplicationOnUicc(int subId, int appType) {
8099 enforceReadPrivilegedPermission("isApplicationOnUicc");
8100 Phone phone = getPhone(subId);
8101 if (phone == null) {
8102 return false;
8103 }
8104 final long identity = Binder.clearCallingIdentity();
8105 try {
8106 UiccCard uiccCard = phone.getUiccCard();
8107 if (uiccCard == null) {
8108 return false;
8109 }
8110 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8111 if (uiccProfile == null) {
8112 return false;
8113 }
8114 if (TelephonyManager.APPTYPE_SIM <= appType
8115 && appType <= TelephonyManager.APPTYPE_ISIM) {
8116 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8117 }
8118 return false;
8119 } finally {
8120 Binder.restoreCallingIdentity(identity);
8121 }
8122 }
8123
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008124 /**
chen xub4baa772019-04-03 10:23:41 -07008125 * Get whether making changes to modem configurations will trigger reboot.
8126 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008127 */
8128 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008129 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8130 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008131 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008132 mApp, subId, callingPackage, callingFeatureId,
8133 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008134 return false;
8135 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008136 final long identity = Binder.clearCallingIdentity();
8137 try {
8138 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8139 } finally {
8140 Binder.restoreCallingIdentity(identity);
8141 }
8142 }
8143
Nathan Harold29f5f052019-02-15 13:41:57 -08008144 private void updateModemStateMetrics() {
8145 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8146 // TODO: check the state for each modem if the api is ready.
8147 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8148 }
8149
Pengquan Meng3889a572019-01-23 11:16:29 -08008150 @Override
8151 public int[] getSlotsMapping() {
8152 enforceReadPrivilegedPermission("getSlotsMapping");
8153
8154 final long identity = Binder.clearCallingIdentity();
8155 try {
8156 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8157 // All logical slots should have a mapping to a physical slot.
8158 int[] logicalSlotsMapping = new int[phoneCount];
8159 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8160 for (int i = 0; i < slotInfos.length; i++) {
8161 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8162 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8163 }
8164 }
8165 return logicalSlotsMapping;
8166 } finally {
8167 Binder.restoreCallingIdentity(identity);
8168 }
8169 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008170
8171 /**
8172 * Get the IRadio HAL Version
8173 */
8174 @Override
8175 public int getRadioHalVersion() {
8176 Phone phone = getDefaultPhone();
8177 if (phone == null) return -1;
8178 HalVersion hv = phone.getHalVersion();
8179 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8180 return hv.major * 100 + hv.minor;
8181 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008182
8183 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008184 * Get the current calling package name.
8185 * @return the current calling package name
8186 */
8187 @Override
8188 public String getCurrentPackageName() {
8189 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8190 }
8191
8192 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008193 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8194 * corresponding network requests on a subId.
8195 *
8196 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008197 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008198 * 2) APN is un-metered for this subscription, or
8199 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008200 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008201 *
8202 * @return whether data is allowed for a apn type.
8203 *
8204 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008205 */
8206 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008207 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008208 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8209 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008210
8211 // Now that all security checks passes, perform the operation as ourselves.
8212 final long identity = Binder.clearCallingIdentity();
8213 try {
8214 Phone phone = getPhone(subId);
8215 if (phone == null) return false;
8216
Jack Yu41407ee2019-05-13 16:54:09 -07008217 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008218 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8219 } finally {
8220 Binder.restoreCallingIdentity(identity);
8221 }
8222 }
8223
8224 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008225 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008226 enforceReadPrivilegedPermission("isApnMetered");
8227
8228 // Now that all security checks passes, perform the operation as ourselves.
8229 final long identity = Binder.clearCallingIdentity();
8230 try {
8231 Phone phone = getPhone(subId);
8232 if (phone == null) return true; // By default return true.
8233
Jack Yu41407ee2019-05-13 16:54:09 -07008234 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008235 } finally {
8236 Binder.restoreCallingIdentity(identity);
8237 }
8238 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008239
8240 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008241 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8242 int subscriptionId, IBooleanConsumer resultCallback) {
8243 enforceModifyPermission();
8244 long token = Binder.clearCallingIdentity();
8245 try {
8246 Phone phone = getPhone(subscriptionId);
8247 if (phone == null) {
8248 try {
8249 if (resultCallback != null) {
8250 resultCallback.accept(false);
8251 }
8252 } catch (RemoteException e) {
8253 // ignore
8254 }
8255 return;
8256 }
8257 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8258 Pair.create(specifiers, (x) -> {
8259 try {
8260 if (resultCallback != null) {
8261 resultCallback.accept(x);
8262 }
8263 } catch (RemoteException e) {
8264 // ignore
8265 }
8266 });
8267 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8268 } finally {
8269 Binder.restoreCallingIdentity(token);
8270 }
8271 }
8272
8273 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008274 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8275 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8276 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8277 if (iccRecords == null) {
8278 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8279 return false;
8280 }
8281 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8282 }
8283
8284 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008285 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8286 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008287 if (callingPackage == null) {
8288 callingPackage = getCurrentPackageName();
8289 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008290 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8291 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008292 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8293 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008294 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8295 }
8296 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8297 Intent intent = new Intent();
8298 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8299 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8300 // Bring up choose default SMS subscription dialog right now
8301 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8302 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8303 mApp.startActivity(intent);
8304 }
chen xud5ca2d52019-05-28 15:20:57 -07008305
8306 @Override
8307 public String getMmsUAProfUrl(int subId) {
8308 //TODO investigate if this API should require proper permission check in R b/133791609
8309 final long identity = Binder.clearCallingIdentity();
8310 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008311 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8312 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8313 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8314 return carrierUAProfUrl;
8315 }
chen xud5ca2d52019-05-28 15:20:57 -07008316 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8317 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8318 } finally {
8319 Binder.restoreCallingIdentity(identity);
8320 }
8321 }
8322
8323 @Override
8324 public String getMmsUserAgent(int subId) {
8325 //TODO investigate if this API should require proper permission check in R b/133791609
8326 final long identity = Binder.clearCallingIdentity();
8327 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008328 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8329 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8330 if (!TextUtils.isEmpty(carrierUserAgent)) {
8331 return carrierUserAgent;
8332 }
chen xud5ca2d52019-05-28 15:20:57 -07008333 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8334 .getString(com.android.internal.R.string.config_mms_user_agent);
8335 } finally {
8336 Binder.restoreCallingIdentity(identity);
8337 }
8338 }
Jack Yub07d4972019-05-28 16:12:25 -07008339
8340 @Override
8341 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8342 enforceModifyPermission();
8343
8344 // Now that all security checks passes, perform the operation as ourselves.
8345 final long identity = Binder.clearCallingIdentity();
8346 try {
8347 Phone phone = getPhone(subId);
8348 if (phone == null) return false;
8349
8350 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8351 } finally {
8352 Binder.restoreCallingIdentity(identity);
8353 }
8354 }
8355
8356 @Override
8357 public boolean isDataAllowedInVoiceCall(int subId) {
8358 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8359
8360 // Now that all security checks passes, perform the operation as ourselves.
8361 final long identity = Binder.clearCallingIdentity();
8362 try {
8363 Phone phone = getPhone(subId);
8364 if (phone == null) return false;
8365
8366 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8367 } finally {
8368 Binder.restoreCallingIdentity(identity);
8369 }
8370 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008371
changbetty97defcf2019-12-24 15:40:37 +08008372 @Override
8373 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8374 enforceModifyPermission();
8375
8376 // Now that all security checks passes, perform the operation as ourselves.
8377 final long identity = Binder.clearCallingIdentity();
8378 try {
8379 Phone phone = getPhone(subId);
8380 if (phone == null) return false;
8381
8382 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8383 } finally {
8384 Binder.restoreCallingIdentity(identity);
8385 }
8386 }
8387
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008388 /**
8389 * Updates whether conference event pacakge handling is enabled.
8390 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8391 * otherwise.
8392 */
8393 @Override
8394 public void setCepEnabled(boolean isCepEnabled) {
8395 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8396
8397 final long identity = Binder.clearCallingIdentity();
8398 try {
8399 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8400 for (Phone phone : PhoneFactory.getPhones()) {
8401 Phone defaultPhone = phone.getImsPhone();
8402 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8403 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8404 ImsPhoneCallTracker imsPhoneCallTracker =
8405 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8406 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8407 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8408 + imsPhone.getMsisdn());
8409 }
8410 }
8411 } finally {
8412 Binder.restoreCallingIdentity(identity);
8413 }
8414 }
allenwtsu46dcc572020-01-08 18:24:03 +08008415
8416 /**
8417 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8418 *
8419 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8420 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8421 * before being read.
8422 */
8423 @Override
8424 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8425 isCompressed) {
8426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8427 mApp, subId, "notifyRcsAutoConfigurationReceived");
8428 try {
8429 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8430 if (configBinder == null) {
8431 Rlog.e(LOG_TAG, "null result for getImsConfig");
8432 } else {
8433 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8434 }
8435 } catch (RemoteException e) {
8436 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8437 }
8438 }
zoey chenf95ca592019-12-30 16:11:23 +08008439
8440 @Override
8441 public boolean isIccLockEnabled(int subId) {
8442 enforceReadPrivilegedPermission("isIccLockEnabled");
8443
8444 // Now that all security checks passes, perform the operation as ourselves.
8445 final long identity = Binder.clearCallingIdentity();
8446 try {
8447 Phone phone = getPhone(subId);
8448 if (phone != null && phone.getIccCard() != null) {
8449 return phone.getIccCard().getIccLockEnabled();
8450 } else {
8451 return false;
8452 }
8453 } finally {
8454 Binder.restoreCallingIdentity(identity);
8455 }
8456 }
8457
8458 /**
8459 * Set the ICC pin lock enabled or disabled..
8460 *
8461 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8462 * 0 or a positive integer as the attempts remaining value.
8463 *
8464 */
8465 @Override
8466 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8467 enforceModifyPermission();
8468
8469 Phone phone = getPhone(subId);
8470 if (phone == null) {
8471 return 0;
8472 }
8473 // Now that all security checks passes, perform the operation as ourselves.
8474 final long identity = Binder.clearCallingIdentity();
8475 try {
8476 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8477 new Pair<Boolean, String>(enabled, password), phone, null);
8478 return attemptsRemaining;
8479
8480 } catch (Exception e) {
8481 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8482 } finally {
8483 Binder.restoreCallingIdentity(identity);
8484 }
8485 return 0;
8486 }
8487
8488 /**
8489 * Change the ICC password used in ICC pin lock.
8490 *
8491 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8492 * 0 or a positive integer as the attempts remaining value.
8493 *
8494 */
8495 @Override
8496 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8497 enforceModifyPermission();
8498
8499 Phone phone = getPhone(subId);
8500 if (phone == null) {
8501 return 0;
8502 }
8503 // Now that all security checks passes, perform the operation as ourselves.
8504 final long identity = Binder.clearCallingIdentity();
8505 try {
8506 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8507 new Pair<String, String>(oldPassword, newPassword), phone, null);
8508 return attemptsRemaining;
8509
8510 } catch (Exception e) {
8511 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8512 } finally {
8513 Binder.restoreCallingIdentity(identity);
8514 }
8515 return 0;
8516 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008517
8518 @Override
8519 public boolean canConnectTo5GInDsdsMode() {
8520 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008522}