blob: 4ee4141c3bea58ee46fe342925b37225c3a7a5d0 [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;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
sqian80370722020-01-29 15:02:51 -080067import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700108import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700109import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800110import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800111import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800113import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700116import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800119
Andrew Lee312e8172014-10-23 17:01:36 -0700120import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800121import com.android.ims.internal.IImsServiceFeatureCallback;
sqian80370722020-01-29 15:02:51 -0800122import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800129import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800131import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800132import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700133import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700134import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800135import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800137import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700138import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700139import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700140import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700142import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800143import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700144import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700145import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700146import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700147import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700148import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700149import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700150import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700151import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800152import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800153import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800154import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700155import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800156import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700157import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800158import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700159import com.android.internal.telephony.imsphone.ImsPhone;
160import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800161import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900162import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800164import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700167import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800168import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800170import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000171import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800172import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700173import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700174import com.android.internal.util.FunctionalUtils;
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;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800194import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800195import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197/**
198 * Implementation of the ITelephony interface.
199 */
Santos Cordon117fee72014-05-16 17:56:12 -0700200public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 private static final String LOG_TAG = "PhoneInterfaceManager";
202 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
203 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800204 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205
206 // Message codes used with mMainThreadHandler
207 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700208 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
209 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700210 private static final int CMD_OPEN_CHANNEL = 9;
211 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
212 private static final int CMD_CLOSE_CHANNEL = 11;
213 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800214 private static final int CMD_NV_READ_ITEM = 13;
215 private static final int EVENT_NV_READ_ITEM_DONE = 14;
216 private static final int CMD_NV_WRITE_ITEM = 15;
217 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
218 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
219 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700220 private static final int CMD_RESET_MODEM_CONFIG = 19;
221 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800222 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
223 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
224 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
225 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800226 private static final int CMD_SEND_ENVELOPE = 25;
227 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000228 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
229 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700230 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
231 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
232 private static final int CMD_EXCHANGE_SIM_IO = 31;
233 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800234 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
235 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700236 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
237 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700238 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
239 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700240 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
241 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
242 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
243 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700244 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
245 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
246 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
247 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700248 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800249 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
250 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000251 private static final int CMD_SWITCH_SLOTS = 50;
252 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700253 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
254 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
255 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
256 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
257 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
258 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
259 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
260 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700261 private static final int CMD_GET_ALL_CELL_INFO = 60;
262 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
263 private static final int CMD_GET_CELL_LOCATION = 62;
264 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_MODEM_REBOOT = 64;
266 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700267 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
268 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800269 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
270 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700271 private static final int CMD_GET_MODEM_STATUS = 70;
272 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700273 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
274 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700275 private static final int CMD_ERASE_MODEM_CONFIG = 74;
276 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800277 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
278 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
279 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
280 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800281 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
282 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800283 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800284 private static final int CMD_GET_CALL_FORWARDING = 83;
285 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
286 private static final int CMD_SET_CALL_FORWARDING = 85;
287 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
288 private static final int CMD_GET_CALL_WAITING = 87;
289 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
290 private static final int CMD_SET_CALL_WAITING = 89;
291 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700292 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
293 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
294 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
295 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800297 // Parameters of select command.
298 private static final int SELECT_COMMAND = 0xA4;
299 private static final int SELECT_P1 = 0x04;
300 private static final int SELECT_P2 = 0;
301 private static final int SELECT_P3 = 0x10;
302
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303 /** The singleton instance. */
304 private static PhoneInterfaceManager sInstance;
305
Wink Saville3ab207e2014-11-20 13:07:20 -0800306 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800307 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800308 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700309 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800310 private AppOpsManager mAppOps;
311 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800312 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800313 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700314 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315
Peter Wangdafb9ac2020-01-15 14:13:38 -0800316 /** User Activity */
317 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800318 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
319
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700320 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
321
Derek Tan97ebb422014-09-05 16:55:38 -0700322 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
323 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800324 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800325 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700326
Michelecea4cf22018-12-21 15:00:11 -0800327 // String to store multi SIM allowed
328 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
329
Derek Tan740e1672017-06-27 14:56:27 -0700330 // The AID of ISD-R.
331 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
332
yinxub1bed742017-04-17 11:45:04 -0700333 private NetworkScanRequestTracker mNetworkScanRequestTracker;
334
David Kelly5e06a7f2018-03-12 14:10:59 +0000335 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
336 private static final int MANUFACTURER_CODE_LENGTH = 8;
337
Derek Tan89e89d42014-07-08 17:00:10 -0700338 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700339 * Experiment flag to enable erase modem config on reset network, default value is false
340 */
341 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
342 "reset_network_erase_modem_config_enabled";
343
344 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700345 * A request object to use for transmitting data to an ICC.
346 */
347 private static final class IccAPDUArgument {
348 public int channel, cla, command, p1, p2, p3;
349 public String data;
350
351 public IccAPDUArgument(int channel, int cla, int command,
352 int p1, int p2, int p3, String data) {
353 this.channel = channel;
354 this.cla = cla;
355 this.command = command;
356 this.p1 = p1;
357 this.p2 = p2;
358 this.p3 = p3;
359 this.data = data;
360 }
361 }
362
363 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700364 * A request object to use for transmitting data to an ICC.
365 */
366 private static final class ManualNetworkSelectionArgument {
367 public OperatorInfo operatorInfo;
368 public boolean persistSelection;
369
370 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
371 this.operatorInfo = operatorInfo;
372 this.persistSelection = persistSelection;
373 }
374 }
375
376 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
378 * request after sending. The main thread will notify the request when it is complete.
379 */
380 private static final class MainThreadRequest {
381 /** The argument to use for the request */
382 public Object argument;
383 /** The result of the request that is run on the main thread */
384 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800385 // The subscriber id that this request applies to. Defaults to
386 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
387 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388
Nathan Harold92bed182018-10-12 18:16:49 -0700389 // In cases where subId is unavailable, the caller needs to specify the phone.
390 public Phone phone;
391
vagdeviaf9a5b92018-08-15 16:01:53 -0700392 public WorkSource workSource;
393
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 public MainThreadRequest(Object argument) {
395 this.argument = argument;
396 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800397
Nathan Harold92bed182018-10-12 18:16:49 -0700398 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
399 this.argument = argument;
400 if (phone != null) {
401 this.phone = phone;
402 }
403 this.workSource = workSource;
404 }
405
vagdeviaf9a5b92018-08-15 16:01:53 -0700406 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800407 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800408 if (subId != null) {
409 this.subId = subId;
410 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700411 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 }
414
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800415 private static final class IncomingThirdPartyCallArgs {
416 public final ComponentName component;
417 public final String callId;
418 public final String callerDisplayName;
419
420 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
421 String callerDisplayName) {
422 this.component = component;
423 this.callId = callId;
424 this.callerDisplayName = callerDisplayName;
425 }
426 }
427
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428 /**
429 * A handler that processes messages on the main thread in the phone process. Since many
430 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
431 * inbound binder threads to the main thread in the phone process. The Binder thread
432 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
433 * on, which will be notified when the operation completes and will contain the result of the
434 * request.
435 *
436 * <p>If a MainThreadRequest object is provided in the msg.obj field,
437 * note that request.result must be set to something non-null for the calling thread to
438 * unblock.
439 */
440 private final class MainThreadHandler extends Handler {
441 @Override
442 public void handleMessage(Message msg) {
443 MainThreadRequest request;
444 Message onCompleted;
445 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800446 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800448 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449
450 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700451 case CMD_HANDLE_USSD_REQUEST: {
452 request = (MainThreadRequest) msg.obj;
453 final Phone phone = getPhoneFromRequest(request);
454 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
455 String ussdRequest = ussdObject.first;
456 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700457
Pengquan Menga1bb6272018-09-06 09:59:22 -0700458 if (!isUssdApiAllowed(request.subId)) {
459 // Carrier does not support use of this API, return failure.
460 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
461 UssdResponse response = new UssdResponse(ussdRequest, null);
462 Bundle returnData = new Bundle();
463 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
464 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700465
Pengquan Menga1bb6272018-09-06 09:59:22 -0700466 request.result = true;
467 notifyRequester(request);
468 return;
469 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700470
Pengquan Menga1bb6272018-09-06 09:59:22 -0700471 try {
472 request.result = phone != null
473 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
474 } catch (CallStateException cse) {
475 request.result = false;
476 }
477 // Wake up the requesting thread
478 notifyRequester(request);
479 break;
pkanwar32d516d2016-10-14 19:37:38 -0700480 }
481
Yorke Lee716f67e2015-06-17 15:39:16 -0700482 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700484 final Phone phone = getPhoneFromRequest(request);
485 request.result = phone != null ?
486 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
487 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700489 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700492
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800496 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700497 if (uiccCard == null) {
498 loge("iccTransmitApduLogicalChannel: No UICC");
499 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700500 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700501 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
503 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700504 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 iccArgument.channel, iccArgument.cla, iccArgument.command,
506 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700507 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700508 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700509 break;
510
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700511 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700512 ar = (AsyncResult) msg.obj;
513 request = (MainThreadRequest) ar.userObj;
514 if (ar.exception == null && ar.result != null) {
515 request.result = ar.result;
516 } else {
517 request.result = new IccIoResult(0x6F, 0, (byte[])null);
518 if (ar.result == null) {
519 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800520 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700521 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800522 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700523 } else {
524 loge("iccTransmitApduLogicalChannel: Unknown exception");
525 }
526 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700528 break;
529
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
531 request = (MainThreadRequest) msg.obj;
532 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800533 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 if (uiccCard == null) {
535 loge("iccTransmitApduBasicChannel: No UICC");
536 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700537 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 } else {
539 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
540 request);
541 uiccCard.iccTransmitApduBasicChannel(
542 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
543 iccArgument.p3, iccArgument.data, onCompleted);
544 }
545 break;
546
547 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
548 ar = (AsyncResult) msg.obj;
549 request = (MainThreadRequest) ar.userObj;
550 if (ar.exception == null && ar.result != null) {
551 request.result = ar.result;
552 } else {
553 request.result = new IccIoResult(0x6F, 0, (byte[])null);
554 if (ar.result == null) {
555 loge("iccTransmitApduBasicChannel: Empty response");
556 } else if (ar.exception instanceof CommandException) {
557 loge("iccTransmitApduBasicChannel: CommandException: " +
558 ar.exception);
559 } else {
560 loge("iccTransmitApduBasicChannel: Unknown exception");
561 }
562 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 break;
565
566 case CMD_EXCHANGE_SIM_IO:
567 request = (MainThreadRequest) msg.obj;
568 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800569 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 if (uiccCard == null) {
571 loge("iccExchangeSimIO: No UICC");
572 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 } else {
575 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
576 request);
577 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
578 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
579 iccArgument.data, onCompleted);
580 }
581 break;
582
583 case EVENT_EXCHANGE_SIM_IO_DONE:
584 ar = (AsyncResult) msg.obj;
585 request = (MainThreadRequest) ar.userObj;
586 if (ar.exception == null && ar.result != null) {
587 request.result = ar.result;
588 } else {
589 request.result = new IccIoResult(0x6f, 0, (byte[])null);
590 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 break;
593
Derek Tan4d5e5c12014-02-04 11:54:58 -0800594 case CMD_SEND_ENVELOPE:
595 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800596 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 if (uiccCard == null) {
598 loge("sendEnvelopeWithStatus: No UICC");
599 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 } else {
602 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
603 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
604 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800605 break;
606
607 case EVENT_SEND_ENVELOPE_DONE:
608 ar = (AsyncResult) msg.obj;
609 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700610 if (ar.exception == null && ar.result != null) {
611 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800612 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700613 request.result = new IccIoResult(0x6F, 0, (byte[])null);
614 if (ar.result == null) {
615 loge("sendEnvelopeWithStatus: Empty response");
616 } else if (ar.exception instanceof CommandException) {
617 loge("sendEnvelopeWithStatus: CommandException: " +
618 ar.exception);
619 } else {
620 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
621 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800622 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700623 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800624 break;
625
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 case CMD_OPEN_CHANNEL:
627 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800628 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800629 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 if (uiccCard == null) {
631 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800632 request.result = new IccOpenLogicalChannelResponse(-1,
633 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 } else {
636 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800637 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
638 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 break;
641
642 case EVENT_OPEN_CHANNEL_DONE:
643 ar = (AsyncResult) msg.obj;
644 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 int[] result = (int[]) ar.result;
648 int channelId = result[0];
649 byte[] selectResponse = null;
650 if (result.length > 1) {
651 selectResponse = new byte[result.length - 1];
652 for (int i = 1; i < result.length; ++i) {
653 selectResponse[i - 1] = (byte) result[i];
654 }
655 }
656 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700657 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 if (ar.result == null) {
660 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 if (ar.exception != null) {
663 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
664 }
665
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700666 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700667 if (ar.exception instanceof CommandException) {
668 CommandException.Error error =
669 ((CommandException) (ar.exception)).getCommandError();
670 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700671 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700672 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700673 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 }
675 }
676 openChannelResp = new IccOpenLogicalChannelResponse(
677 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700679 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700680 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 break;
682
683 case CMD_CLOSE_CHANNEL:
684 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800685 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 if (uiccCard == null) {
687 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900688 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700689 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700690 } else {
691 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
692 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
693 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 break;
695
696 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800697 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
698 break;
699
700 case CMD_NV_READ_ITEM:
701 request = (MainThreadRequest) msg.obj;
702 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800703 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
704 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800705 break;
706
707 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 ar = (AsyncResult) msg.obj;
709 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800710 if (ar.exception == null && ar.result != null) {
711 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800713 request.result = "";
714 if (ar.result == null) {
715 loge("nvReadItem: Empty response");
716 } else if (ar.exception instanceof CommandException) {
717 loge("nvReadItem: CommandException: " +
718 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800720 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 }
722 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700723 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 break;
725
Jake Hambye994d462014-02-03 13:10:13 -0800726 case CMD_NV_WRITE_ITEM:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
729 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800730 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700731 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800732 break;
733
734 case EVENT_NV_WRITE_ITEM_DONE:
735 handleNullReturnEvent(msg, "nvWriteItem");
736 break;
737
738 case CMD_NV_WRITE_CDMA_PRL:
739 request = (MainThreadRequest) msg.obj;
740 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800741 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800742 break;
743
744 case EVENT_NV_WRITE_CDMA_PRL_DONE:
745 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
746 break;
747
chen xu6dac5ab2018-10-26 17:39:23 -0700748 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800749 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700750 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800751 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800752 break;
753
chen xu6dac5ab2018-10-26 17:39:23 -0700754 case EVENT_RESET_MODEM_CONFIG_DONE:
755 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800756 break;
757
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700758 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
759 request = (MainThreadRequest) msg.obj;
760 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
761 request);
762 Phone phone = getPhoneFromRequest(request);
763 if (phone != null) {
764 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
765 } else {
766 loge("isNRDualConnectivityEnabled: No phone object");
767 request.result = false;
768 notifyRequester(request);
769 }
770 break;
771 }
772
773 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
774 ar = (AsyncResult) msg.obj;
775 request = (MainThreadRequest) ar.userObj;
776 if (ar.exception == null && ar.result != null) {
777 request.result = ar.result;
778 } else {
779 // request.result must be set to something non-null
780 // for the calling thread to unblock
781 if (request.result != null) {
782 request.result = ar.result;
783 } else {
784 request.result = false;
785 }
786 if (ar.result == null) {
787 loge("isNRDualConnectivityEnabled: Empty response");
788 } else if (ar.exception instanceof CommandException) {
789 loge("isNRDualConnectivityEnabled: CommandException: "
790 + ar.exception);
791 } else {
792 loge("isNRDualConnectivityEnabled: Unknown exception");
793 }
794 }
795 notifyRequester(request);
796 break;
797
798 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
801 Phone phone = getPhoneFromRequest(request);
802 if (phone != null) {
803 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
804 request.workSource);
805 } else {
806 loge("enableNrDualConnectivity: No phone object");
807 request.result =
808 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
809 notifyRequester(request);
810 }
811 break;
812 }
813
814 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
815 ar = (AsyncResult) msg.obj;
816 request = (MainThreadRequest) ar.userObj;
817 if (ar.exception == null) {
818 request.result =
819 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
820 } else {
821 request.result =
822 TelephonyManager
823 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
824 if (ar.exception instanceof CommandException) {
825 CommandException.Error error =
826 ((CommandException) (ar.exception)).getCommandError();
827 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
828 request.result =
829 TelephonyManager
830 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
831 }
832 loge("enableNrDualConnectivity" + ": CommandException: "
833 + ar.exception);
834 } else {
835 loge("enableNrDualConnectivity" + ": Unknown exception");
836 }
837 }
838 notifyRequester(request);
839 break;
840 }
841
Jake Hamby7c27be32014-03-03 13:25:59 -0800842 case CMD_GET_PREFERRED_NETWORK_TYPE:
843 request = (MainThreadRequest) msg.obj;
844 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700845 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800846 break;
847
848 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
849 ar = (AsyncResult) msg.obj;
850 request = (MainThreadRequest) ar.userObj;
851 if (ar.exception == null && ar.result != null) {
852 request.result = ar.result; // Integer
853 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530854 // request.result must be set to something non-null
855 // for the calling thread to unblock
856 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800857 if (ar.result == null) {
858 loge("getPreferredNetworkType: Empty response");
859 } else if (ar.exception instanceof CommandException) {
860 loge("getPreferredNetworkType: CommandException: " +
861 ar.exception);
862 } else {
863 loge("getPreferredNetworkType: Unknown exception");
864 }
865 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700866 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800867 break;
868
869 case CMD_SET_PREFERRED_NETWORK_TYPE:
870 request = (MainThreadRequest) msg.obj;
871 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
872 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700873 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800874 break;
875
876 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
877 handleNullReturnEvent(msg, "setPreferredNetworkType");
878 break;
879
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000880 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
881 request = (MainThreadRequest)msg.obj;
882 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800883 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000884 break;
885
886 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
887 ar = (AsyncResult)msg.obj;
888 request = (MainThreadRequest)ar.userObj;
889 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700890 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000891 break;
892
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800893 case CMD_SET_VOICEMAIL_NUMBER:
894 request = (MainThreadRequest) msg.obj;
895 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
896 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800897 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
898 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800899 break;
900
901 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
902 handleNullReturnEvent(msg, "setVoicemailNumber");
903 break;
904
Stuart Scott54788802015-03-30 13:18:01 -0700905 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
906 request = (MainThreadRequest) msg.obj;
907 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
908 request);
909 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
910 break;
911
912 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
913 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
914 break;
915
Shishir Agrawal302c8692015-06-19 13:49:39 -0700916 case CMD_PERFORM_NETWORK_SCAN:
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
919 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
920 break;
921
Hall Liua1acea22020-09-18 19:04:59 -0700922 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800923 request = (MainThreadRequest) msg.obj;
924 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700925 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
926 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
927 request.argument;
928 int callForwardingReason = args.first;
929 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800930 break;
Hall Liua1acea22020-09-18 19:04:59 -0700931 }
932 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800933 ar = (AsyncResult) msg.obj;
934 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700935 TelephonyManager.CallForwardingInfoCallback callback =
936 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
937 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800938 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700939 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800940 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
941 for (CallForwardInfo callForwardInfo : callForwardInfos) {
942 // Service Class is a bit mask per 3gpp 27.007. Search for
943 // any service for voice call.
944 if ((callForwardInfo.serviceClass
945 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700946 callForwardingInfo = new CallForwardingInfo(true,
947 callForwardInfo.reason,
948 callForwardInfo.number,
949 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800950 break;
951 }
952 }
953 // Didn't find a call forward info for voice call.
954 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700955 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
956 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800957 }
Hall Liua1acea22020-09-18 19:04:59 -0700958 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800959 } else {
960 if (ar.result == null) {
961 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
962 }
963 if (ar.exception != null) {
964 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
965 }
Hall Liuae527aa2020-09-29 17:10:18 -0700966 int errorCode = TelephonyManager
967 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800968 if (ar.exception instanceof CommandException) {
969 CommandException.Error error =
970 ((CommandException) (ar.exception)).getCommandError();
971 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -0700972 errorCode = TelephonyManager
973 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -0800974 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -0700975 errorCode = TelephonyManager
976 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -0800977 }
978 }
Hall Liua1acea22020-09-18 19:04:59 -0700979 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -0800980 }
sqian80370722020-01-29 15:02:51 -0800981 break;
Hall Liua1acea22020-09-18 19:04:59 -0700982 }
sqian80370722020-01-29 15:02:51 -0800983
Hall Liua1acea22020-09-18 19:04:59 -0700984 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800985 request = (MainThreadRequest) msg.obj;
986 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700987 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -0800988 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -0700989 ((Pair<CallForwardingInfo, Consumer<Integer>>)
990 request.argument).first;
991 request.phone.setCallForwardingOption(
992 callForwardingInfoToSet.isEnabled()
993 ? CommandsInterface.CF_ACTION_ENABLE
994 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -0800995 callForwardingInfoToSet.getReason(),
996 callForwardingInfoToSet.getNumber(),
997 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
998 break;
Hall Liua1acea22020-09-18 19:04:59 -0700999 }
sqian80370722020-01-29 15:02:51 -08001000
Hall Liua1acea22020-09-18 19:04:59 -07001001 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001004 Consumer<Integer> callback =
1005 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1006 request.argument).second;
1007 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001008 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001009 int errorCode = TelephonyManager.CallForwardingInfoCallback
1010 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001011 if (ar.exception instanceof CommandException) {
1012 CommandException.Error error =
1013 ((CommandException) (ar.exception)).getCommandError();
1014 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001015 errorCode = TelephonyManager.CallForwardingInfoCallback
1016 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001017 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001018 errorCode = TelephonyManager.CallForwardingInfoCallback
1019 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001020 }
1021 }
1022 callback.accept(errorCode);
1023 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001024 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001025 }
sqian80370722020-01-29 15:02:51 -08001026 break;
Hall Liua1acea22020-09-18 19:04:59 -07001027 }
sqian80370722020-01-29 15:02:51 -08001028
Hall Liua1acea22020-09-18 19:04:59 -07001029 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001030 request = (MainThreadRequest) msg.obj;
1031 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1032 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1033 break;
Hall Liua1acea22020-09-18 19:04:59 -07001034 }
sqian80370722020-01-29 15:02:51 -08001035
Hall Liua1acea22020-09-18 19:04:59 -07001036 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001039 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001040 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1041 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001042 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001043 // Service Class is a bit mask per 3gpp 27.007.
1044 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001045 if (callForwardResults.length > 1
1046 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001047 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001048 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001049 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1050 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001051 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001052 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001053 }
1054 } else {
1055 if (ar.result == null) {
1056 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1057 }
1058 if (ar.exception != null) {
1059 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1060 }
1061 if (ar.exception instanceof CommandException) {
1062 CommandException.Error error =
1063 ((CommandException) (ar.exception)).getCommandError();
1064 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1065 callForwardingStatus =
1066 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1067 }
1068 }
1069 }
Hall Liua1acea22020-09-18 19:04:59 -07001070 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001071 break;
Hall Liua1acea22020-09-18 19:04:59 -07001072 }
sqian80370722020-01-29 15:02:51 -08001073
Hall Liua1acea22020-09-18 19:04:59 -07001074 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001075 request = (MainThreadRequest) msg.obj;
1076 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001077 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1078 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001079 break;
Hall Liua1acea22020-09-18 19:04:59 -07001080 }
sqian80370722020-01-29 15:02:51 -08001081
Hall Liua1acea22020-09-18 19:04:59 -07001082 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001083 ar = (AsyncResult) msg.obj;
1084 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001085 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1086 Consumer<Integer> callback =
1087 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1088 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001089 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001090 if (ar.exception instanceof CommandException) {
1091 CommandException.Error error =
1092 ((CommandException) (ar.exception)).getCommandError();
1093 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1094 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1095 } else {
1096 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1097 }
1098 } else {
1099 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1100 }
1101 } else {
1102 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1103 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001104 }
sqian80370722020-01-29 15:02:51 -08001105 break;
Hall Liua1acea22020-09-18 19:04:59 -07001106 }
sqian80370722020-01-29 15:02:51 -08001107
Shishir Agrawal302c8692015-06-19 13:49:39 -07001108 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1109 ar = (AsyncResult) msg.obj;
1110 request = (MainThreadRequest) ar.userObj;
1111 CellNetworkScanResult cellScanResult;
1112 if (ar.exception == null && ar.result != null) {
1113 cellScanResult = new CellNetworkScanResult(
1114 CellNetworkScanResult.STATUS_SUCCESS,
1115 (List<OperatorInfo>) ar.result);
1116 } else {
1117 if (ar.result == null) {
1118 loge("getCellNetworkScanResults: Empty response");
1119 }
1120 if (ar.exception != null) {
1121 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1122 }
1123 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1124 if (ar.exception instanceof CommandException) {
1125 CommandException.Error error =
1126 ((CommandException) (ar.exception)).getCommandError();
1127 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1128 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1129 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1130 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1131 }
1132 }
1133 cellScanResult = new CellNetworkScanResult(errorCode, null);
1134 }
1135 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001136 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001137 break;
1138
1139 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1140 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001141 ManualNetworkSelectionArgument selArg =
1142 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001143 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1144 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001145 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1146 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001147 break;
1148
1149 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001150 ar = (AsyncResult) msg.obj;
1151 request = (MainThreadRequest) ar.userObj;
1152 if (ar.exception == null) {
1153 request.result = true;
1154 } else {
1155 request.result = false;
1156 loge("setNetworkSelectionModeManual " + ar.exception);
1157 }
1158 notifyRequester(request);
1159 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001160 break;
1161
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001162 case CMD_GET_MODEM_ACTIVITY_INFO:
1163 request = (MainThreadRequest) msg.obj;
1164 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001165 if (defaultPhone != null) {
1166 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001167 } else {
1168 ResultReceiver result = (ResultReceiver) request.argument;
1169 Bundle bundle = new Bundle();
1170 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1171 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1172 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001173 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001174 break;
1175
1176 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1177 ar = (AsyncResult) msg.obj;
1178 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001179 ResultReceiver result = (ResultReceiver) request.argument;
1180
1181 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001182 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001183 // Update the last modem activity info and the result of the request.
1184 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1185 if (isModemActivityInfoValid(info)) {
1186 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1187 int[] txTimeMs = info.getTransmitTimeMillis();
1188 int[] lastModemTxTimeMs = mLastModemActivityInfo
1189 .getTransmitTimeMillis();
1190 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1191 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1192 }
1193 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1194 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1195 + mLastModemActivityInfo.getSleepTimeMillis());
1196 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1197 + mLastModemActivityInfo.getIdleTimeMillis());
1198 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1199 mLastModemActivityInfo.setReceiveTimeMillis(
1200 info.getReceiveTimeMillis()
1201 + mLastModemActivityInfo.getReceiveTimeMillis());
1202 }
1203 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1204 mLastModemActivityInfo.getSleepTimeMillis(),
1205 mLastModemActivityInfo.getIdleTimeMillis(),
1206 mLastModemActivityInfo.getTransmitTimeMillis(),
1207 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001208 } else {
1209 if (ar.result == null) {
1210 loge("queryModemActivityInfo: Empty response");
1211 } else if (ar.exception instanceof CommandException) {
1212 loge("queryModemActivityInfo: CommandException: " +
1213 ar.exception);
1214 } else {
1215 loge("queryModemActivityInfo: Unknown exception");
1216 }
1217 }
sqian1a1be542020-03-05 11:37:28 -08001218 Bundle bundle = new Bundle();
1219 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1220 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001221 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001222 break;
1223
Meng Wang1a7c35a2016-05-05 20:56:15 -07001224 case CMD_SET_ALLOWED_CARRIERS:
1225 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001226 CarrierRestrictionRules argument =
1227 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001228 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001229 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001230 break;
1231
1232 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1233 ar = (AsyncResult) msg.obj;
1234 request = (MainThreadRequest) ar.userObj;
1235 if (ar.exception == null && ar.result != null) {
1236 request.result = ar.result;
1237 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001238 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1239 if (ar.exception instanceof CommandException) {
1240 loge("setAllowedCarriers: CommandException: " + ar.exception);
1241 CommandException.Error error =
1242 ((CommandException) (ar.exception)).getCommandError();
1243 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1244 request.result =
1245 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1246 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001247 } else {
1248 loge("setAllowedCarriers: Unknown exception");
1249 }
1250 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001251 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001252 break;
1253
1254 case CMD_GET_ALLOWED_CARRIERS:
1255 request = (MainThreadRequest) msg.obj;
1256 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001257 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001258 break;
1259
1260 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1261 ar = (AsyncResult) msg.obj;
1262 request = (MainThreadRequest) ar.userObj;
1263 if (ar.exception == null && ar.result != null) {
1264 request.result = ar.result;
1265 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001266 request.result = new IllegalStateException(
1267 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001268 if (ar.result == null) {
1269 loge("getAllowedCarriers: Empty response");
1270 } else if (ar.exception instanceof CommandException) {
1271 loge("getAllowedCarriers: CommandException: " +
1272 ar.exception);
1273 } else {
1274 loge("getAllowedCarriers: Unknown exception");
1275 }
1276 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001277 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001278 break;
1279
Nathan Haroldb3014052017-01-25 15:57:32 -08001280 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1281 ar = (AsyncResult) msg.obj;
1282 request = (MainThreadRequest) ar.userObj;
1283 if (ar.exception == null && ar.result != null) {
1284 request.result = ar.result;
1285 } else {
1286 request.result = new IllegalArgumentException(
1287 "Failed to retrieve Forbidden Plmns");
1288 if (ar.result == null) {
1289 loge("getForbiddenPlmns: Empty response");
1290 } else {
1291 loge("getForbiddenPlmns: Unknown exception");
1292 }
1293 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001294 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001295 break;
1296
1297 case CMD_GET_FORBIDDEN_PLMNS:
1298 request = (MainThreadRequest) msg.obj;
1299 uiccCard = getUiccCardFromRequest(request);
1300 if (uiccCard == null) {
1301 loge("getForbiddenPlmns() UiccCard is null");
1302 request.result = new IllegalArgumentException(
1303 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001304 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001305 break;
1306 }
1307 Integer appType = (Integer) request.argument;
1308 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1309 if (uiccApp == null) {
1310 loge("getForbiddenPlmns() no app with specified type -- "
1311 + appType);
1312 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001313 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001314 break;
1315 } else {
1316 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1317 + " specified type -- " + appType);
1318 }
1319 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1320 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1321 onCompleted);
1322 break;
1323
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001324 case CMD_SWITCH_SLOTS:
1325 request = (MainThreadRequest) msg.obj;
1326 int[] physicalSlots = (int[]) request.argument;
1327 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1328 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1329 break;
1330
1331 case EVENT_SWITCH_SLOTS_DONE:
1332 ar = (AsyncResult) msg.obj;
1333 request = (MainThreadRequest) ar.userObj;
1334 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001335 notifyRequester(request);
1336 break;
1337 case CMD_GET_NETWORK_SELECTION_MODE:
1338 request = (MainThreadRequest) msg.obj;
1339 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1340 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1341 break;
1342
1343 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1344 ar = (AsyncResult) msg.obj;
1345 request = (MainThreadRequest) ar.userObj;
1346 if (ar.exception != null) {
1347 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1348 } else {
1349 int mode = ((int[]) ar.result)[0];
1350 if (mode == 0) {
1351 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1352 } else {
1353 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1354 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001355 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001356 notifyRequester(request);
1357 break;
1358 case CMD_GET_CDMA_ROAMING_MODE:
1359 request = (MainThreadRequest) msg.obj;
1360 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1361 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1362 break;
1363 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1364 ar = (AsyncResult) msg.obj;
1365 request = (MainThreadRequest) ar.userObj;
1366 if (ar.exception != null) {
1367 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1368 } else {
1369 request.result = ((int[]) ar.result)[0];
1370 }
1371 notifyRequester(request);
1372 break;
1373 case CMD_SET_CDMA_ROAMING_MODE:
1374 request = (MainThreadRequest) msg.obj;
1375 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1376 int mode = (int) request.argument;
1377 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1378 break;
1379 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1380 ar = (AsyncResult) msg.obj;
1381 request = (MainThreadRequest) ar.userObj;
1382 request.result = ar.exception == null;
1383 notifyRequester(request);
1384 break;
1385 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1386 request = (MainThreadRequest) msg.obj;
1387 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1388 int subscriptionMode = (int) request.argument;
1389 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1390 break;
1391 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1392 ar = (AsyncResult) msg.obj;
1393 request = (MainThreadRequest) ar.userObj;
1394 request.result = ar.exception == null;
1395 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001396 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001397 case CMD_GET_ALL_CELL_INFO:
1398 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001399 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001400 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001401 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001402 case EVENT_GET_ALL_CELL_INFO_DONE:
1403 ar = (AsyncResult) msg.obj;
1404 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001405 // If a timeout occurs, the response will be null
1406 request.result = (ar.exception == null && ar.result != null)
1407 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001408 synchronized (request) {
1409 request.notifyAll();
1410 }
1411 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001412 case CMD_REQUEST_CELL_INFO_UPDATE:
1413 request = (MainThreadRequest) msg.obj;
1414 request.phone.requestCellInfoUpdate(request.workSource,
1415 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1416 break;
1417 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1418 ar = (AsyncResult) msg.obj;
1419 request = (MainThreadRequest) ar.userObj;
1420 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1421 try {
1422 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001423 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001424 cb.onError(
1425 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1426 ar.exception.getClass().getName(),
1427 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001428 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001429 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001430 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001431 } else {
1432 // use the result as returned
1433 cb.onCellInfo((List<CellInfo>) ar.result);
1434 }
1435 } catch (RemoteException re) {
1436 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1437 }
1438 break;
1439 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001440 request = (MainThreadRequest) msg.obj;
1441 WorkSource ws = (WorkSource) request.argument;
1442 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001443 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001444 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001445 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001446 ar = (AsyncResult) msg.obj;
1447 request = (MainThreadRequest) ar.userObj;
1448 if (ar.exception == null) {
1449 request.result = ar.result;
1450 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001451 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001452 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001453 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001454 }
1455
1456 synchronized (request) {
1457 request.notifyAll();
1458 }
1459 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001460 case CMD_MODEM_REBOOT:
1461 request = (MainThreadRequest) msg.obj;
1462 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001463 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001464 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001465 case EVENT_CMD_MODEM_REBOOT_DONE:
1466 handleNullReturnEvent(msg, "rebootModem");
1467 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001468 case CMD_REQUEST_ENABLE_MODEM:
1469 request = (MainThreadRequest) msg.obj;
1470 boolean enable = (boolean) request.argument;
1471 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001472 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001473 PhoneConfigurationManager.getInstance()
1474 .enablePhone(request.phone, enable, onCompleted);
1475 break;
1476 case EVENT_ENABLE_MODEM_DONE:
1477 ar = (AsyncResult) msg.obj;
1478 request = (MainThreadRequest) ar.userObj;
1479 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001480 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001481 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001482 if ((boolean) request.result) {
1483 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1484 updateModemStateMetrics();
1485 } else {
1486 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1487 + ar.exception);
1488 }
1489 notifyRequester(request);
1490 break;
1491 case CMD_GET_MODEM_STATUS:
1492 request = (MainThreadRequest) msg.obj;
1493 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1494 PhoneConfigurationManager.getInstance()
1495 .getPhoneStatusFromModem(request.phone, onCompleted);
1496 break;
1497 case EVENT_GET_MODEM_STATUS_DONE:
1498 ar = (AsyncResult) msg.obj;
1499 request = (MainThreadRequest) ar.userObj;
1500 int id = request.phone.getPhoneId();
1501 if (ar.exception == null && ar.result != null) {
1502 request.result = ar.result;
1503 //update the cache as modem status has changed
1504 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1505 (boolean) request.result);
1506 } else {
1507 // Return true if modem status cannot be retrieved. For most cases,
1508 // modem status is on. And for older version modems, GET_MODEM_STATUS
1509 // and disable modem are not supported. Modem is always on.
1510 // TODO: this should be fixed in R to support a third
1511 // status UNKNOWN b/131631629
1512 request.result = true;
1513 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1514 + ar.exception);
1515 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001516 notifyRequester(request);
1517 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001518 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1519 request = (MainThreadRequest) msg.obj;
1520 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1521 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1522 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1523 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1524 break;
1525 }
1526 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1527 ar = (AsyncResult) msg.obj;
1528 request = (MainThreadRequest) ar.userObj;
1529 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1530 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1531 args.second.accept(ar.exception == null);
1532 notifyRequester(request);
1533 break;
1534 }
yincheng zhaod698b842019-09-06 17:06:54 -07001535 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1536 ar = (AsyncResult) msg.obj;
1537 request = (MainThreadRequest) ar.userObj;
1538 if (ar.exception == null && ar.result != null) {
1539 request.result = ar.result;
1540 } else {
1541 request.result = -1;
1542 loge("Failed to set Forbidden Plmns");
1543 if (ar.result == null) {
1544 loge("setForbidenPlmns: Empty response");
1545 } else if (ar.exception != null) {
1546 loge("setForbiddenPlmns: Exception: " + ar.exception);
1547 request.result = -1;
1548 } else {
1549 loge("setForbiddenPlmns: Unknown exception");
1550 }
1551 }
1552 notifyRequester(request);
1553 break;
1554 case CMD_SET_FORBIDDEN_PLMNS:
1555 request = (MainThreadRequest) msg.obj;
1556 uiccCard = getUiccCardFromRequest(request);
1557 if (uiccCard == null) {
1558 loge("setForbiddenPlmns: UiccCard is null");
1559 request.result = -1;
1560 notifyRequester(request);
1561 break;
1562 }
1563 Pair<Integer, List<String>> setFplmnsArgs =
1564 (Pair<Integer, List<String>>) request.argument;
1565 appType = setFplmnsArgs.first;
1566 List<String> fplmns = setFplmnsArgs.second;
1567 uiccApp = uiccCard.getApplicationByType(appType);
1568 if (uiccApp == null) {
1569 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1570 request.result = -1;
1571 loge("Failed to get UICC App");
1572 notifyRequester(request);
1573 } else {
1574 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1575 ((SIMRecords) uiccApp.getIccRecords())
1576 .setForbiddenPlmns(onCompleted, fplmns);
1577 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001578 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001579 case CMD_ERASE_MODEM_CONFIG:
1580 request = (MainThreadRequest) msg.obj;
1581 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1582 defaultPhone.eraseModemConfig(onCompleted);
1583 break;
1584 case EVENT_ERASE_MODEM_CONFIG_DONE:
1585 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001586 break;
zoey chenf95ca592019-12-30 16:11:23 +08001587
1588 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1589 request = (MainThreadRequest) msg.obj;
1590 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1591 Pair<String, String> changed = (Pair<String, String>) request.argument;
1592 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1593 changed.first, changed.second, onCompleted);
1594 break;
1595 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1596 ar = (AsyncResult) msg.obj;
1597 request = (MainThreadRequest) ar.userObj;
1598 if (ar.exception == null) {
1599 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1600 } else {
1601 request.result = msg.arg1;
1602 }
1603 notifyRequester(request);
1604 break;
1605
1606 case CMD_SET_ICC_LOCK_ENABLED:
1607 request = (MainThreadRequest) msg.obj;
1608 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1609 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1610 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1611 enabled.first, enabled.second, onCompleted);
1612 break;
1613 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1614 ar = (AsyncResult) msg.obj;
1615 request = (MainThreadRequest) ar.userObj;
1616 if (ar.exception == null) {
1617 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1618 } else {
1619 request.result = msg.arg1;
1620 }
1621 notifyRequester(request);
1622 break;
1623
Peter Wangdafb9ac2020-01-15 14:13:38 -08001624 case MSG_NOTIFY_USER_ACTIVITY:
1625 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001626 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001627 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1628 getDefaultPhone().getContext().sendBroadcastAsUser(
1629 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1630 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 default:
1632 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1633 break;
1634 }
1635 }
Jake Hambye994d462014-02-03 13:10:13 -08001636
Pengquan Menga1bb6272018-09-06 09:59:22 -07001637 private void notifyRequester(MainThreadRequest request) {
1638 synchronized (request) {
1639 request.notifyAll();
1640 }
1641 }
1642
Jake Hambye994d462014-02-03 13:10:13 -08001643 private void handleNullReturnEvent(Message msg, String command) {
1644 AsyncResult ar = (AsyncResult) msg.obj;
1645 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1646 if (ar.exception == null) {
1647 request.result = true;
1648 } else {
1649 request.result = false;
1650 if (ar.exception instanceof CommandException) {
1651 loge(command + ": CommandException: " + ar.exception);
1652 } else {
1653 loge(command + ": Unknown exception");
1654 }
1655 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001656 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
1659
1660 /**
1661 * Posts the specified command to be executed on the main thread,
1662 * waits for the request to complete, and returns the result.
1663 * @see #sendRequestAsync
1664 */
1665 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001666 return sendRequest(
1667 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001668 }
1669
1670 /**
1671 * Posts the specified command to be executed on the main thread,
1672 * waits for the request to complete, and returns the result.
1673 * @see #sendRequestAsync
1674 */
1675 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1676 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001677 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001678 }
1679
1680 /**
1681 * Posts the specified command to be executed on the main thread,
1682 * waits for the request to complete, and returns the result.
1683 * @see #sendRequestAsync
1684 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001685 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001686 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001687 }
1688
1689 /**
1690 * Posts the specified command to be executed on the main thread,
1691 * waits for the request to complete, and returns the result.
1692 * @see #sendRequestAsync
1693 */
Nathan Harold92bed182018-10-12 18:16:49 -07001694 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1695 return sendRequest(command, argument, subId, null, workSource);
1696 }
1697
1698 /**
1699 * Posts the specified command to be executed on the main thread,
1700 * waits for the request to complete, and returns the result.
1701 * @see #sendRequestAsync
1702 */
1703 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1704 return sendRequest(
1705 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1706 }
1707
1708 /**
1709 * Posts the specified command to be executed on the main thread,
1710 * waits for the request to complete, and returns the result.
1711 * @see #sendRequestAsync
1712 */
1713 private Object sendRequest(
1714 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1716 throw new RuntimeException("This method will deadlock if called from the main thread.");
1717 }
1718
Nathan Harold92bed182018-10-12 18:16:49 -07001719 MainThreadRequest request = null;
1720 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1721 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1722 } else if (phone != null) {
1723 request = new MainThreadRequest(argument, phone, workSource);
1724 } else {
1725 request = new MainThreadRequest(argument, subId, workSource);
1726 }
1727
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 Message msg = mMainThreadHandler.obtainMessage(command, request);
1729 msg.sendToTarget();
1730
1731 // Wait for the request to complete
1732 synchronized (request) {
1733 while (request.result == null) {
1734 try {
1735 request.wait();
1736 } catch (InterruptedException e) {
1737 // Do nothing, go back and wait until the request is complete
1738 }
1739 }
1740 }
1741 return request.result;
1742 }
1743
1744 /**
1745 * Asynchronous ("fire and forget") version of sendRequest():
1746 * Posts the specified command to be executed on the main thread, and
1747 * returns immediately.
1748 * @see #sendRequest
1749 */
1750 private void sendRequestAsync(int command) {
1751 mMainThreadHandler.sendEmptyMessage(command);
1752 }
1753
1754 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001755 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001756 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001757 */
1758 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001759 sendRequestAsync(command, argument, null, null);
1760 }
1761
1762 /**
1763 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1764 * @see {@link #sendRequest(int,Object)}
1765 */
1766 private void sendRequestAsync(
1767 int command, Object argument, Phone phone, WorkSource workSource) {
1768 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001769 Message msg = mMainThreadHandler.obtainMessage(command, request);
1770 msg.sendToTarget();
1771 }
1772
1773 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 * Initialize the singleton PhoneInterfaceManager instance.
1775 * This is only done once, at startup, from PhoneApp.onCreate().
1776 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001777 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 synchronized (PhoneInterfaceManager.class) {
1779 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001780 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 } else {
1782 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1783 }
1784 return sInstance;
1785 }
1786 }
1787
1788 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001789 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001792 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001793 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1795 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001796 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001797 mTelephonySharedPreferences =
1798 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001799 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001800 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001801 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001802
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 publish();
1804 }
1805
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001806 private Phone getDefaultPhone() {
1807 Phone thePhone = getPhone(getDefaultSubscription());
1808 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1809 }
1810
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 private void publish() {
1812 if (DBG) log("publish: " + this);
1813
Peter Wangc035ce42020-01-08 21:00:22 -08001814 TelephonyFrameworkInitializer
1815 .getTelephonyServiceManager()
1816 .getTelephonyServiceRegisterer()
1817 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 }
1819
Stuart Scott584921c2015-01-15 17:10:34 -08001820 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001821 if (request.phone != null) {
1822 return request.phone;
1823 } else {
1824 return getPhoneFromSubId(request.subId);
1825 }
1826 }
1827
1828 private Phone getPhoneFromSubId(int subId) {
1829 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1830 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001831 }
1832
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001833 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1834 Phone phone = getPhoneFromRequest(request);
1835 return phone == null ? null :
1836 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1837 }
1838
Wink Saville36469e72014-06-11 15:17:00 -07001839 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001840 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001841 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001844 private void sendEraseModemConfig(Phone phone) {
1845 if (phone != null) {
1846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1847 mApp, phone.getSubId(), "eraseModemConfig");
1848 final long identity = Binder.clearCallingIdentity();
1849 try {
1850 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1851 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1852 } finally {
1853 Binder.restoreCallingIdentity(identity);
1854 }
1855 }
1856 }
1857
Peter Wang050bb052020-01-13 23:33:09 -08001858 private boolean isImsAvailableOnDevice() {
1859 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1860 if (pm == null) {
1861 // For some reason package manger is not available.. This will fail internally anyway,
1862 // so do not throw error and allow.
1863 return true;
1864 }
1865 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1866 }
1867
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001869 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001870 }
1871
Wink Savilleb564aae2014-10-23 10:18:09 -07001872 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 if (DBG) log("dial: " + number);
1874 // No permission check needed here: This is just a wrapper around the
1875 // ACTION_DIAL intent, which is available to any app since it puts up
1876 // the UI before it does anything.
1877
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001878 final long identity = Binder.clearCallingIdentity();
1879 try {
1880 String url = createTelUrl(number);
1881 if (url == null) {
1882 return;
1883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001885 // PENDING: should we just silently fail if phone is offhook or ringing?
1886 PhoneConstants.State state = mCM.getState(subId);
1887 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1888 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1889 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1890 mApp.startActivity(intent);
1891 }
1892 } finally {
1893 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 }
1895 }
1896
1897 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001898 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001899 }
1900
Wink Savilleb564aae2014-10-23 10:18:09 -07001901 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 if (DBG) log("call: " + number);
1903
1904 // This is just a wrapper around the ACTION_CALL intent, but we still
1905 // need to do a permission check since we're calling startActivity()
1906 // from the context of the phone app.
1907 enforceCallPermission();
1908
Jordan Liu1617b712019-07-10 15:06:26 -07001909 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 != AppOpsManager.MODE_ALLOWED) {
1911 return;
1912 }
1913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001914 final long identity = Binder.clearCallingIdentity();
1915 try {
1916 String url = createTelUrl(number);
1917 if (url == null) {
1918 return;
1919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001921 boolean isValid = false;
1922 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1923 if (slist != null) {
1924 for (SubscriptionInfo subInfoRecord : slist) {
1925 if (subInfoRecord.getSubscriptionId() == subId) {
1926 isValid = true;
1927 break;
1928 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001929 }
Wink Saville08874612014-08-31 19:19:58 -07001930 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001931 if (!isValid) {
1932 return;
1933 }
Wink Saville08874612014-08-31 19:19:58 -07001934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001935 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1936 intent.putExtra(SUBSCRIPTION_KEY, subId);
1937 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1938 mApp.startActivity(intent);
1939 } finally {
1940 Binder.restoreCallingIdentity(identity);
1941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
1943
Wink Savilleb564aae2014-10-23 10:18:09 -07001944 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001945 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001946 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1947 }
1948
Wink Savilleb564aae2014-10-23 10:18:09 -07001949 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001950 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001951 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1952 }
1953
Wink Savilleb564aae2014-10-23 10:18:09 -07001954 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001956
1957 final long identity = Binder.clearCallingIdentity();
1958 try {
1959 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1960 checkSimPin.start();
1961 return checkSimPin.unlockSim(null, pin);
1962 } finally {
1963 Binder.restoreCallingIdentity(identity);
1964 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001965 }
1966
Wink Savilleb564aae2014-10-23 10:18:09 -07001967 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001969
1970 final long identity = Binder.clearCallingIdentity();
1971 try {
1972 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1973 checkSimPuk.start();
1974 return checkSimPuk.unlockSim(puk, pin);
1975 } finally {
1976 Binder.restoreCallingIdentity(identity);
1977 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 }
1979
1980 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001981 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 * a synchronous one.
1983 */
1984 private static class UnlockSim extends Thread {
1985
1986 private final IccCard mSimCard;
1987
1988 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001989 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1990 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991
1992 // For replies from SimCard interface
1993 private Handler mHandler;
1994
1995 // For async handler to identify request type
1996 private static final int SUPPLY_PIN_COMPLETE = 100;
1997
1998 public UnlockSim(IccCard simCard) {
1999 mSimCard = simCard;
2000 }
2001
2002 @Override
2003 public void run() {
2004 Looper.prepare();
2005 synchronized (UnlockSim.this) {
2006 mHandler = new Handler() {
2007 @Override
2008 public void handleMessage(Message msg) {
2009 AsyncResult ar = (AsyncResult) msg.obj;
2010 switch (msg.what) {
2011 case SUPPLY_PIN_COMPLETE:
2012 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2013 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002014 mRetryCount = msg.arg1;
2015 if (ar.exception != null) {
2016 if (ar.exception instanceof CommandException &&
2017 ((CommandException)(ar.exception)).getCommandError()
2018 == CommandException.Error.PASSWORD_INCORRECT) {
2019 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002020 } //When UiccCardApp dispose,handle message and return exception
2021 else if (ar.exception instanceof CommandException &&
2022 ((CommandException) (ar.exception)).getCommandError()
2023 == CommandException.Error.ABORTED) {
2024 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002025 } else {
2026 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2027 }
2028 } else {
2029 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 mDone = true;
2032 UnlockSim.this.notifyAll();
2033 }
2034 break;
2035 }
2036 }
2037 };
2038 UnlockSim.this.notifyAll();
2039 }
2040 Looper.loop();
2041 }
2042
2043 /*
2044 * Use PIN or PUK to unlock SIM card
2045 *
2046 * If PUK is null, unlock SIM card with PIN
2047 *
2048 * If PUK is not null, unlock SIM card with PUK and set PIN code
2049 */
Wink Saville9de0f752013-10-22 19:04:03 -07002050 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051
2052 while (mHandler == null) {
2053 try {
2054 wait();
2055 } catch (InterruptedException e) {
2056 Thread.currentThread().interrupt();
2057 }
2058 }
2059 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2060
2061 if (puk == null) {
2062 mSimCard.supplyPin(pin, callback);
2063 } else {
2064 mSimCard.supplyPuk(puk, pin, callback);
2065 }
2066
2067 while (!mDone) {
2068 try {
2069 Log.d(LOG_TAG, "wait for done");
2070 wait();
2071 } catch (InterruptedException e) {
2072 // Restore the interrupted status
2073 Thread.currentThread().interrupt();
2074 }
2075 }
2076 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002077 int[] resultArray = new int[2];
2078 resultArray[0] = mResult;
2079 resultArray[1] = mRetryCount;
2080 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 }
2082 }
2083
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002084 /**
2085 * This method has been removed due to privacy and stability concerns.
2086 */
2087 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002089 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2090 return;
Wink Saville36469e72014-06-11 15:17:00 -07002091 }
2092
Nathan Harold1f889d82020-06-04 17:05:26 -07002093 @Override
2094 public void updateServiceLocationWithPackageName(String callingPackage) {
2095 mApp.getSystemService(AppOpsManager.class)
2096 .checkPackage(Binder.getCallingUid(), callingPackage);
2097
2098 final int targetSdk = getTargetSdk(callingPackage);
2099 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2100 // Callers targeting S have no business invoking this method.
2101 return;
2102 }
2103
2104 LocationAccessPolicy.LocationPermissionResult locationResult =
2105 LocationAccessPolicy.checkLocationPermission(mApp,
2106 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2107 .setCallingPackage(callingPackage)
2108 .setCallingFeatureId(null)
2109 .setCallingPid(Binder.getCallingPid())
2110 .setCallingUid(Binder.getCallingUid())
2111 .setMethod("updateServiceLocation")
2112 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2113 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2114 .build());
2115 // Apps that lack location permission have no business calling this method;
2116 // however, because no permission was declared in the public API, denials must
2117 // all be "soft".
2118 switch (locationResult) {
2119 case DENIED_HARD: /* fall through */
2120 case DENIED_SOFT:
2121 return;
2122 }
2123
2124 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002125 final long identity = Binder.clearCallingIdentity();
2126 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002127 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002128 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002129 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002130 }
2131 } finally {
2132 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002133 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 }
2135
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002136 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002137 @Override
2138 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002139 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002140 }
2141
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002142
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002143 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002144 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2145 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2146 callingFeatureId);
2147 }
2148
2149 @Deprecated
2150 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002151 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002152 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2153 }
2154
2155 @Override
2156 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2157 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002159 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002160 return false;
2161 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002162
2163 final long identity = Binder.clearCallingIdentity();
2164 try {
2165 return isRadioOnForSubscriber(subId);
2166 } finally {
2167 Binder.restoreCallingIdentity(identity);
2168 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002169 }
2170
2171 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002172 final long identity = Binder.clearCallingIdentity();
2173 try {
2174 final Phone phone = getPhone(subId);
2175 if (phone != null) {
2176 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2177 } else {
2178 return false;
2179 }
2180 } finally {
2181 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 }
2184
2185 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002186 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002187 }
Wink Saville36469e72014-06-11 15:17:00 -07002188
Wink Savilleb564aae2014-10-23 10:18:09 -07002189 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002191
2192 final long identity = Binder.clearCallingIdentity();
2193 try {
2194 final Phone phone = getPhone(subId);
2195 if (phone != null) {
2196 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2197 }
2198 } finally {
2199 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002200 }
Wink Saville36469e72014-06-11 15:17:00 -07002201 }
2202
2203 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002204 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002205 }
2206
Wink Savilleb564aae2014-10-23 10:18:09 -07002207 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002208 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209
2210 final long identity = Binder.clearCallingIdentity();
2211 try {
2212 final Phone phone = getPhone(subId);
2213 if (phone == null) {
2214 return false;
2215 }
2216 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2217 toggleRadioOnOffForSubscriber(subId);
2218 }
2219 return true;
2220 } finally {
2221 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002222 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 }
Wink Saville36469e72014-06-11 15:17:00 -07002224
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002225 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002226 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002227 /*
2228 * If any of the Radios are available, it will need to be
2229 * shutdown. So return true if any Radio is available.
2230 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002231 final long identity = Binder.clearCallingIdentity();
2232 try {
2233 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2234 Phone phone = PhoneFactory.getPhone(i);
2235 if (phone != null && phone.isRadioAvailable()) return true;
2236 }
2237 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2238 return false;
2239 } finally {
2240 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002241 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002242 }
2243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002244 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002245 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002246 enforceModifyPermission();
2247
2248 final long identity = Binder.clearCallingIdentity();
2249 try {
2250 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2251 logv("Shutting down Phone " + i);
2252 shutdownRadioUsingPhoneId(i);
2253 }
2254 } finally {
2255 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002256 }
2257 }
2258
2259 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002260 Phone phone = PhoneFactory.getPhone(phoneId);
2261 if (phone != null && phone.isRadioAvailable()) {
2262 phone.shutdownRadio();
2263 }
2264 }
2265
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002267 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002268
2269 final long identity = Binder.clearCallingIdentity();
2270 try {
2271 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2272 if (defaultPhone != null) {
2273 defaultPhone.setRadioPower(turnOn);
2274 return true;
2275 } else {
2276 loge("There's no default phone.");
2277 return false;
2278 }
2279 } finally {
2280 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002281 }
Wink Saville36469e72014-06-11 15:17:00 -07002282 }
2283
Wink Savilleb564aae2014-10-23 10:18:09 -07002284 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286
2287 final long identity = Binder.clearCallingIdentity();
2288 try {
2289 final Phone phone = getPhone(subId);
2290 if (phone != null) {
2291 phone.setRadioPower(turnOn);
2292 return true;
2293 } else {
2294 return false;
2295 }
2296 } finally {
2297 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 }
2300
Wink Saville36469e72014-06-11 15:17:00 -07002301 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002302 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 public boolean enableDataConnectivity() {
2304 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305
2306 final long identity = Binder.clearCallingIdentity();
2307 try {
2308 int subId = mSubscriptionController.getDefaultDataSubId();
2309 final Phone phone = getPhone(subId);
2310 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002311 phone.getDataEnabledSettings().setDataEnabled(
2312 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002313 return true;
2314 } else {
2315 return false;
2316 }
2317 } finally {
2318 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002319 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 }
2321
Wink Saville36469e72014-06-11 15:17:00 -07002322 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002323 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 public boolean disableDataConnectivity() {
2325 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326
2327 final long identity = Binder.clearCallingIdentity();
2328 try {
2329 int subId = mSubscriptionController.getDefaultDataSubId();
2330 final Phone phone = getPhone(subId);
2331 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002332 phone.getDataEnabledSettings().setDataEnabled(
2333 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002334 return true;
2335 } else {
2336 return false;
2337 }
2338 } finally {
2339 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 }
2342
Sanket Padawe356d7632015-06-22 14:03:32 -07002343 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002344 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002345 final long identity = Binder.clearCallingIdentity();
2346 try {
2347 final Phone phone = getPhone(subId);
2348 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002349 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002350 } else {
2351 return false;
2352 }
2353 } finally {
2354 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 }
2357
2358 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002359 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002360 }
2361
pkanwarae03a6b2016-11-06 20:37:09 -08002362 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002363 enforceCallPermission();
2364
2365 final long identity = Binder.clearCallingIdentity();
2366 try {
2367 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2368 return;
2369 }
2370 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2371 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2372 } finally {
2373 Binder.restoreCallingIdentity(identity);
2374 }
pkanwar32d516d2016-10-14 19:37:38 -07002375 };
2376
Wink Savilleb564aae2014-10-23 10:18:09 -07002377 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002379
2380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2383 return false;
2384 }
2385 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 }
2390
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002392 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002393 }
2394
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002395 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002396 final long identity = Binder.clearCallingIdentity();
2397 try {
2398 Phone phone = PhoneFactory.getPhone(slotIndex);
2399 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2400 PhoneConstantConversions.convertCallState(phone.getState());
2401 } finally {
2402 Binder.restoreCallingIdentity(identity);
2403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 }
2405
Sanket Padawe356d7632015-06-22 14:03:32 -07002406 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002407 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002408 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2409 }
2410
2411 @Override
2412 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002413 final long identity = Binder.clearCallingIdentity();
2414 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002415 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416 if (phone != null) {
2417 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2418 } else {
2419 return PhoneConstantConversions.convertDataState(
2420 PhoneConstants.DataState.DISCONNECTED);
2421 }
2422 } finally {
2423 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 }
2426
Sanket Padawe356d7632015-06-22 14:03:32 -07002427 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002428 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002429 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2430 }
2431
2432 @Override
2433 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434 final long identity = Binder.clearCallingIdentity();
2435 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002436 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437 if (phone != null) {
2438 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2439 } else {
2440 return TelephonyManager.DATA_ACTIVITY_NONE;
2441 }
2442 } finally {
2443 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 }
2446
2447 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002448 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002449 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002450 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002451
2452 LocationAccessPolicy.LocationPermissionResult locationResult =
2453 LocationAccessPolicy.checkLocationPermission(mApp,
2454 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2455 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002456 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002457 .setCallingPid(Binder.getCallingPid())
2458 .setCallingUid(Binder.getCallingUid())
2459 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002460 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002461 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2462 .build());
2463 switch (locationResult) {
2464 case DENIED_HARD:
2465 throw new SecurityException("Not allowed to access cell location");
2466 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002467 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2468 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 }
2470
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002471 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472 final long identity = Binder.clearCallingIdentity();
2473 try {
2474 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002475 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002476 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477 } finally {
2478 Binder.restoreCallingIdentity(identity);
2479 }
Svetoslav64fad262015-04-14 14:35:21 -07002480 }
2481
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 @Override
Jack Yu01425032020-02-22 19:38:58 -08002483 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002484 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2485 // registered cell info, so return a NULL country instead.
2486 final long identity = Binder.clearCallingIdentity();
2487 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002488 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2489 // Get default phone in this case.
2490 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2491 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002492 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002494 if (phone == null) return "";
2495 ServiceStateTracker sst = phone.getServiceStateTracker();
2496 if (sst == null) return "";
2497 LocaleTracker lt = sst.getLocaleTracker();
2498 if (lt == null) return "";
2499 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2500 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2501 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002502 } finally {
2503 Binder.restoreCallingIdentity(identity);
2504 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002505 }
2506
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002507 /**
2508 * This method was removed due to potential issues caused by performing partial
2509 * updates of service state, and lack of a credible use case.
2510 *
2511 * This has the ability to break the telephony implementation by disabling notification of
2512 * changes in device connectivity. DO NOT USE THIS!
2513 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002514 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 public void enableLocationUpdates() {
2516 mApp.enforceCallingOrSelfPermission(
2517 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 }
2519
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002520 /**
2521 * This method was removed due to potential issues caused by performing partial
2522 * updates of service state, and lack of a credible use case.
2523 *
2524 * This has the ability to break the telephony implementation by disabling notification of
2525 * changes in device connectivity. DO NOT USE THIS!
2526 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 @Override
2528 public void disableLocationUpdates() {
2529 mApp.enforceCallingOrSelfPermission(
2530 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 }
2532
Nathan Harold31d7ff32018-10-15 20:20:30 -07002533 /**
2534 * Returns the target SDK version number for a given package name.
2535 *
Nathan Haroldec184742019-07-10 17:04:16 -07002536 * This call MUST be invoked before clearing the calling UID.
2537 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002538 * @return target SDK if the package is found or INT_MAX.
2539 */
2540 private int getTargetSdk(String packageName) {
2541 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002542 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002543 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002544 if (ai != null) return ai.targetSdkVersion;
2545 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002546 loge("Failed to get package info for pkg="
2547 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002548 }
2549 return Integer.MAX_VALUE;
2550 }
2551
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 @Override
2553 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002554 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2555 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002556 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002557 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2558 throw new SecurityException(
2559 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2560 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002561
Jordan Liu1617b712019-07-10 15:06:26 -07002562 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2564 return null;
2565 }
Svetoslav64fad262015-04-14 14:35:21 -07002566
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002567 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002569 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002570 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571
Nathan Haroldf180aac2018-06-01 18:43:55 -07002572 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2573 for (CellInfo ci : info) {
2574 if (ci instanceof CellInfoGsm) {
2575 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2576 } else if (ci instanceof CellInfoWcdma) {
2577 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2578 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002579 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002580 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 }
2582
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002583 private List<CellInfo> getCachedCellInfo() {
2584 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2585 for (Phone phone : PhoneFactory.getPhones()) {
2586 List<CellInfo> info = phone.getAllCellInfo();
2587 if (info != null) cellInfos.addAll(info);
2588 }
2589 return cellInfos;
2590 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002591
2592 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002593 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002594 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002595 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002596
2597 LocationAccessPolicy.LocationPermissionResult locationResult =
2598 LocationAccessPolicy.checkLocationPermission(mApp,
2599 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2600 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002601 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002602 .setCallingPid(Binder.getCallingPid())
2603 .setCallingUid(Binder.getCallingUid())
2604 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002605 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002606 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2607 .build());
2608 switch (locationResult) {
2609 case DENIED_HARD:
2610 throw new SecurityException("Not allowed to access cell info");
2611 case DENIED_SOFT:
2612 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 }
2614
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002615 final int targetSdk = getTargetSdk(callingPackage);
2616 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2617 return getCachedCellInfo();
2618 }
2619
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002620 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002621 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 final long identity = Binder.clearCallingIdentity();
2623 try {
2624 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2625 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002626 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002627 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628 if (info != null) cellInfos.addAll(info);
2629 }
2630 return cellInfos;
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633 }
2634 }
2635
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002636 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002637 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2638 String callingFeatureId) {
2639 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2640 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002641 }
2642
2643 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002644 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2645 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002646 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002647 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002648 }
2649
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002650 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2651 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002652 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002653 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002654
2655 LocationAccessPolicy.LocationPermissionResult locationResult =
2656 LocationAccessPolicy.checkLocationPermission(mApp,
2657 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2658 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002659 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002660 .setCallingPid(Binder.getCallingPid())
2661 .setCallingUid(Binder.getCallingUid())
2662 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002663 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2664 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002665 .build());
2666 switch (locationResult) {
2667 case DENIED_HARD:
Hall Liuaa4283b2020-05-21 17:09:35 -07002668 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2669 // Safetynet logging for b/154934934
2670 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2671 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002672 throw new SecurityException("Not allowed to access cell info");
2673 case DENIED_SOFT:
Hall Liuaa4283b2020-05-21 17:09:35 -07002674 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2675 // Safetynet logging for b/154934934
2676 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2677 }
Nathan Harold5320c422019-05-09 10:26:08 -07002678 try {
2679 cb.onCellInfo(new ArrayList<CellInfo>());
2680 } catch (RemoteException re) {
2681 // Drop without consequences
2682 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002683 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002684 }
2685
Nathan Harolda939a962019-05-09 10:13:47 -07002686
2687 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002688 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2689
2690 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2691 }
2692
2693 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002695 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002696 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697
2698 final long identity = Binder.clearCallingIdentity();
2699 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002700 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701 } finally {
2702 Binder.restoreCallingIdentity(identity);
2703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 }
2705
Shishir Agrawala9f32182016-04-12 12:00:16 -07002706 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002707 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002708 Phone phone = PhoneFactory.getPhone(slotIndex);
2709 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002710 return null;
2711 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002712 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002713 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002714 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002715 return null;
2716 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717
2718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 return phone.getImei();
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
2723 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002724 }
2725
2726 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002727 public String getTypeAllocationCodeForSlot(int slotIndex) {
2728 Phone phone = PhoneFactory.getPhone(slotIndex);
2729 String tac = null;
2730 if (phone != null) {
2731 String imei = phone.getImei();
2732 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2733 }
2734 return tac;
2735 }
2736
2737 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002738 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002739 Phone phone = PhoneFactory.getPhone(slotIndex);
2740 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002741 return null;
2742 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002743
Jeff Davidson913390f2018-02-23 17:11:49 -08002744 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002745 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002746 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002747 return null;
2748 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 return phone.getMeid();
2753 } finally {
2754 Binder.restoreCallingIdentity(identity);
2755 }
Jack Yu2af8d712017-03-15 17:14:14 -07002756 }
2757
2758 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002759 public String getManufacturerCodeForSlot(int slotIndex) {
2760 Phone phone = PhoneFactory.getPhone(slotIndex);
2761 String manufacturerCode = null;
2762 if (phone != null) {
2763 String meid = phone.getMeid();
2764 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2765 }
2766 return manufacturerCode;
2767 }
2768
2769 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002770 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2771 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002772 Phone phone = PhoneFactory.getPhone(slotIndex);
2773 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002774 return null;
2775 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002776 int subId = phone.getSubId();
2777 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002778 mApp, subId, callingPackage, callingFeatureId,
2779 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002780 return null;
2781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782
2783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 return phone.getDeviceSvn();
2786 } finally {
2787 Binder.restoreCallingIdentity(identity);
2788 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002789 }
2790
fionaxu43304da2017-11-27 22:51:16 -08002791 @Override
2792 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793 final long identity = Binder.clearCallingIdentity();
2794 try {
2795 final Phone phone = getPhone(subId);
2796 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2797 } finally {
2798 Binder.restoreCallingIdentity(identity);
2799 }
fionaxu43304da2017-11-27 22:51:16 -08002800 }
2801
2802 @Override
2803 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 final long identity = Binder.clearCallingIdentity();
2805 try {
2806 final Phone phone = getPhone(subId);
2807 return phone == null ? null : phone.getCarrierName();
2808 } finally {
2809 Binder.restoreCallingIdentity(identity);
2810 }
fionaxu43304da2017-11-27 22:51:16 -08002811 }
2812
calvinpanffe225e2018-11-01 19:43:06 +08002813 @Override
chen xu0026ca62019-03-06 15:28:50 -08002814 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002815 final long identity = Binder.clearCallingIdentity();
2816 try {
2817 final Phone phone = getPhone(subId);
2818 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002819 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002820 } finally {
2821 Binder.restoreCallingIdentity(identity);
2822 }
2823 }
2824
2825 @Override
chen xu0026ca62019-03-06 15:28:50 -08002826 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002830 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002831 } finally {
2832 Binder.restoreCallingIdentity(identity);
2833 }
2834 }
2835
chen xu651eec72018-11-11 19:03:44 -08002836 @Override
chen xu864e11c2018-12-06 22:10:03 -08002837 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2838 if (!isSubscriptionMccMnc) {
2839 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2840 }
chen xu651eec72018-11-11 19:03:44 -08002841 final Phone phone = PhoneFactory.getPhone(slotIndex);
2842 if (phone == null) {
2843 return TelephonyManager.UNKNOWN_CARRIER_ID;
2844 }
2845 final long identity = Binder.clearCallingIdentity();
2846 try {
2847 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2848 } finally {
2849 Binder.restoreCallingIdentity(identity);
2850 }
2851 }
2852
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002853 //
2854 // Internal helper methods.
2855 //
2856
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002857 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002858 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2859 *
2860 * @throws SecurityException if the caller does not have the required permission
2861 */
2862 private void enforceModifyPermission() {
2863 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2864 }
2865
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002866 /**
2867 * Make sure the caller is system.
2868 *
2869 * @throws SecurityException if the caller is not system.
2870 */
2871 private void enforceSystemCaller() {
2872 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2873 throw new SecurityException("Caller must be system");
2874 }
2875 }
2876
Shuo Qianf2b2df42019-11-13 17:43:31 -08002877 private void enforceActiveEmergencySessionPermission() {
2878 mApp.enforceCallingOrSelfPermission(
2879 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2880 }
2881
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002882 /**
2883 * Make sure the caller has the CALL_PHONE permission.
2884 *
2885 * @throws SecurityException if the caller does not have the required permission
2886 */
2887 private void enforceCallPermission() {
2888 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2889 }
2890
paulhu423b5f22019-08-23 19:17:33 +08002891 private void enforceSettingsPermission() {
2892 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002893 }
2894
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 private String createTelUrl(String number) {
2896 if (TextUtils.isEmpty(number)) {
2897 return null;
2898 }
2899
Jake Hambye994d462014-02-03 13:10:13 -08002900 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901 }
2902
Ihab Awadf9e92732013-12-05 18:02:52 -08002903 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002904 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2905 }
2906
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002907 private static void logv(String msg) {
2908 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2909 }
2910
Ihab Awadf9e92732013-12-05 18:02:52 -08002911 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2913 }
2914
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002915 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002916 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002917 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002918 }
2919
Sanket Padawe356d7632015-06-22 14:03:32 -07002920 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002921 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 final long identity = Binder.clearCallingIdentity();
2923 try {
2924 final Phone phone = PhoneFactory.getPhone(slotIndex);
2925 if (phone == null) {
2926 return PhoneConstants.PHONE_TYPE_NONE;
2927 } else {
2928 return phone.getPhoneType();
2929 }
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 }
2934
2935 /**
2936 * Returns the CDMA ERI icon index to display
2937 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002938 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002939 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2940 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2941 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002942 }
2943
Sanket Padawe356d7632015-06-22 14:03:32 -07002944 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002945 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2946 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002947 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002948 mApp, subId, callingPackage, callingFeatureId,
2949 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002950 return -1;
2951 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002952
2953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 final Phone phone = getPhone(subId);
2956 if (phone != null) {
2957 return phone.getCdmaEriIconIndex();
2958 } else {
2959 return -1;
2960 }
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002963 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002964 }
2965
2966 /**
2967 * Returns the CDMA ERI icon mode,
2968 * 0 - ON
2969 * 1 - FLASHING
2970 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002971 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002972 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2973 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2974 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002975 }
2976
Sanket Padawe356d7632015-06-22 14:03:32 -07002977 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002978 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2979 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002980 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002981 mApp, subId, callingPackage, callingFeatureId,
2982 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002983 return -1;
2984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985
2986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 final Phone phone = getPhone(subId);
2989 if (phone != null) {
2990 return phone.getCdmaEriIconMode();
2991 } else {
2992 return -1;
2993 }
2994 } finally {
2995 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002997 }
2998
2999 /**
3000 * Returns the CDMA ERI text,
3001 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003002 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003003 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3004 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3005 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003006 }
3007
Sanket Padawe356d7632015-06-22 14:03:32 -07003008 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003009 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3010 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003012 mApp, subId, callingPackage, callingFeatureId,
3013 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003014 return null;
3015 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016
3017 final long identity = Binder.clearCallingIdentity();
3018 try {
3019 final Phone phone = getPhone(subId);
3020 if (phone != null) {
3021 return phone.getCdmaEriText();
3022 } else {
3023 return null;
3024 }
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003028 }
3029
3030 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003031 * Returns the CDMA MDN.
3032 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003033 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003034 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3036 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037
3038 final long identity = Binder.clearCallingIdentity();
3039 try {
3040 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003041 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003042 return phone.getLine1Number();
3043 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003044 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003045 return null;
3046 }
3047 } finally {
3048 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003049 }
3050 }
3051
3052 /**
3053 * Returns the CDMA MIN.
3054 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003055 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003056 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3058 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003059
3060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 final Phone phone = getPhone(subId);
3063 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3064 return phone.getCdmaMin();
3065 } else {
3066 return null;
3067 }
3068 } finally {
3069 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003070 }
3071 }
3072
Hall Liud892bec2018-11-30 14:51:45 -08003073 @Override
3074 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3075 INumberVerificationCallback callback, String callingPackage) {
3076 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3077 != PERMISSION_GRANTED) {
3078 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3079 }
3080 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3081
3082 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3083 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3084 throw new SecurityException("Calling package must be configured in the device config");
3085 }
3086
3087 if (range == null) {
3088 throw new NullPointerException("Range must be non-null");
3089 }
3090
3091 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003092 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003093
3094 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3095 }
3096
Junda Liuca05d5d2014-08-14 22:36:34 -07003097 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 * Returns true if CDMA provisioning needs to run.
3099 */
3100 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101 final long identity = Binder.clearCallingIdentity();
3102 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003103 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003104 } finally {
3105 Binder.restoreCallingIdentity(identity);
3106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003107 }
3108
3109 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003110 * Sets the voice mail number of a given subId.
3111 */
3112 @Override
3113 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003114 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3115 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116
3117 final long identity = Binder.clearCallingIdentity();
3118 try {
3119 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3120 new Pair<String, String>(alphaTag, number), new Integer(subId));
3121 return success;
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003125 }
3126
Ta-wei Yen87c49842016-05-13 21:19:52 -07003127 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003128 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3129 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003130 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3131 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003132 if (!TextUtils.equals(callingPackage, systemDialer)) {
3133 throw new SecurityException("caller must be system dialer");
3134 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003135
3136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3139 if (phoneAccountHandle == null) {
3140 return null;
3141 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003142 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003143 } finally {
3144 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003145 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003146 }
3147
3148 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003149 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3150 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003151 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003153 mApp, subId, callingPackage, callingFeatureId,
3154 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003155 return null;
3156 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003157
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003158 final long identity = Binder.clearCallingIdentity();
3159 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003160 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003161 } finally {
3162 Binder.restoreCallingIdentity(identity);
3163 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003164 }
3165
3166 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003167 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3168 VisualVoicemailSmsFilterSettings settings) {
3169 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170
3171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003174 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003175 } finally {
3176 Binder.restoreCallingIdentity(identity);
3177 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003178 }
3179
3180 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003181 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3182 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003183
3184 final long identity = Binder.clearCallingIdentity();
3185 try {
3186 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003187 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188 } finally {
3189 Binder.restoreCallingIdentity(identity);
3190 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003191 }
3192
3193 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003194 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3195 String callingPackage, int subId) {
3196 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197
3198 final long identity = Binder.clearCallingIdentity();
3199 try {
3200 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003201 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202 } finally {
3203 Binder.restoreCallingIdentity(identity);
3204 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003205 }
3206
3207 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003208 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003209 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210
3211 final long identity = Binder.clearCallingIdentity();
3212 try {
3213 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003214 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003218 }
3219
3220 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003221 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3222 String callingAttributionTag, int subId, String number, int port, String text,
3223 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003224 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003225 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003226 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003227 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003228 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3229 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003230 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003231
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003232 /**
fionaxu0152e512016-11-14 13:36:14 -08003233 * Sets the voice activation state of a given subId.
3234 */
3235 @Override
3236 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3238 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003239
3240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 final Phone phone = getPhone(subId);
3243 if (phone != null) {
3244 phone.setVoiceActivationState(activationState);
3245 } else {
3246 loge("setVoiceActivationState fails with invalid subId: " + subId);
3247 }
3248 } finally {
3249 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003250 }
3251 }
3252
3253 /**
3254 * Sets the data activation state of a given subId.
3255 */
3256 @Override
3257 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3259 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003260
3261 final long identity = Binder.clearCallingIdentity();
3262 try {
3263 final Phone phone = getPhone(subId);
3264 if (phone != null) {
3265 phone.setDataActivationState(activationState);
3266 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003267 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003268 }
3269 } finally {
3270 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003271 }
3272 }
3273
3274 /**
3275 * Returns the voice activation state of a given subId.
3276 */
3277 @Override
3278 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003279 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280
fionaxu0152e512016-11-14 13:36:14 -08003281 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 if (phone != null) {
3285 return phone.getVoiceActivationState();
3286 } else {
3287 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3288 }
3289 } finally {
3290 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003291 }
3292 }
3293
3294 /**
3295 * Returns the data activation state of a given subId.
3296 */
3297 @Override
3298 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003299 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003300
fionaxu0152e512016-11-14 13:36:14 -08003301 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003302 final long identity = Binder.clearCallingIdentity();
3303 try {
3304 if (phone != null) {
3305 return phone.getDataActivationState();
3306 } else {
3307 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3308 }
3309 } finally {
3310 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003311 }
3312 }
3313
3314 /**
Wink Saville36469e72014-06-11 15:17:00 -07003315 * Returns the unread count of voicemails for a subId
3316 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003317 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003318 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3319 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003321 mApp, subId, callingPackage, callingFeatureId,
3322 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003323 return 0;
3324 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003325 final long identity = Binder.clearCallingIdentity();
3326 try {
3327 final Phone phone = getPhone(subId);
3328 if (phone != null) {
3329 return phone.getVoiceMessageCount();
3330 } else {
3331 return 0;
3332 }
3333 } finally {
3334 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003336 }
3337
3338 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003339 * returns true, if the device is in a state where both voice and data
3340 * are supported simultaneously. This can change based on location or network condition.
3341 */
3342 @Override
3343 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 final Phone phone = getPhone(subId);
3347 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3348 } finally {
3349 Binder.restoreCallingIdentity(identity);
3350 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003351 }
3352
3353 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003354 * Send the dialer code if called from the current default dialer or the caller has
3355 * carrier privilege.
3356 * @param inputCode The dialer code to send
3357 */
3358 @Override
3359 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003360 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003361 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003362 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3363 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003364 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003365 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003366 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003367 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003368
3369 final long identity = Binder.clearCallingIdentity();
3370 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003371 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003372 } finally {
3373 Binder.restoreCallingIdentity(identity);
3374 }
fionaxu235cc5e2017-03-06 22:25:57 -08003375 }
3376
Pengquan Menga1bb6272018-09-06 09:59:22 -07003377 @Override
3378 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003379 TelephonyPermissions
3380 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3381 mApp, subId, "getNetworkSelectionMode");
3382 final long identity = Binder.clearCallingIdentity();
3383 try {
3384 if (!isActiveSubscription(subId)) {
3385 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3386 }
3387 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3388 } finally {
3389 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003390 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003391 }
3392
Brad Ebinger35c841c2018-10-01 10:40:55 -07003393 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003394 public boolean isInEmergencySmsMode() {
3395 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3396 final long identity = Binder.clearCallingIdentity();
3397 try {
3398 for (Phone phone : PhoneFactory.getPhones()) {
3399 if (phone.isInEmergencySmsMode()) {
3400 return true;
3401 }
3402 }
3403 } finally {
3404 Binder.restoreCallingIdentity(identity);
3405 }
3406 return false;
3407 }
3408
shilu366312e2019-12-17 09:28:10 -08003409 /**
3410 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3411 * @param subId The subscription to use to check the configuration.
3412 * @param c The callback that will be used to send the result.
3413 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003414 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003415 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3416 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003417 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3418 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003419
Brad Ebinger77b832e2019-10-17 17:03:22 -07003420 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3421 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3422 "IMS not available on device.");
3423 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003424 final long token = Binder.clearCallingIdentity();
3425 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003426 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003427 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003428 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003429 } catch (ImsException e) {
3430 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003431 } finally {
3432 Binder.restoreCallingIdentity(token);
3433 }
3434 }
3435
shilu366312e2019-12-17 09:28:10 -08003436 /**
3437 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3438 * @param subId The subscription to use to check the configuration.
3439 * @param c The callback that will be used to send the result.
3440 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003441 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003442 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003443 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3444 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003445 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3446 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3447 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003448 final long token = Binder.clearCallingIdentity();
3449 try {
3450 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3451 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3452 .removeRegistrationCallbackForSubscription(c, subId);
3453 } catch (ImsException e) {
3454 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3455 + "is inactive, ignoring unregister.");
3456 // If the subscription is no longer active, just return, since the callback
3457 // will already have been removed internally.
3458 } finally {
3459 Binder.restoreCallingIdentity(token);
3460 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003461 }
3462
Brad Ebinger774ba362019-10-22 17:36:18 -07003463 /**
3464 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3465 */
3466 @Override
3467 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3468 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
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 Phone phone = getPhone(subId);
3476 if (phone == null) {
3477 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3478 + subId + "'");
3479 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3480 }
3481 phone.getImsRegistrationState(regState -> {
3482 try {
3483 consumer.accept((regState == null)
3484 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3485 } catch (RemoteException e) {
3486 // Ignore if the remote process is no longer available to call back.
3487 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3488 }
3489 });
3490 } finally {
3491 Binder.restoreCallingIdentity(token);
3492 }
3493 }
3494
3495 /**
3496 * Get the transport type for the IMS service registration state.
3497 */
3498 @Override
3499 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003500 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3501 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003502 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3503 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3504 "IMS not available on device.");
3505 }
3506 final long token = Binder.clearCallingIdentity();
3507 try {
3508 Phone phone = getPhone(subId);
3509 if (phone == null) {
3510 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3511 + subId + "'");
3512 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3513 }
3514 phone.getImsRegistrationTech(regTech -> {
3515 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3516 int regTechConverted = (regTech == null)
3517 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3518 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3519 regTechConverted);
3520 try {
3521 consumer.accept(regTechConverted);
3522 } catch (RemoteException e) {
3523 // Ignore if the remote process is no longer available to call back.
3524 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3525 }
3526 });
3527 } finally {
3528 Binder.restoreCallingIdentity(token);
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 * @param c The callback that will be used to send the result.
3536 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003537 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003538 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3539 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003540 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3541 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003542 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3543 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3544 "IMS not available on device.");
3545 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003546 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3547 final long token = Binder.clearCallingIdentity();
3548 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003549 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003550 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003551 } catch (ImsException e) {
3552 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003553 } finally {
3554 Binder.restoreCallingIdentity(token);
3555 }
3556 }
3557
shilu366312e2019-12-17 09:28:10 -08003558 /**
3559 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3560 * @param subId The subscription to use to check the configuration.
3561 * @param c The callback that will be used to send the result.
3562 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003563 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003564 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003565 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3566 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003567 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3568 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3569 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003570
3571 final long token = Binder.clearCallingIdentity();
3572 try {
3573 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3574 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003575 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003576 } catch (ImsException e) {
3577 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3578 + "is inactive, ignoring unregister.");
3579 // If the subscription is no longer active, just return, since the callback
3580 // will already have been removed internally.
3581 } finally {
3582 Binder.restoreCallingIdentity(token);
3583 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003584 }
3585
3586 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003587 public boolean isCapable(int subId, int capability, int regTech) {
3588 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003589 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3590 final long token = Binder.clearCallingIdentity();
3591 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003592 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003593 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003594 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003595 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3596 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003597 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003598 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3599 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003600 } finally {
3601 Binder.restoreCallingIdentity(token);
3602 }
3603 }
3604
3605 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003606 public boolean isAvailable(int subId, int capability, int regTech) {
3607 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003608 final long token = Binder.clearCallingIdentity();
3609 try {
3610 Phone phone = getPhone(subId);
3611 if (phone == null) return false;
3612 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003613 } catch (com.android.ims.ImsException e) {
3614 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3615 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003616 } finally {
3617 Binder.restoreCallingIdentity(token);
3618 }
3619 }
3620
Brad Ebinger77b832e2019-10-17 17:03:22 -07003621 /**
3622 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3623 * subscription.
3624 * @param subId The subscription to use to check the configuration.
3625 * @param callback The callback that will be used to send the result.
3626 * @param capability The MmTelFeature capability that will be used to send the result.
3627 * @param transportType The transport type of the MmTelFeature capability.
3628 */
3629 @Override
3630 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3631 int transportType) {
3632 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3633 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3634 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3635 "IMS not available on device.");
3636 }
3637 final long token = Binder.clearCallingIdentity();
3638 try {
3639 int slotId = getSlotIndex(subId);
3640 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3641 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3642 + subId + "'");
3643 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3644 }
3645 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3646 transportType, aBoolean -> {
3647 try {
3648 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3649 } catch (RemoteException e) {
3650 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3651 + "running. Ignore");
3652 }
3653 });
3654 } finally {
3655 Binder.restoreCallingIdentity(token);
3656 }
3657 }
3658
shilu366312e2019-12-17 09:28:10 -08003659 /**
3660 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3661 * @param subId The subscription to use to check the configuration.
3662 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003663 @Override
3664 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003665 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3666 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003667
Brad Ebinger35c841c2018-10-01 10:40:55 -07003668 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3669 final long token = Binder.clearCallingIdentity();
3670 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003671 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003672 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003673 } catch (ImsException e) {
3674 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003675 } finally {
3676 Binder.restoreCallingIdentity(token);
3677 }
3678 }
3679
3680 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003681 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003683 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003684 final long identity = Binder.clearCallingIdentity();
3685 try {
3686 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003687 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003688 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003689 } catch (ImsException e) {
3690 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003691 } finally {
3692 Binder.restoreCallingIdentity(identity);
3693 }
3694 }
3695
shilu366312e2019-12-17 09:28:10 -08003696 /**
3697 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3698 * @param subId The subscription to use to check the configuration.
3699 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003700 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003701 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003702 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3703 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003707 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3708 } catch (ImsException e) {
3709 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
3713 }
3714
3715 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003716 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003718 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003719 final long identity = Binder.clearCallingIdentity();
3720 try {
3721 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003722 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003723 } catch (ImsException e) {
3724 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 } finally {
3726 Binder.restoreCallingIdentity(identity);
3727 }
3728 }
3729
shilu366312e2019-12-17 09:28:10 -08003730 /**
3731 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3732 * @param subId The subscription to use to check the configuration.
3733 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003734 @Override
3735 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003736 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3737 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003738 final long identity = Binder.clearCallingIdentity();
3739 try {
3740 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003741 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003742 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003743 } catch (ImsException e) {
3744 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003745 } finally {
3746 Binder.restoreCallingIdentity(identity);
3747 }
3748 }
3749
3750 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003751 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003753 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003754 final long identity = Binder.clearCallingIdentity();
3755 try {
3756 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003757 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003758 } catch (ImsException e) {
3759 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003760 } finally {
3761 Binder.restoreCallingIdentity(identity);
3762 }
3763 }
3764
shilu366312e2019-12-17 09:28:10 -08003765 /**
3766 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3767 * @param subId The subscription to use to check the configuration.
3768 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003769 @Override
3770 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003771 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3772 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003773 final long identity = Binder.clearCallingIdentity();
3774 try {
3775 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003776 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003777 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003778 } catch (ImsException e) {
3779 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003780 } finally {
3781 Binder.restoreCallingIdentity(identity);
3782 }
3783 }
3784
3785 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003786 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003788 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003789 final long identity = Binder.clearCallingIdentity();
3790 try {
3791 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003792 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003793 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003794 } catch (ImsException e) {
3795 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003796 } finally {
3797 Binder.restoreCallingIdentity(identity);
3798 }
3799 }
3800
3801 @Override
3802 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3804 "setVoWiFiNonPersistent");
3805 final long identity = Binder.clearCallingIdentity();
3806 try {
3807 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003808 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003809 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003810 } catch (ImsException e) {
3811 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003812 } finally {
3813 Binder.restoreCallingIdentity(identity);
3814 }
3815 }
3816
shilu366312e2019-12-17 09:28:10 -08003817 /**
3818 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3819 * @param subId The subscription to use to check the configuration.
3820 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003821 @Override
3822 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003823 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3824 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003825 final long identity = Binder.clearCallingIdentity();
3826 try {
3827 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003828 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003829 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003830 } catch (ImsException e) {
3831 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003832 } finally {
3833 Binder.restoreCallingIdentity(identity);
3834 }
3835 }
3836
3837 @Override
3838 public void setVoWiFiModeSetting(int subId, int mode) {
3839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3840 "setVoWiFiModeSetting");
3841 final long identity = Binder.clearCallingIdentity();
3842 try {
3843 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003844 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003846 } catch (ImsException e) {
3847 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003848 } finally {
3849 Binder.restoreCallingIdentity(identity);
3850 }
3851 }
3852
3853 @Override
3854 public int getVoWiFiRoamingModeSetting(int subId) {
3855 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3856 final long identity = Binder.clearCallingIdentity();
3857 try {
3858 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003859 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003860 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003861 } catch (ImsException e) {
3862 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003863 } finally {
3864 Binder.restoreCallingIdentity(identity);
3865 }
3866 }
3867
3868 @Override
3869 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3871 "setVoWiFiRoamingModeSetting");
3872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003875 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003876 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003877 } catch (ImsException e) {
3878 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003879 } finally {
3880 Binder.restoreCallingIdentity(identity);
3881 }
3882 }
3883
3884 @Override
3885 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3887 "setRttCapabilityEnabled");
3888 final long identity = Binder.clearCallingIdentity();
3889 try {
3890 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003891 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3892 } catch (ImsException e) {
3893 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 } finally {
3895 Binder.restoreCallingIdentity(identity);
3896 }
3897 }
3898
shilu366312e2019-12-17 09:28:10 -08003899 /**
3900 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3901 * @param subId The subscription to use to check the configuration.
3902 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003903 @Override
3904 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003905 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3906 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 final long identity = Binder.clearCallingIdentity();
3908 try {
3909 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003910 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003911 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003912 } catch (ImsException e) {
3913 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003914 } finally {
3915 Binder.restoreCallingIdentity(identity);
3916 }
3917 }
3918
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003919 @Override
3920 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3921 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3922 final long identity = Binder.clearCallingIdentity();
3923 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003924 if (!isImsAvailableOnDevice()) {
3925 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3926 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003927 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003928 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003929 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003930 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003931 } catch (ImsException e) {
3932 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003933 } finally {
3934 Binder.restoreCallingIdentity(identity);
3935 }
3936 }
3937
3938 @Override
3939 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3940 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3941 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003942 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3943 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3944 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003945 try {
3946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003947 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003948 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003949 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003950 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3951 + "is inactive, ignoring unregister.");
3952 // If the subscription is no longer active, just return, since the callback will already
3953 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003954 } finally {
3955 Binder.restoreCallingIdentity(identity);
3956 }
3957 }
3958
allenwtsu99c623b2020-01-03 18:24:23 +08003959
3960 private void checkModifyPhoneStatePermission(int subId, String message) {
3961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3962 message);
3963 }
3964
3965 private boolean isImsProvisioningRequired(int subId, int capability,
3966 boolean isMmtelCapability) {
3967 Phone phone = getPhone(subId);
3968 if (phone == null) {
3969 loge("phone instance null for subid " + subId);
3970 return false;
3971 }
3972 if (isMmtelCapability) {
3973 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3974 return false;
3975 }
3976 } else {
3977 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3978 return false;
3979 }
3980 }
3981 return true;
3982 }
3983
3984 @Override
3985 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3986 boolean isProvisioned) {
3987 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3988
3989 final long identity = Binder.clearCallingIdentity();
3990 try {
3991 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3992 if (!isImsProvisioningRequired(subId, capability, false)) {
3993 return;
3994 }
3995
3996 // this capability requires provisioning, route to the correct API.
3997 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3998 switch (capability) {
3999 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4000 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4001 ims.setEabProvisioned(isProvisioned);
4002 break;
4003 default: {
4004 throw new IllegalArgumentException("Tried to set provisioning for "
4005 + "rcs capability '" + capability + "', which does not require "
4006 + "provisioning.");
4007 }
4008 }
4009 } finally {
4010 Binder.restoreCallingIdentity(identity);
4011 }
4012
4013 }
4014
4015
4016 @Override
4017 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4018 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4019 final long identity = Binder.clearCallingIdentity();
4020 try {
4021 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4022 if (!isImsProvisioningRequired(subId, capability, false)) {
4023 return true;
4024 }
4025
4026 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4027 switch (capability) {
4028 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4029 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4030 return ims.isEabProvisionedOnDevice();
4031
4032 default: {
4033 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4034 + "capability '" + capability + "', which does not require "
4035 + "provisioning.");
4036 }
4037 }
4038
4039 } finally {
4040 Binder.restoreCallingIdentity(identity);
4041 }
4042 }
4043
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004044 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004045 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4046 boolean isProvisioned) {
4047 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4048 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4049 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4050 }
allenwtsu99c623b2020-01-03 18:24:23 +08004051 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004055 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004056 return;
4057 }
4058
4059 // this capability requires provisioning, route to the correct API.
4060 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4061 switch (capability) {
4062 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4063 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4064 ims.setVolteProvisioned(isProvisioned);
4065 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4066 ims.setWfcProvisioned(isProvisioned);
4067 }
4068 break;
4069 }
4070 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4071 // There is currently no difference in VT provisioning type.
4072 ims.setVtProvisioned(isProvisioned);
4073 break;
4074 }
4075 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4076 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4077 // change the capability of the feature instead if needed.
4078 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4079 == isProvisioned) {
4080 // No change in provisioning.
4081 return;
4082 }
4083 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4084 try {
4085 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004086 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004087 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4088 + ", Exception" + e.getMessage());
4089 }
4090 break;
4091 }
4092 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004093 throw new IllegalArgumentException("Tried to set provisioning for "
4094 + "MmTel capability '" + capability + "', which does not require "
4095 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004096 }
4097 }
4098
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
4101 }
4102 }
4103
4104 @Override
4105 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4106 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4107 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4108 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4109 }
4110 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4111 final long identity = Binder.clearCallingIdentity();
4112 try {
4113 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004114 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004115 return true;
4116 }
4117
4118 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4119 switch (capability) {
4120 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4121 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4122 return ims.isVolteProvisionedOnDevice();
4123 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4124 return ims.isWfcProvisionedOnDevice();
4125 }
4126 // This should never happen, since we are checking tech above to make sure it
4127 // is either LTE or IWLAN.
4128 throw new IllegalArgumentException("Invalid radio technology for voice "
4129 + "capability.");
4130 }
4131 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4132 // There is currently no difference in VT provisioning type.
4133 return ims.isVtProvisionedOnDevice();
4134 }
4135 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4136 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4137 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4138 }
4139 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004140 throw new IllegalArgumentException(
4141 "Tried to get provisioning for MmTel capability '" + capability
4142 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004143 }
4144 }
4145
4146 } finally {
4147 Binder.restoreCallingIdentity(identity);
4148 }
4149 }
4150
4151 @Override
4152 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4153 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4154 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4155 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4156 }
4157 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4158 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4159 return (provisionedBits & capability) > 0;
4160 }
4161
4162 @Override
4163 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4164 boolean isProvisioned) {
4165 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4166 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4167 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4168 }
4169 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4170 "setProvisioningStatusForCapability");
4171 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4172 // If the current provisioning status for capability already matches isProvisioned,
4173 // do nothing.
4174 if (((provisionedBits & capability) > 0) == isProvisioned) {
4175 return;
4176 }
4177 if (isProvisioned) {
4178 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4179 } else {
4180 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4181 }
4182 }
4183
4184 /**
4185 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4186 * technology. The bitfield should mirror the bitfield defined by
4187 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4188 */
4189 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4190 String key = getMmTelProvisioningKey(subId, tech);
4191 // Default is no capabilities are provisioned.
4192 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4193 }
4194
4195 /**
4196 * Sets the MmTel capability provisioning bitfield (defined by
4197 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4198 * technology specified.
4199 *
4200 * Note: This is a synchronous command and should not be called on UI thread.
4201 */
4202 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4203 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4204 String key = getMmTelProvisioningKey(subId, tech);
4205 editor.putInt(key, newField);
4206 editor.commit();
4207 }
4208
4209 private static String getMmTelProvisioningKey(int subId, int tech) {
4210 // resulting key is provision_ims_mmtel_{subId}_{tech}
4211 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4212 }
4213
4214 /**
4215 * Query CarrierConfig to see if the specified capability requires provisioning for the
4216 * carrier associated with the subscription id.
4217 */
4218 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4219 int capability) {
4220 CarrierConfigManager configManager = new CarrierConfigManager(context);
4221 PersistableBundle c = configManager.getConfigForSubId(subId);
4222 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004223 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004224 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4225 false);
4226 boolean requireVoiceVtProvisioning = c.getBoolean(
4227 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4228
4229 // First check to make sure that the capability requires provisioning.
4230 switch (capability) {
4231 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4232 // intentional fallthrough
4233 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4234 if (requireVoiceVtProvisioning) {
4235 // Voice and Video requires provisioning
4236 return true;
4237 }
4238 break;
4239 }
4240 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4241 if (requireUtProvisioning) {
4242 // UT requires provisioning
4243 return true;
4244 }
4245 break;
4246 }
4247 }
4248 return false;
4249 }
4250
allenwtsu99c623b2020-01-03 18:24:23 +08004251 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4252 int capability) {
4253 CarrierConfigManager configManager = new CarrierConfigManager(context);
4254 PersistableBundle c = configManager.getConfigForSubId(subId);
4255
4256 boolean requireRcsProvisioning = c.getBoolean(
4257 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4258
4259 // First check to make sure that the capability requires provisioning.
4260 switch (capability) {
4261 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4262 // intentional fallthrough
4263 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4264 if (requireRcsProvisioning) {
4265 // OPTION or PRESENCE requires provisioning
4266 return true;
4267 }
4268 break;
4269 }
4270 }
4271 return false;
4272 }
4273
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004274 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004275 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004276 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4277 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4278 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004279 enforceReadPrivilegedPermission("getImsProvisioningInt");
4280 final long identity = Binder.clearCallingIdentity();
4281 try {
4282 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004283 int slotId = getSlotIndex(subId);
4284 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4285 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4286 + subId + "' for key:" + key);
4287 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4288 }
4289 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004290 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004291 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4292 + subId + "' for key:" + key);
4293 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004294 } finally {
4295 Binder.restoreCallingIdentity(identity);
4296 }
4297 }
4298
4299 @Override
4300 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004301 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4302 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4303 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004304 enforceReadPrivilegedPermission("getImsProvisioningString");
4305 final long identity = Binder.clearCallingIdentity();
4306 try {
4307 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004308 int slotId = getSlotIndex(subId);
4309 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4310 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4311 + subId + "' for key:" + key);
4312 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4313 }
4314 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004315 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004316 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4317 + subId + "' for key:" + key);
4318 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
4322 }
4323
4324 @Override
4325 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004326 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4327 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4328 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4330 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004331 final long identity = Binder.clearCallingIdentity();
4332 try {
4333 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004334 int slotId = getSlotIndex(subId);
4335 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4336 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4337 + subId + "' for key:" + key);
4338 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4339 }
4340 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004341 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004342 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4343 + "' for key:" + key);
4344 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004345 } finally {
4346 Binder.restoreCallingIdentity(identity);
4347 }
4348 }
4349
4350 @Override
4351 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004352 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4353 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4354 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4356 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004357 final long identity = Binder.clearCallingIdentity();
4358 try {
4359 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004360 int slotId = getSlotIndex(subId);
4361 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4362 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4363 + subId + "' for key:" + key);
4364 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4365 }
4366 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004367 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004368 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4369 + "' for key:" + key);
4370 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004371 } finally {
4372 Binder.restoreCallingIdentity(identity);
4373 }
4374 }
4375
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004376 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004377 int slotId = SubscriptionManager.getSlotIndex(subId);
4378 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004379 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4380 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004381 }
4382 return slotId;
4383 }
4384
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004385 private int getSlotIndex(int subId) {
4386 int slotId = SubscriptionManager.getSlotIndex(subId);
4387 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4388 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4389 }
4390 return slotId;
4391 }
4392
Wink Saville36469e72014-06-11 15:17:00 -07004393 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004394 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004395 */
4396 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004397 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4398 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004399 final int targetSdk = getTargetSdk(callingPackage);
4400 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004401 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004402 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004403 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004404 mApp, subId, callingPackage, callingFeatureId,
4405 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004406 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4407 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004408
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409 final long identity = Binder.clearCallingIdentity();
4410 try {
4411 final Phone phone = getPhone(subId);
4412 if (phone != null) {
4413 return phone.getServiceState().getDataNetworkType();
4414 } else {
4415 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4416 }
4417 } finally {
4418 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004420 }
4421
4422 /**
4423 * Returns the data network type
4424 */
4425 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004426 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4427 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4428 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004429 }
4430
4431 /**
4432 * Returns the data network type for a subId
4433 */
4434 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004435 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4436 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004438 mApp, subId, callingPackage, callingFeatureId,
4439 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004440 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4441 }
4442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 final long identity = Binder.clearCallingIdentity();
4444 try {
4445 final Phone phone = getPhone(subId);
4446 if (phone != null) {
4447 return phone.getServiceState().getDataNetworkType();
4448 } else {
4449 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4450 }
4451 } finally {
4452 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004454 }
4455
4456 /**
Wink Saville36469e72014-06-11 15:17:00 -07004457 * Returns the Voice network type for a subId
4458 */
4459 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004460 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4461 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004462 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004463 mApp, subId, callingPackage, callingFeatureId,
4464 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004465 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4466 }
4467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004468 final long identity = Binder.clearCallingIdentity();
4469 try {
4470 final Phone phone = getPhone(subId);
4471 if (phone != null) {
4472 return phone.getServiceState().getVoiceNetworkType();
4473 } else {
4474 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4475 }
4476 } finally {
4477 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004479 }
4480
4481 /**
4482 * @return true if a ICC card is present
4483 */
4484 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004485 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004486 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4487 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004488 }
4489
4490 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004491 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004492 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004493 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004494 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 final long identity = Binder.clearCallingIdentity();
4496 try {
4497 final Phone phone = PhoneFactory.getPhone(slotIndex);
4498 if (phone != null) {
4499 return phone.getIccCard().hasIccCard();
4500 } else {
4501 return false;
4502 }
4503 } finally {
4504 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004506 }
4507
4508 /**
4509 * Return if the current radio is LTE on CDMA. This
4510 * is a tri-state return value as for a period of time
4511 * the mode may be unknown.
4512 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004513 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004514 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004515 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004516 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004517 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004518 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4519 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4520 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004521 }
4522
Sanket Padawe356d7632015-06-22 14:03:32 -07004523 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004524 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4525 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004526 try {
4527 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4528 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004529 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4530 }
4531
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004532 final long identity = Binder.clearCallingIdentity();
4533 try {
4534 final Phone phone = getPhone(subId);
4535 if (phone == null) {
4536 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4537 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004538 return TelephonyProperties.lte_on_cdma_device()
4539 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 }
4541 } finally {
4542 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004543 }
Wink Saville36469e72014-06-11 15:17:00 -07004544 }
4545
Wink Saville36469e72014-06-11 15:17:00 -07004546 /**
4547 * {@hide}
4548 * Returns Default subId, 0 in the case of single standby.
4549 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004550 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004551 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004552 }
4553
Shishir Agrawala9f32182016-04-12 12:00:16 -07004554 private int getSlotForDefaultSubscription() {
4555 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4556 }
4557
Wink Savilleb564aae2014-10-23 10:18:09 -07004558 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004559 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004560 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004561
Pengquan Menge92a50d2018-09-21 15:54:48 -07004562 private boolean isActiveSubscription(int subId) {
4563 return mSubscriptionController.isActiveSubId(subId);
4564 }
4565
Ihab Awadf2177b72013-11-25 13:33:23 -08004566 /**
4567 * @see android.telephony.TelephonyManager.WifiCallingChoices
4568 */
4569 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570 final long identity = Binder.clearCallingIdentity();
4571 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004572 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004573 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4574 getWhenToMakeWifiCallsDefaultPreference());
4575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004578 }
4579
4580 /**
4581 * @see android.telephony.TelephonyManager.WifiCallingChoices
4582 */
4583 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004584 final long identity = Binder.clearCallingIdentity();
4585 try {
4586 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004587 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004588 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4589 } finally {
4590 Binder.restoreCallingIdentity(identity);
4591 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004592 }
4593
Sailesh Nepald1e68152013-12-12 19:08:02 -08004594 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004595 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004596 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004597 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004598
Jordan Liu4c733742019-02-28 12:03:40 -08004599 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4600 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4601 if (phoneId == -1) {
4602 throw new IllegalArgumentException("Given slot index: " + slotIndex
4603 + " does not correspond to an active phone");
4604 }
4605 return PhoneFactory.getPhone(phoneId);
4606 }
4607
Shishir Agrawal566b7612013-10-28 14:41:00 -07004608 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004609 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4610 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4612 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004613 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004614 if (DBG) {
4615 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4616 }
4617 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4618 p2);
4619 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004620
Jordan Liu4c733742019-02-28 12:03:40 -08004621
4622 @Override
4623 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4624 int slotIndex, String callingPackage, String aid, int p2) {
4625 enforceModifyPermission();
4626 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4627 if (DBG) {
4628 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4629 }
4630 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4631 callingPackage, aid, p2);
4632 }
4633
4634 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4635 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004636 final long identity = Binder.clearCallingIdentity();
4637 try {
4638 if (TextUtils.equals(ISDR_AID, aid)) {
4639 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004640 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4641 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004642 if (bestComponent == null
4643 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4644 loge("The calling package is not allowed to access ISD-R.");
4645 throw new SecurityException(
4646 "The calling package is not allowed to access ISD-R.");
4647 }
Derek Tan740e1672017-06-27 14:56:27 -07004648 }
Derek Tan740e1672017-06-27 14:56:27 -07004649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004651 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4652 null /* workSource */);
4653 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004654 return response;
4655 } finally {
4656 Binder.restoreCallingIdentity(identity);
4657 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004658 }
4659
4660 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004661 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4663 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004664 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4665 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4666 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004667
Jordan Liu4c733742019-02-28 12:03:40 -08004668 @Override
4669 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4670 enforceModifyPermission();
4671 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4672 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4673 channel);
4674 }
4675
4676 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004677 final long identity = Binder.clearCallingIdentity();
4678 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004679 if (channel < 0) {
4680 return false;
4681 }
Jordan Liu4c733742019-02-28 12:03:40 -08004682 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4683 null /* workSource */);
4684 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685 return success;
4686 } finally {
4687 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004688 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004689 }
4690
4691 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004692 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004693 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4695 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004696 if (DBG) {
4697 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4698 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4699 + p3 + " data=" + data);
4700 }
4701 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4702 command, p1, p2, p3, data);
4703 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004704
Jordan Liu4c733742019-02-28 12:03:40 -08004705 @Override
4706 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4707 int command, int p1, int p2, int p3, String data) {
4708 enforceModifyPermission();
4709 if (DBG) {
4710 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4711 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4712 + p3 + " data=" + data);
4713 }
4714 return iccTransmitApduLogicalChannelWithPermission(
4715 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4716 data);
4717 }
4718
4719 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4720 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004721 final long identity = Binder.clearCallingIdentity();
4722 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004723 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004724 return "";
4725 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004728 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4729 null /* workSource */);
4730 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004732 // Append the returned status code to the end of the response payload.
4733 String s = Integer.toHexString(
4734 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4735 if (response.payload != null) {
4736 s = IccUtils.bytesToHexString(response.payload) + s;
4737 }
4738 return s;
4739 } finally {
4740 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004741 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004742 }
Jake Hambye994d462014-02-03 13:10:13 -08004743
Evan Charltonc66da362014-05-16 14:06:40 -07004744 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004745 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4746 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4748 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004749 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004750 if (DBG) {
4751 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4752 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4753 }
4754 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4755 cla, command, p1, p2, p3, data);
4756 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004757
Jordan Liu4c733742019-02-28 12:03:40 -08004758 @Override
4759 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4760 int command, int p1, int p2, int p3, String data) {
4761 enforceModifyPermission();
4762 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4763 if (DBG) {
4764 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4765 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4766 + " data=" + data);
4767 }
4768
4769 return iccTransmitApduBasicChannelWithPermission(
4770 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4771 p2, p3, data);
4772 }
4773
4774 // open APDU basic channel assuming the caller has sufficient permissions
4775 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4776 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004777 final long identity = Binder.clearCallingIdentity();
4778 try {
4779 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4780 && TextUtils.equals(ISDR_AID, data)) {
4781 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004782 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4783 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 if (bestComponent == null
4785 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4786 loge("The calling package is not allowed to select ISD-R.");
4787 throw new SecurityException(
4788 "The calling package is not allowed to select ISD-R.");
4789 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004790 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004791
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004793 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4794 null /* workSource */);
4795 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004797 // Append the returned status code to the end of the response payload.
4798 String s = Integer.toHexString(
4799 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4800 if (response.payload != null) {
4801 s = IccUtils.bytesToHexString(response.payload) + s;
4802 }
4803 return s;
4804 } finally {
4805 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004806 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004807 }
4808
4809 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004810 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004811 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4813 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815 final long identity = Binder.clearCallingIdentity();
4816 try {
4817 if (DBG) {
4818 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4819 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4820 }
4821
4822 IccIoResult response =
4823 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4824 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4825 subId);
4826
4827 if (DBG) {
4828 log("Exchange SIM_IO [R]" + response);
4829 }
4830
4831 byte[] result = null;
4832 int length = 2;
4833 if (response.payload != null) {
4834 length = 2 + response.payload.length;
4835 result = new byte[length];
4836 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4837 } else {
4838 result = new byte[length];
4839 }
4840
4841 result[length - 1] = (byte) response.sw2;
4842 result[length - 2] = (byte) response.sw1;
4843 return result;
4844 } finally {
4845 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004846 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004847 }
4848
Nathan Haroldb3014052017-01-25 15:57:32 -08004849 /**
4850 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4851 * on a particular subscription
4852 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004853 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4854 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004856 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004857 return null;
4858 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859
4860 final long identity = Binder.clearCallingIdentity();
4861 try {
4862 if (appType != TelephonyManager.APPTYPE_USIM
4863 && appType != TelephonyManager.APPTYPE_SIM) {
4864 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4865 return null;
4866 }
4867 Object response = sendRequest(
4868 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4869 if (response instanceof String[]) {
4870 return (String[]) response;
4871 }
yincheng zhaod698b842019-09-06 17:06:54 -07004872 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004874 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004875 } finally {
4876 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004877 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004878 }
4879
yincheng zhaod698b842019-09-06 17:06:54 -07004880 /**
4881 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4882 * subscription.
4883 *
4884 * @param subId the id of the subscription.
4885 * @param appType the uicc app type, must be USIM or SIM.
4886 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4887 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004888 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004889 * @return number of fplmns that is successfully written to the SIM.
4890 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004891 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4892 String callingFeatureId) {
4893 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4894 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004895 if (DBG) logv("no permissions for setForbiddenplmns");
4896 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4897 }
4898 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4899 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4900 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4901 }
4902 if (fplmns == null) {
4903 throw new IllegalArgumentException("Fplmn List provided is null");
4904 }
4905 for (String fplmn : fplmns) {
4906 if (!CellIdentity.isValidPlmn(fplmn)) {
4907 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4908 }
4909 }
4910 final long identity = Binder.clearCallingIdentity();
4911 try {
4912 Object response = sendRequest(
4913 CMD_SET_FORBIDDEN_PLMNS,
4914 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4915 subId);
4916 return (int) response;
4917 } finally {
4918 Binder.restoreCallingIdentity(identity);
4919 }
4920 }
4921
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004922 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004923 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004924 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4925 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004927 final long identity = Binder.clearCallingIdentity();
4928 try {
4929 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4930 if (response.payload == null) {
4931 return "";
4932 }
Evan Charltonc66da362014-05-16 14:06:40 -07004933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934 // Append the returned status code to the end of the response payload.
4935 String s = Integer.toHexString(
4936 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4937 s = IccUtils.bytesToHexString(response.payload) + s;
4938 return s;
4939 } finally {
4940 Binder.restoreCallingIdentity(identity);
4941 }
Evan Charltonc66da362014-05-16 14:06:40 -07004942 }
4943
Jake Hambye994d462014-02-03 13:10:13 -08004944 /**
4945 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4946 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4947 *
4948 * @param itemID the ID of the item to read
4949 * @return the NV item as a String, or null on error.
4950 */
4951 @Override
4952 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004953 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4955 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004956
4957 final long identity = Binder.clearCallingIdentity();
4958 try {
4959 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004960 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004961 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4962 return value;
4963 } finally {
4964 Binder.restoreCallingIdentity(identity);
4965 }
Jake Hambye994d462014-02-03 13:10:13 -08004966 }
4967
4968 /**
4969 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4970 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4971 *
4972 * @param itemID the ID of the item to read
4973 * @param itemValue the value to write, as a String
4974 * @return true on success; false on any failure
4975 */
4976 @Override
4977 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004978 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4980 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004981
4982 final long identity = Binder.clearCallingIdentity();
4983 try {
4984 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4985 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004986 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004987 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4988 return success;
4989 } finally {
4990 Binder.restoreCallingIdentity(identity);
4991 }
Jake Hambye994d462014-02-03 13:10:13 -08004992 }
4993
4994 /**
4995 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4996 * Used for device configuration by some CDMA operators.
4997 *
4998 * @param preferredRoamingList byte array containing the new PRL
4999 * @return true on success; false on any failure
5000 */
5001 @Override
5002 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5004 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005
5006 final long identity = Binder.clearCallingIdentity();
5007 try {
5008 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5009 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5010 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5011 return success;
5012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
Jake Hambye994d462014-02-03 13:10:13 -08005015 }
5016
5017 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005018 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005019 * Used for device configuration by some CDMA operators.
5020 *
chen xu6dac5ab2018-10-26 17:39:23 -07005021 * @param slotIndex - device slot.
5022 *
Jake Hambye994d462014-02-03 13:10:13 -08005023 * @return true on success; false on any failure
5024 */
5025 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005026 public boolean resetModemConfig(int slotIndex) {
5027 Phone phone = PhoneFactory.getPhone(slotIndex);
5028 if (phone != null) {
5029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5030 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031
chen xu6dac5ab2018-10-26 17:39:23 -07005032 final long identity = Binder.clearCallingIdentity();
5033 try {
5034 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5035 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5036 return success;
5037 } finally {
5038 Binder.restoreCallingIdentity(identity);
5039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005040 }
chen xu6dac5ab2018-10-26 17:39:23 -07005041 return false;
5042 }
5043
5044 /**
5045 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5046 *
5047 * @param slotIndex - device slot.
5048 *
5049 * @return true on success; false on any failure
5050 */
5051 @Override
5052 public boolean rebootModem(int slotIndex) {
5053 Phone phone = PhoneFactory.getPhone(slotIndex);
5054 if (phone != null) {
5055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5056 mApp, phone.getSubId(), "rebootModem");
5057
5058 final long identity = Binder.clearCallingIdentity();
5059 try {
5060 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5061 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5062 return success;
5063 } finally {
5064 Binder.restoreCallingIdentity(identity);
5065 }
5066 }
5067 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005068 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005069
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005070 public String[] getPcscfAddress(String apnType, String callingPackage,
5071 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005072 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005073 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5074 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005075 return new String[0];
5076 }
5077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 final long identity = Binder.clearCallingIdentity();
5079 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005080 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 } finally {
5082 Binder.restoreCallingIdentity(identity);
5083 }
Wink Saville36469e72014-06-11 15:17:00 -07005084 }
5085
Brad Ebinger51f743a2017-01-23 13:50:20 -08005086 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005087 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5088 * {@link #disableIms(int)}.
5089 * @param slotIndex device slot.
5090 */
5091 public void resetIms(int slotIndex) {
5092 enforceModifyPermission();
5093
5094 final long identity = Binder.clearCallingIdentity();
5095 try {
5096 if (mImsResolver == null) {
5097 // may happen if the does not support IMS.
5098 return;
5099 }
5100 mImsResolver.disableIms(slotIndex);
5101 mImsResolver.enableIms(slotIndex);
5102 } finally {
5103 Binder.restoreCallingIdentity(identity);
5104 }
5105 }
5106
5107 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005108 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5109 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005110 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005111 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005112 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113
5114 final long identity = Binder.clearCallingIdentity();
5115 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005116 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005117 // may happen if the device does not support IMS.
5118 return;
5119 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005120 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121 } finally {
5122 Binder.restoreCallingIdentity(identity);
5123 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005124 }
5125
5126 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005127 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5128 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005129 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005130 public void disableIms(int slotId) {
5131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132
5133 final long identity = Binder.clearCallingIdentity();
5134 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005135 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005136 // may happen if the device does not support IMS.
5137 return;
5138 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005139 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140 } finally {
5141 Binder.restoreCallingIdentity(identity);
5142 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005143 }
5144
5145 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005146 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5147 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005148 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005149 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005150 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005151 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005152
5153 final long identity = Binder.clearCallingIdentity();
5154 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005155 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005156 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5157 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005158 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005159 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005160 } finally {
5161 Binder.restoreCallingIdentity(identity);
5162 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005163 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005164 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005165 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5166 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005167 @Override
5168 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005169 enforceModifyPermission();
5170
5171 final long identity = Binder.clearCallingIdentity();
5172 try {
5173 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005174 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005175 } finally {
5176 Binder.restoreCallingIdentity(identity);
5177 }
5178 }
5179
5180 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005181 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005182 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005183 */
5184 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5185 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005186
5187 final long identity = Binder.clearCallingIdentity();
5188 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005189 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005190 // may happen if the device does not support IMS.
5191 return null;
5192 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005193 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005194 } finally {
5195 Binder.restoreCallingIdentity(identity);
5196 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005197 }
5198
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005199 /**
5200 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005201 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005202 */
5203 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5204 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205
5206 final long identity = Binder.clearCallingIdentity();
5207 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005208 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005209 // may happen if the device does not support IMS.
5210 return null;
5211 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005212 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005213 } finally {
5214 Binder.restoreCallingIdentity(identity);
5215 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005216 }
5217
Brad Ebinger884c07b2018-02-15 16:17:40 -08005218 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005219 * Sets the ImsService Package Name that Telephony will bind to.
5220 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005221 * @param slotIndex the slot ID that the ImsService should bind for.
5222 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005223 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005224 * @param featureTypes An integer array of feature types associated with a packageName.
5225 * @param packageName The name of the package that the current configuration will be replaced
5226 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005227 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005228 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005229 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5230 int[] featureTypes, String packageName) {
5231 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5232 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5234 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005235 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005236
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 final long identity = Binder.clearCallingIdentity();
5238 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005239 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005240 // may happen if the device does not support IMS.
5241 return false;
5242 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005243 Map<Integer, String> featureConfig = new HashMap<>();
5244 for (int featureType : featureTypes) {
5245 featureConfig.put(featureType, packageName);
5246 }
5247 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5248 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005252 }
5253
5254 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005255 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005256 *
5257 * @param slotId The slot that the ImsService is associated with.
5258 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5259 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005260 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005261 * @return the package name of the ImsService configuration.
5262 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005263 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5264 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005265 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005266 TelephonyPermissions
5267 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5268 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5269 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005270
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005271 final long identity = Binder.clearCallingIdentity();
5272 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005273 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005274 // may happen if the device does not support IMS.
5275 return "";
5276 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005277 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005278 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5279 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005283 }
5284
Brad Ebinger77b832e2019-10-17 17:03:22 -07005285 /**
5286 * Get the MmTelFeature state associated with the requested subscription id.
5287 * @param subId The subscription that the MmTelFeature is associated with.
5288 * @param callback A callback with an integer containing the
5289 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5290 */
5291 @Override
5292 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5293 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5294 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5295 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5296 "IMS not available on device.");
5297 }
5298 final long token = Binder.clearCallingIdentity();
5299 try {
5300 int slotId = getSlotIndex(subId);
5301 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5302 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5303 + subId + "'");
5304 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5305 }
5306 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5307 try {
5308 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5309 } catch (RemoteException e) {
5310 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5311 + "Ignore");
5312 }
5313 });
5314 } finally {
5315 Binder.restoreCallingIdentity(token);
5316 }
5317 }
5318
Wink Saville36469e72014-06-11 15:17:00 -07005319 public void setImsRegistrationState(boolean registered) {
5320 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321
5322 final long identity = Binder.clearCallingIdentity();
5323 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005324 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 } finally {
5326 Binder.restoreCallingIdentity(identity);
5327 }
Wink Saville36469e72014-06-11 15:17:00 -07005328 }
5329
5330 /**
Stuart Scott54788802015-03-30 13:18:01 -07005331 * Set the network selection mode to automatic.
5332 *
5333 */
5334 @Override
5335 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5337 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338
5339 final long identity = Binder.clearCallingIdentity();
5340 try {
shilufc958392020-01-20 11:36:01 -08005341 if (!isActiveSubscription(subId)) {
5342 return;
5343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005344 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5345 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5346 } finally {
5347 Binder.restoreCallingIdentity(identity);
5348 }
Stuart Scott54788802015-03-30 13:18:01 -07005349 }
5350
Jack Yud10cdd42020-09-28 20:28:01 -07005351 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005352 * Ask the radio to connect to the input network and change selection mode to manual.
5353 *
5354 * @param subId the id of the subscription.
5355 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5356 * the operator to attach to.
5357 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5358 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5359 * normal network selection next time.
5360 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005361 */
5362 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005363 public boolean setNetworkSelectionModeManual(
5364 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5366 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005367
5368 if (!isActiveSubscription(subId)) {
5369 return false;
5370 }
5371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 final long identity = Binder.clearCallingIdentity();
5373 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005374 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005376 if (DBG) {
5377 log("setNetworkSelectionModeManual: subId: " + subId
5378 + " operator: " + operatorInfo);
5379 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5381 } finally {
5382 Binder.restoreCallingIdentity(identity);
5383 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005384 }
shilu84f6e8b2019-12-19 13:58:01 -08005385 /**
5386 * Get the manual network selection
5387 *
5388 * @param subId the id of the subscription.
5389 *
5390 * @return the previously saved user selected PLMN
5391 */
5392 @Override
5393 public String getManualNetworkSelectionPlmn(int subId) {
5394 TelephonyPermissions
5395 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5396 mApp, subId, "getManualNetworkSelectionPlmn");
5397
5398 final long identity = Binder.clearCallingIdentity();
5399 try {
5400 if (!isActiveSubscription(subId)) {
5401 return "";
5402 }
5403
5404 final Phone phone = getPhone(subId);
5405 if (phone == null) {
5406 return "";
5407 }
5408 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5409 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5410 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5411 } finally {
5412 Binder.restoreCallingIdentity(identity);
5413 }
5414 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005415
5416 /**
5417 * Scans for available networks.
5418 */
5419 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005420 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5421 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5423 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005424 LocationAccessPolicy.LocationPermissionResult locationResult =
5425 LocationAccessPolicy.checkLocationPermission(mApp,
5426 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5427 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005428 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005429 .setCallingPid(Binder.getCallingPid())
5430 .setCallingUid(Binder.getCallingUid())
5431 .setMethod("getCellNetworkScanResults")
5432 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5433 .build());
5434 switch (locationResult) {
5435 case DENIED_HARD:
5436 throw new SecurityException("Not allowed to access scan results -- location");
5437 case DENIED_SOFT:
5438 return null;
5439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440
Pengquan Menga1bb6272018-09-06 09:59:22 -07005441 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442 try {
5443 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005444 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 } finally {
5447 Binder.restoreCallingIdentity(identity);
5448 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005449 }
5450
5451 /**
sqian80370722020-01-29 15:02:51 -08005452 * Get the call forwarding info, given the call forwarding reason.
5453 */
5454 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005455 public void getCallForwarding(int subId, int callForwardingReason,
5456 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005457 enforceReadPrivilegedPermission("getCallForwarding");
5458 long identity = Binder.clearCallingIdentity();
5459 try {
5460 if (DBG) {
5461 log("getCallForwarding: subId " + subId
5462 + " callForwardingReason" + callForwardingReason);
5463 }
Hall Liua1acea22020-09-18 19:04:59 -07005464
5465 Phone phone = getPhone(subId);
5466 if (phone == null) {
5467 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005468 callback.onError(
5469 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005470 } catch (RemoteException e) {
5471 // ignore
5472 }
5473 return;
5474 }
5475
5476 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5477 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5478 @Override
5479 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5480 try {
5481 callback.onCallForwardingInfoAvailable(info);
5482 } catch (RemoteException e) {
5483 // ignore
5484 }
5485 }
5486
5487 @Override
5488 public void onError(int error) {
5489 try {
5490 callback.onError(error);
5491 } catch (RemoteException e) {
5492 // ignore
5493 }
5494 }
5495 });
5496 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005497 } finally {
5498 Binder.restoreCallingIdentity(identity);
5499 }
5500 }
5501
5502 /**
5503 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5504 * reason, the number to forward, and the timeout before the forwarding is attempted.
5505 */
5506 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005507 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5508 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005509 enforceModifyPermission();
5510 long identity = Binder.clearCallingIdentity();
5511 try {
5512 if (DBG) {
5513 log("setCallForwarding: subId " + subId
5514 + " callForwardingInfo" + callForwardingInfo);
5515 }
Hall Liua1acea22020-09-18 19:04:59 -07005516
5517 Phone phone = getPhone(subId);
5518 if (phone == null) {
5519 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005520 callback.accept(
5521 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005522 } catch (RemoteException e) {
5523 // ignore
5524 }
5525 return;
5526 }
5527
5528 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5529 FunctionalUtils.ignoreRemoteException(callback::accept));
5530
5531 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005532 } finally {
5533 Binder.restoreCallingIdentity(identity);
5534 }
5535 }
5536
5537 /**
Hall Liua1acea22020-09-18 19:04:59 -07005538 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005539 */
5540 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005541 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005542 enforceReadPrivilegedPermission("getCallForwarding");
5543 long identity = Binder.clearCallingIdentity();
5544 try {
Hall Liua1acea22020-09-18 19:04:59 -07005545
5546 Phone phone = getPhone(subId);
5547 if (phone == null) {
5548 try {
5549 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5550 } catch (RemoteException e) {
5551 // ignore
5552 }
5553 return;
5554 }
5555
5556 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5557
sqian80370722020-01-29 15:02:51 -08005558 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005559 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005560 } finally {
5561 Binder.restoreCallingIdentity(identity);
5562 }
5563 }
5564
5565 /**
Hall Liua1acea22020-09-18 19:04:59 -07005566 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005567 */
5568 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005569 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005570 enforceModifyPermission();
5571 long identity = Binder.clearCallingIdentity();
5572 try {
Hall Liua1acea22020-09-18 19:04:59 -07005573 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5574
5575 Phone phone = getPhone(subId);
5576 if (phone == null) {
5577 try {
5578 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5579 } catch (RemoteException e) {
5580 // ignore
5581 }
5582 return;
5583 }
5584
5585 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5586 FunctionalUtils.ignoreRemoteException(callback::accept));
5587
5588 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005589 } finally {
5590 Binder.restoreCallingIdentity(identity);
5591 }
5592 }
5593
5594 /**
yinxub1bed742017-04-17 11:45:04 -07005595 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005596 *
yinxub1bed742017-04-17 11:45:04 -07005597 * @param subId id of the subscription
5598 * @param request contains the radio access networks with bands/channels to scan
5599 * @param messenger callback messenger for scan results or errors
5600 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005601 * @return the id of the requested scan which can be used to stop the scan.
5602 */
5603 @Override
5604 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005605 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5607 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005608 LocationAccessPolicy.LocationPermissionResult locationResult =
5609 LocationAccessPolicy.checkLocationPermission(mApp,
5610 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5611 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005612 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005613 .setCallingPid(Binder.getCallingPid())
5614 .setCallingUid(Binder.getCallingUid())
5615 .setMethod("requestNetworkScan")
5616 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5617 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005618 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005619 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5620 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005621 if (e != null) {
5622 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5623 throw e;
5624 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005625 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005626 return TelephonyScanManager.INVALID_SCAN_ID;
5627 }
5628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629 }
Hall Liu912dfd32019-04-25 14:02:26 -07005630 int callingUid = Binder.getCallingUid();
5631 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005632 final long identity = Binder.clearCallingIdentity();
5633 try {
5634 return mNetworkScanRequestTracker.startNetworkScan(
5635 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005636 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005637 } finally {
5638 Binder.restoreCallingIdentity(identity);
5639 }
yinxu504e1392017-04-12 16:03:22 -07005640 }
5641
Hall Liub2ac8ef2019-02-28 15:56:23 -08005642 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005643 NetworkScanRequest request, int subId, String callingPackage) {
5644 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005645 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5646 boolean hasNetworkScanPermission =
5647 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5648 == PERMISSION_GRANTED;
5649
5650 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5651 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5652 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005653 }
5654
5655 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5656 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005657 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5658 return new SecurityException("Specific channels must not be"
5659 + " scanned without location access.");
5660 }
5661 }
5662 }
5663
Hall Liub2ac8ef2019-02-28 15:56:23 -08005664 return null;
5665 }
5666
yinxu504e1392017-04-12 16:03:22 -07005667 /**
5668 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005669 *
5670 * @param subId id of the subscription
5671 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005672 */
5673 @Override
5674 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5676 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677
Hall Liu912dfd32019-04-25 14:02:26 -07005678 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 final long identity = Binder.clearCallingIdentity();
5680 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005681 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 } finally {
5683 Binder.restoreCallingIdentity(identity);
5684 }
yinxu504e1392017-04-12 16:03:22 -07005685 }
5686
5687 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005688 * Get the calculated preferred network type.
5689 * Used for debugging incorrect network type.
5690 *
5691 * @return the preferred network type, defined in RILConstants.java.
5692 */
5693 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005694 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005695 final Phone defaultPhone = getDefaultPhone();
5696 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005697 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005698 return RILConstants.PREFERRED_NETWORK_MODE;
5699 }
5700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701 final long identity = Binder.clearCallingIdentity();
5702 try {
5703 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005704 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 } finally {
5706 Binder.restoreCallingIdentity(identity);
5707 }
Junda Liu84d15a22014-07-02 11:21:04 -07005708 }
5709
5710 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005711 * Get the preferred network type.
5712 * Used for device configuration by some CDMA operators.
5713 *
5714 * @return the preferred network type, defined in RILConstants.java.
5715 */
5716 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005717 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005718 TelephonyPermissions
5719 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5720 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005721
5722 final long identity = Binder.clearCallingIdentity();
5723 try {
5724 if (DBG) log("getPreferredNetworkType");
5725 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5726 int networkType = (result != null ? result[0] : -1);
5727 if (DBG) log("getPreferredNetworkType: " + networkType);
5728 return networkType;
5729 } finally {
5730 Binder.restoreCallingIdentity(identity);
5731 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005732 }
5733
5734 /**
5735 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005736 *
5737 * @param networkType the preferred network type, defined in RILConstants.java.
5738 * @return true on success; false on any failure.
5739 */
5740 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005741 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5743 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005744
5745 final long identity = Binder.clearCallingIdentity();
5746 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005747 Settings.Global.putInt(mApp.getContentResolver(),
5748 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005749
5750 Boolean success = (Boolean) sendRequest(
5751 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5752 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5753 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 } finally {
5755 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005756 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005757 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005758
5759 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005760 * Get the allowed network types that store in the telephony provider.
5761 *
5762 * @param subId the id of the subscription.
5763 * @return allowedNetworkTypes the allowed network types.
5764 */
5765 @Override
5766 public long getAllowedNetworkTypes(int subId) {
5767 TelephonyPermissions
5768 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5769 mApp, subId, "getAllowedNetworkTypes");
5770
5771 final long identity = Binder.clearCallingIdentity();
5772 try {
5773 return SubscriptionManager.getLongSubscriptionProperty(
5774 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
5778 }
5779
5780 /**
5781 * Set the allowed network types.
5782 *
5783 * @param subId the id of the subscription.
5784 * @param allowedNetworkTypes the allowed network types.
5785 * @return true on success; false on any failure.
5786 */
5787 @Override
5788 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5790 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005791
calvinpan089c2a62020-03-12 14:17:55 +08005792 SubscriptionManager.setSubscriptionProperty(subId,
5793 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5794 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005795
calvinpan089c2a62020-03-12 14:17:55 +08005796 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5797 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5798 RILConstants.PREFERRED_NETWORK_MODE);
5799 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005800 }
5801
5802 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005803 * Get the allowed network types for certain reason.
5804 *
5805 * @param subId the id of the subscription.
5806 * @param reason the reason the allowed network type change is taking place
5807 * @return the allowed network types.
5808 */
5809 @Override
5810 public long getAllowedNetworkTypesForReason(int subId,
5811 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5812 TelephonyPermissions
5813 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5814 mApp, subId, "getAllowedNetworkTypesForReason");
5815 final long identity = Binder.clearCallingIdentity();
5816 try {
5817 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5818 } finally {
5819 Binder.restoreCallingIdentity(identity);
5820 }
5821 }
5822
5823 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07005824 * Enable/Disable E-UTRA-NR Dual Connectivity
5825 * @param subId subscription id of the sim card
5826 * @param nrDualConnectivityState expected NR dual connectivity state
5827 * This can be passed following states
5828 * <ol>
5829 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
5830 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
5831 * <li>Disable NR dual connectivity and force secondary cell to be released
5832 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
5833 * </ol>
5834 * @return operation result.
5835 */
5836 @Override
5837 public int setNrDualConnectivityState(int subId,
5838 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
5839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5840 mApp, subId, "enableNRDualConnectivity");
5841 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5842 final long identity = Binder.clearCallingIdentity();
5843 try {
5844 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
5845 nrDualConnectivityState, subId,
5846 workSource);
5847 if (DBG) log("enableNRDualConnectivity result: " + result);
5848 return result;
5849 } finally {
5850 Binder.restoreCallingIdentity(identity);
5851 }
5852 }
5853
5854 /**
5855 * Is E-UTRA-NR Dual Connectivity enabled
5856 * @return true if dual connectivity is enabled else false
5857 */
5858 @Override
5859 public boolean isNrDualConnectivityEnabled(int subId) {
5860 TelephonyPermissions
5861 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5862 mApp, subId, "isNRDualConnectivityEnabled");
5863 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5864 final long identity = Binder.clearCallingIdentity();
5865 try {
5866 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
5867 null, subId, workSource);
5868 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
5869 return isEnabled;
5870 } finally {
5871 Binder.restoreCallingIdentity(identity);
5872 }
5873 }
5874
5875 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005876 * Get the effective allowed network types on the device.
5877 * This API will return an intersection of allowed network types for all reasons,
5878 * including the configuration done through setAllowedNetworkTypes
5879 *
5880 * @param subId the id of the subscription.
5881 * @return the allowed network types
5882 */
5883 @Override
5884 public long getEffectiveAllowedNetworkTypes(int subId) {
5885 TelephonyPermissions
5886 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5887 mApp, subId, "getEffectiveAllowedNetworkTypes");
5888 final long identity = Binder.clearCallingIdentity();
5889 try {
5890 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5891 } finally {
5892 Binder.restoreCallingIdentity(identity);
5893 }
5894 }
5895
5896 /**
5897 * Set the allowed network types of the device and
5898 * provide the reason triggering the allowed network change.
5899 *
5900 * @param subId the id of the subscription.
5901 * @param reason the reason the allowed network type change is taking place
5902 * @param allowedNetworkTypes the allowed network types.
5903 * @return true on success; false on any failure.
5904 */
5905 @Override
5906 public boolean setAllowedNetworkTypesForReason(int subId,
5907 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5909 mApp, subId, "setAllowedNetworkTypesForReason");
5910 final long identity = Binder.clearCallingIdentity();
5911 try {
5912 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5913 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5914 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5915 RILConstants.PREFERRED_NETWORK_MODE);
5916 return setPreferredNetworkType(subId, preferredNetworkMode);
5917 } finally {
5918 Binder.restoreCallingIdentity(identity);
5919 }
5920 }
5921
5922 /**
Miaoa84611c2019-03-15 09:21:10 +08005923 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005924 *
Miaoa84611c2019-03-15 09:21:10 +08005925 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005926 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005927 * @hide
5928 */
5929 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005930 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005931 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005933 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934 try {
Miaoa84611c2019-03-15 09:21:10 +08005935 if (phone != null) {
5936 return phone.hasMatchedTetherApnSetting();
5937 } else {
5938 return false;
5939 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940 } finally {
5941 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005942 }
Junda Liu475951f2014-11-07 16:45:03 -08005943 }
5944
5945 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005946 * Enable or disable always reporting signal strength changes from radio.
5947 *
5948 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5949 */
5950 @Override
5951 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5952 enforceModifyPermission();
5953 enforceSystemCaller();
5954
5955 final long identity = Binder.clearCallingIdentity();
5956 final Phone phone = getPhone(subId);
5957 try {
5958 if (phone != null) {
5959 if (DBG) {
5960 log("setAlwaysReportSignalStrength: subId=" + subId
5961 + " isEnable=" + isEnable);
5962 }
5963 phone.setAlwaysReportSignalStrength(isEnable);
5964 } else {
5965 loge("setAlwaysReportSignalStrength: no phone found for subId="
5966 + subId);
5967 }
5968 } finally {
5969 Binder.restoreCallingIdentity(identity);
5970 }
5971 }
5972
5973 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005974 * Get the user enabled state of Mobile Data.
5975 *
5976 * TODO: remove and use isUserDataEnabled.
5977 * This can't be removed now because some vendor codes
5978 * calls through ITelephony directly while they should
5979 * use TelephonyManager.
5980 *
5981 * @return true on enabled
5982 */
5983 @Override
5984 public boolean getDataEnabled(int subId) {
5985 return isUserDataEnabled(subId);
5986 }
5987
5988 /**
5989 * Get whether mobile data is enabled per user setting.
5990 *
5991 * There are other factors deciding whether mobile data is actually enabled, but they are
5992 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005993 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005994 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005995 *
5996 * @return {@code true} if data is enabled else {@code false}
5997 */
5998 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005999 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006000 try {
6001 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6002 null);
6003 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6005 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007
6008 final long identity = Binder.clearCallingIdentity();
6009 try {
6010 int phoneId = mSubscriptionController.getPhoneId(subId);
6011 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6012 Phone phone = PhoneFactory.getPhone(phoneId);
6013 if (phone != null) {
6014 boolean retVal = phone.isUserDataEnabled();
6015 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6016 return retVal;
6017 } else {
6018 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6019 return false;
6020 }
6021 } finally {
6022 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006023 }
6024 }
6025
6026 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006027 * Checks if the device is capable of mobile data by considering whether whether the
6028 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6029 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006030 *
Shuo Qian985d1232020-01-08 14:30:06 -08006031 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006032 */
6033 @Override
6034 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006035 try {
6036 try {
6037 mApp.enforceCallingOrSelfPermission(
6038 android.Manifest.permission.ACCESS_NETWORK_STATE,
6039 null);
6040 } catch (Exception e) {
6041 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6042 "isDataEnabled");
6043 }
6044 } catch (Exception e) {
6045 enforceReadPrivilegedPermission("isDataEnabled");
6046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006047
6048 final long identity = Binder.clearCallingIdentity();
6049 try {
6050 int phoneId = mSubscriptionController.getPhoneId(subId);
6051 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6052 Phone phone = PhoneFactory.getPhone(phoneId);
6053 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006054 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6056 return retVal;
6057 } else {
6058 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6059 return false;
6060 }
6061 } finally {
6062 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006063 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006064 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006065
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006066 /**
6067 * Check if data is enabled for a specific reason
6068 * @param subId Subscription index
6069 * @param reason the reason the data enable change is taking place
6070 * @return {@code true} if the overall data is enabled; {@code false} if not.
6071 */
6072 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006073 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006074 @TelephonyManager.DataEnabledReason int reason) {
6075 try {
6076 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6077 null);
6078 } catch (Exception e) {
6079 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006080 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006081 }
6082
6083
6084 final long identity = Binder.clearCallingIdentity();
6085 try {
6086 int phoneId = mSubscriptionController.getPhoneId(subId);
6087 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006088 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006089 + " reason=" + reason);
6090 }
6091 Phone phone = PhoneFactory.getPhone(phoneId);
6092 if (phone != null) {
6093 boolean retVal;
6094 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6095 retVal = phone.isUserDataEnabled();
6096 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006097 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006098 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006099 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006100 return retVal;
6101 } else {
6102 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006103 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006104 + subId + " retVal=false");
6105 }
6106 return false;
6107 }
6108 } finally {
6109 Binder.restoreCallingIdentity(identity);
6110 }
6111 }
6112
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006113 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006114 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006115 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6116 // Skip the check if it's one of these special uids
6117 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6118 }
6119
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006120 //load access rules from carrier configs, and check those as well: b/139133814
6121 SubscriptionController subController = SubscriptionController.getInstance();
6122 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6123 || subController == null) return privilegeFromSim;
6124
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006125 PackageManager pkgMgr = phone.getContext().getPackageManager();
6126 String[] packages = pkgMgr.getPackagesForUid(uid);
6127
6128 final long identity = Binder.clearCallingIdentity();
6129 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006130 int subId = phone.getSubId();
6131 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6132 // A test override is in place for the privileges for this subId, so don't try to
6133 // read the subscription privileges.
6134 return privilegeFromSim;
6135 }
6136 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006137 SubscriptionManager subManager = (SubscriptionManager)
6138 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6139 for (String pkg : packages) {
6140 if (subManager.canManageSubscription(subInfo, pkg)) {
6141 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6142 }
6143 }
6144 return privilegeFromSim;
6145 } finally {
6146 Binder.restoreCallingIdentity(identity);
6147 }
6148 }
6149
6150 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6151 String pkgName) {
6152 //load access rules from carrier configs, and check those as well: b/139133814
6153 SubscriptionController subController = SubscriptionController.getInstance();
6154 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6155 || subController == null) return privilegeFromSim;
6156
6157 final long identity = Binder.clearCallingIdentity();
6158 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006159 int subId = phone.getSubId();
6160 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6161 // A test override is in place for the privileges for this subId, so don't try to
6162 // read the subscription privileges.
6163 return privilegeFromSim;
6164 }
6165 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006166 SubscriptionManager subManager = (SubscriptionManager)
6167 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6168 return subManager.canManageSubscription(subInfo, pkgName)
6169 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6170 } finally {
6171 Binder.restoreCallingIdentity(identity);
6172 }
6173 }
6174
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006175 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006176 public int getCarrierPrivilegeStatus(int subId) {
6177 final Phone phone = getPhone(subId);
6178 if (phone == null) {
6179 loge("getCarrierPrivilegeStatus: Invalid subId");
6180 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6181 }
6182 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006183 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006184 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006185 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6186 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006187
6188 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6189 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006190 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006191 }
Junda Liu29340342014-07-10 15:23:27 -07006192
6193 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006194 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006195 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006196 final Phone phone = getPhone(subId);
6197 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006198 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006199 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6200 }
6201 UiccProfile profile =
6202 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6203 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006204 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006205 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6206 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006207 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006208 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006209 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006210 }
6211
6212 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006213 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6214 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006215 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006216 }
6217
6218 int phoneId = SubscriptionManager.getPhoneId(subId);
6219 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006220 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006221 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006222 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6223 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006224 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6225 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6226 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006227 }
6228
6229 @Override
6230 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006231 if (TextUtils.isEmpty(pkgName))
6232 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006233 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6234 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6235 UiccCard card = UiccController.getInstance().getUiccCard(i);
6236 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006237 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006238 continue;
6239 }
6240
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006241 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6242 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6243 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006244 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6245 break;
6246 }
6247 }
6248
6249 return result;
Junda Liu29340342014-07-10 15:23:27 -07006250 }
Derek Tan89e89d42014-07-08 17:00:10 -07006251
6252 @Override
Junda Liue64de782015-04-16 17:19:16 -07006253 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6254 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6255 loge("phoneId " + phoneId + " is not valid.");
6256 return null;
6257 }
6258 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006259 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006260 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006261 return null ;
6262 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006263 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006264 }
6265
Amith Yamasani6e118872016-02-19 12:53:51 -08006266 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006267 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006268 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006269 List<String> privilegedPackages = new ArrayList<>();
6270 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006271 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6272 // has UICC in that slot.
6273 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006274 if (card.hasCarrierPrivilegeRules()) {
6275 if (packages == null) {
6276 // Only check packages in user 0 for now
6277 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006278 PackageManager.MATCH_DISABLED_COMPONENTS
6279 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006280 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006281 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006282 }
6283 for (int p = packages.size() - 1; p >= 0; p--) {
6284 PackageInfo pkgInfo = packages.get(p);
6285 if (pkgInfo != null && pkgInfo.packageName != null
6286 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006287 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006288 privilegedPackages.add(pkgInfo.packageName);
6289 }
6290 }
6291 }
6292 }
6293 return privilegedPackages;
6294 }
6295
chen xuf7e9fe82019-05-09 19:31:02 -07006296 @Override
6297 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006298 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6299
6300 final long identity = Binder.clearCallingIdentity();
6301
chen xuf7e9fe82019-05-09 19:31:02 -07006302 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006303 try {
6304 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6305 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6306 }
6307 } finally {
6308 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006309 }
6310 return privilegedPackages;
6311 }
6312
Wink Savilleb564aae2014-10-23 10:18:09 -07006313 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006314 final Phone phone = getPhone(subId);
6315 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006316 if (card == null) {
6317 loge("getIccId: No UICC");
6318 return null;
6319 }
6320 String iccId = card.getIccId();
6321 if (TextUtils.isEmpty(iccId)) {
6322 loge("getIccId: ICC ID is null or empty.");
6323 return null;
6324 }
6325 return iccId;
6326 }
6327
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006328 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006329 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6330 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006331 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006332 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334 final long identity = Binder.clearCallingIdentity();
6335 try {
6336 final String iccId = getIccId(subId);
6337 final Phone phone = getPhone(subId);
6338 if (phone == null) {
6339 return false;
6340 }
6341 final String subscriberId = phone.getSubscriberId();
6342
6343 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006344 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 + subscriberId + " to " + number);
6346 }
6347
6348 if (TextUtils.isEmpty(iccId)) {
6349 return false;
6350 }
6351
6352 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6353
6354 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6355 if (alphaTag == null) {
6356 editor.remove(alphaTagPrefKey);
6357 } else {
6358 editor.putString(alphaTagPrefKey, alphaTag);
6359 }
6360
6361 // Record both the line number and IMSI for this ICCID, since we need to
6362 // track all merged IMSIs based on line number
6363 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6364 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6365 if (number == null) {
6366 editor.remove(numberPrefKey);
6367 editor.remove(subscriberPrefKey);
6368 } else {
6369 editor.putString(numberPrefKey, number);
6370 editor.putString(subscriberPrefKey, subscriberId);
6371 }
6372
6373 editor.commit();
6374 return true;
6375 } finally {
6376 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006377 }
Derek Tan7226c842014-07-02 17:42:23 -07006378 }
6379
6380 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006381 public String getLine1NumberForDisplay(int subId, String callingPackage,
6382 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006383 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006385 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006386 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006387 return null;
6388 }
Derek Tan97ebb422014-09-05 16:55:38 -07006389
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390 final long identity = Binder.clearCallingIdentity();
6391 try {
6392 String iccId = getIccId(subId);
6393 if (iccId != null) {
6394 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6395 if (DBG_MERGE) {
6396 log("getLine1NumberForDisplay returning "
6397 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6398 }
6399 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006400 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6402 return null;
6403 } finally {
6404 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006405 }
Derek Tan7226c842014-07-02 17:42:23 -07006406 }
6407
6408 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006409 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6410 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006411 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006412 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006413 return null;
6414 }
Derek Tan97ebb422014-09-05 16:55:38 -07006415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006416 final long identity = Binder.clearCallingIdentity();
6417 try {
6418 String iccId = getIccId(subId);
6419 if (iccId != null) {
6420 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6421 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6422 }
6423 return null;
6424 } finally {
6425 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006426 }
Derek Tan7226c842014-07-02 17:42:23 -07006427 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006428
6429 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006430 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6431 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006432 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6433 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006434 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006435 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006436 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006437 return null;
6438 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006439
Jordan Liub49b04b2019-05-06 14:45:15 -07006440 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6441 // the process, where TelephonyManager was instantiated.
6442 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006443 final long identity = Binder.clearCallingIdentity();
6444 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006445 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006446 final TelephonyManager tele = TelephonyManager.from(context);
6447 final SubscriptionManager sub = SubscriptionManager.from(context);
6448
6449 // Figure out what subscribers are currently active
6450 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006451
Jordan Liub49b04b2019-05-06 14:45:15 -07006452 // Only consider subs which match the current subId
6453 // This logic can be simplified. See b/131189269 for progress.
6454 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006455 activeSubscriberIds.add(tele.getSubscriberId(subId));
6456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006457
6458 // First pass, find a number override for an active subscriber
6459 String mergeNumber = null;
6460 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6461 for (String key : prefs.keySet()) {
6462 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6463 final String subscriberId = (String) prefs.get(key);
6464 if (activeSubscriberIds.contains(subscriberId)) {
6465 final String iccId = key.substring(
6466 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6467 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6468 mergeNumber = (String) prefs.get(numberKey);
6469 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006470 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006471 + " for active subscriber " + subscriberId);
6472 }
6473 if (!TextUtils.isEmpty(mergeNumber)) {
6474 break;
6475 }
6476 }
6477 }
6478 }
6479
6480 // Shortcut when no active merged subscribers
6481 if (TextUtils.isEmpty(mergeNumber)) {
6482 return null;
6483 }
6484
6485 // Second pass, find all subscribers under that line override
6486 final ArraySet<String> result = new ArraySet<>();
6487 for (String key : prefs.keySet()) {
6488 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6489 final String number = (String) prefs.get(key);
6490 if (mergeNumber.equals(number)) {
6491 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6492 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6493 final String subscriberId = (String) prefs.get(subscriberKey);
6494 if (!TextUtils.isEmpty(subscriberId)) {
6495 result.add(subscriberId);
6496 }
6497 }
6498 }
6499 }
6500
6501 final String[] resultArray = result.toArray(new String[result.size()]);
6502 Arrays.sort(resultArray);
6503 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006504 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006505 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6506 }
6507 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006508 } finally {
6509 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006510 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006511 }
6512
6513 @Override
zoey chen38003472019-12-13 17:16:31 +08006514 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6515 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006516
6517 final long identity = Binder.clearCallingIdentity();
6518 try {
6519 final TelephonyManager telephonyManager = mApp.getSystemService(
6520 TelephonyManager.class);
6521 String subscriberId = telephonyManager.getSubscriberId(subId);
6522 if (subscriberId == null) {
6523 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006524 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006525 + subId);
6526 }
6527 return null;
6528 }
6529
6530 final SubscriptionInfo info = SubscriptionController.getInstance()
6531 .getSubscriptionInfo(subId);
6532 final ParcelUuid groupUuid = info.getGroupUuid();
6533 // If it doesn't belong to any group, return just subscriberId of itself.
6534 if (groupUuid == null) {
6535 return new String[]{subscriberId};
6536 }
6537
6538 // Get all subscriberIds from the group.
6539 final List<String> mergedSubscriberIds = new ArrayList<>();
6540 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006541 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006542 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006543 for (SubscriptionInfo subInfo : groupInfos) {
6544 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6545 if (subscriberId != null) {
6546 mergedSubscriberIds.add(subscriberId);
6547 }
6548 }
6549
6550 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6551 } finally {
6552 Binder.restoreCallingIdentity(identity);
6553
6554 }
6555 }
6556
6557 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006558 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006559 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006560 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006561
6562 final long identity = Binder.clearCallingIdentity();
6563 try {
6564 final Phone phone = getPhone(subId);
6565 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6566 } finally {
6567 Binder.restoreCallingIdentity(identity);
6568 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006569 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006570
6571 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006572 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006573 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6574 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006575 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6576 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006577
6578 final long identity = Binder.clearCallingIdentity();
6579 try {
6580 final Phone phone = getPhone(subId);
6581 if (phone == null) {
6582 return false;
6583 }
6584 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6585 cdmaNonRoamingList);
6586 } finally {
6587 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006588 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006589 }
6590
6591 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006592 @Deprecated
6593 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6594 enforceModifyPermission();
6595
6596 int returnValue = 0;
6597 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006598 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006599 if(result.exception == null) {
6600 if (result.result != null) {
6601 byte[] responseData = (byte[])(result.result);
6602 if(responseData.length > oemResp.length) {
6603 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6604 responseData.length + "bytes. Buffer Size is " +
6605 oemResp.length + "bytes.");
6606 }
6607 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6608 returnValue = responseData.length;
6609 }
6610 } else {
6611 CommandException ex = (CommandException) result.exception;
6612 returnValue = ex.getCommandError().ordinal();
6613 if(returnValue > 0) returnValue *= -1;
6614 }
6615 } catch (RuntimeException e) {
6616 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6617 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6618 if(returnValue > 0) returnValue *= -1;
6619 }
6620
6621 return returnValue;
6622 }
6623
6624 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006625 public void setRadioCapability(RadioAccessFamily[] rafs) {
6626 try {
6627 ProxyController.getInstance().setRadioCapability(rafs);
6628 } catch (RuntimeException e) {
6629 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6630 }
6631 }
6632
6633 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006634 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006635 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006636 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006637 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006638 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006640 final long identity = Binder.clearCallingIdentity();
6641 try {
chen xub97461a2018-10-26 14:17:57 -07006642 TelephonyPermissions
6643 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6644 mApp, phone.getSubId(), "getRadioAccessFamily");
6645 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006646 } finally {
6647 Binder.restoreCallingIdentity(identity);
6648 }
chen xub97461a2018-10-26 14:17:57 -07006649 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006650 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006651
6652 @Override
6653 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006654 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006655 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656
6657 final long identity = Binder.clearCallingIdentity();
6658 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006659 ImsManager.getInstance(defaultPhone.getContext(),
6660 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006661 } finally {
6662 Binder.restoreCallingIdentity(identity);
6663 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006664 }
6665
6666 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006667 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006668 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6670 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006671 return false;
6672 }
Svet Ganovb320e182015-04-16 12:30:10 -07006673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006674 final long identity = Binder.clearCallingIdentity();
6675 try {
6676 // Check the user preference and the system-level IMS setting. Even if the user has
6677 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6678 // In the long run, we may instead need to check if there exists a connection service
6679 // which can support video calling.
6680 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006681 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006682 return imsManager.isVtEnabledByPlatform()
6683 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6684 && imsManager.isVtEnabledByUser();
6685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006688 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006689
Andrew Leea1239f22015-03-02 17:44:07 -08006690 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006691 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6692 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006694 mApp, subId, callingPackage, callingFeatureId,
6695 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006696 return false;
6697 }
6698
6699 final long identity = Binder.clearCallingIdentity();
6700 try {
6701 CarrierConfigManager configManager =
6702 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006703 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006704 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6705 } finally {
6706 Binder.restoreCallingIdentity(identity);
6707 }
Andrew Leea1239f22015-03-02 17:44:07 -08006708 }
6709
6710 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006711 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006713 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 return false;
6715 }
6716
6717 final long identity = Binder.clearCallingIdentity();
6718 try {
6719 CarrierConfigManager configManager =
6720 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006721 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006722 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6723 } finally {
6724 Binder.restoreCallingIdentity(identity);
6725 }
Andrew Leea1239f22015-03-02 17:44:07 -08006726 }
6727
Andrew Lee9431b832015-03-09 18:46:45 -07006728 @Override
6729 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006730 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006731 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006732 }
6733
6734 @Override
6735 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736 final long identity = Binder.clearCallingIdentity();
6737 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006738 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006739 } finally {
6740 Binder.restoreCallingIdentity(identity);
6741 }
Andrew Lee9431b832015-03-09 18:46:45 -07006742 }
6743
Hall Liuf6668912018-10-31 17:05:23 -07006744 /**
6745 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6746 * support for the feature and device firmware support.
6747 *
6748 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6749 */
6750 @Override
6751 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006752 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006753 final Phone phone = getPhone(subscriptionId);
6754 if (phone == null) {
6755 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6756 return false;
6757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006759 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6761 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006762 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 return isCarrierSupported && isDeviceSupported;
6764 } finally {
6765 Binder.restoreCallingIdentity(identity);
6766 }
Hall Liu98187582018-01-22 19:15:32 -08006767 }
6768
Hall Liuf6668912018-10-31 17:05:23 -07006769 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006770 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6771 * RTT setting, will return true if the device and carrier both support RTT.
6772 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006773 */
6774 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775 final long identity = Binder.clearCallingIdentity();
6776 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006777 boolean isRttSupported = isRttSupported(subscriptionId);
6778 boolean isUserRttSettingOn = Settings.Secure.getInt(
6779 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6780 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6781 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6782 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783 } finally {
6784 Binder.restoreCallingIdentity(identity);
6785 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006786 }
6787
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006788 @Deprecated
6789 @Override
6790 public String getDeviceId(String callingPackage) {
6791 return getDeviceIdWithFeature(callingPackage, null);
6792 }
6793
Sanket Padawe7310cc72015-01-14 09:53:20 -08006794 /**
6795 * Returns the unique device ID of phone, for example, the IMEI for
6796 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6797 *
6798 * <p>Requires Permission:
6799 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6800 */
6801 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006802 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006803 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006804 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006805 return null;
6806 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006807 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006808 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006809 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006810 return null;
6811 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006812
6813 final long identity = Binder.clearCallingIdentity();
6814 try {
6815 return phone.getDeviceId();
6816 } finally {
6817 Binder.restoreCallingIdentity(identity);
6818 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006819 }
6820
Ping Sunc67b7c22016-03-02 19:16:45 +08006821 /**
6822 * {@hide}
6823 * Returns the IMS Registration Status on a particular subid
6824 *
6825 * @param subId
6826 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006827 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006828 Phone phone = getPhone(subId);
6829 if (phone != null) {
6830 return phone.isImsRegistered();
6831 } else {
6832 return false;
6833 }
6834 }
6835
Santos Cordon7a1885b2015-02-03 11:15:19 -08006836 @Override
6837 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006838 final long identity = Binder.clearCallingIdentity();
6839 try {
6840 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6841 } finally {
6842 Binder.restoreCallingIdentity(identity);
6843 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006844 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006845
Tyler Gunnf70ed162019-04-03 15:28:53 -07006846 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006847 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006848 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006850 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006851 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6852 }
6853 final long identity = Binder.clearCallingIdentity();
6854 try {
6855 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6856 } finally {
6857 Binder.restoreCallingIdentity(identity);
6858 }
6859 }
6860
6861 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006862 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006863 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6864 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006865 final long identity = Binder.clearCallingIdentity();
6866 try {
6867 Phone phone = getPhone(subscriptionId);
6868 if (phone == null) {
6869 return null;
6870 }
6871 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6872 } finally {
6873 Binder.restoreCallingIdentity(identity);
6874 }
6875 }
6876
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006877 /**
6878 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006879 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006880 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881 final long identity = Binder.clearCallingIdentity();
6882 try {
6883 Phone phone = getPhone(subId);
6884 if (phone != null) {
6885 return phone.isWifiCallingEnabled();
6886 } else {
6887 return false;
6888 }
6889 } finally {
6890 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006891 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006892 }
6893
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006894 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006895 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006896 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006897 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006898 final long identity = Binder.clearCallingIdentity();
6899 try {
6900 Phone phone = getPhone(subId);
6901 if (phone != null) {
6902 return phone.isVideoEnabled();
6903 } else {
6904 return false;
6905 }
6906 } finally {
6907 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006908 }
6909 }
6910
6911 /**
6912 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6913 * defined in {@link ImsRegistrationImplBase}.
6914 */
6915 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006916 final long identity = Binder.clearCallingIdentity();
6917 try {
6918 Phone phone = getPhone(subId);
6919 if (phone != null) {
6920 return phone.getImsRegistrationTech();
6921 } else {
6922 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6923 }
6924 } finally {
6925 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006926 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006927 }
6928
Stuart Scott8eef64f2015-04-08 15:13:54 -07006929 @Override
6930 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006931 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006932 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6933 return;
6934 }
6935
Svet Ganovcc087f82015-05-12 20:35:54 -07006936 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006937
Svet Ganovcc087f82015-05-12 20:35:54 -07006938 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006939 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6940 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006941 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006942 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006943 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006944 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006945 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6946 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006947 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006948 // There has been issues when Sms raw table somehow stores orphan
6949 // fragments. They lead to garbled message when new fragments come
6950 // in and combined with those stale ones. In case this happens again,
6951 // user can reset all network settings which will clean up this table.
6952 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006953 // Clean up IMS settings as well here.
6954 int slotId = getSlotIndex(subId);
6955 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6956 ImsManager.getInstance(mApp, slotId).factoryReset();
6957 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006958
6959 // Erase modem config if erase modem on network setting is enabled.
6960 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6961 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6962 if (configValue != null && Boolean.parseBoolean(configValue)) {
6963 sendEraseModemConfig(getDefaultPhone());
6964 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006965 } finally {
6966 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006967 }
6968 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006969
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006970 private void cleanUpSmsRawTable(Context context) {
6971 ContentResolver resolver = context.getContentResolver();
6972 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6973 resolver.delete(uri, null, null);
6974 }
6975
Narayan Kamath1c496c22015-04-16 14:40:19 +01006976 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006977 public String getSimLocaleForSubscriber(int subId) {
6978 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6979 final Phone phone = getPhone(subId);
6980 if (phone == null) {
6981 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006982 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006983 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006984 final long identity = Binder.clearCallingIdentity();
6985 try {
chen xu5d3637b2019-01-21 23:31:38 -08006986 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006987 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006988 if (info == null) {
6989 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6990 return null;
6991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992 // Try and fetch the locale from the carrier properties or from the SIM language
6993 // preferences (EF-PL and EF-LI)...
6994 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006996 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6997 if (localeFromDefaultSim != null) {
6998 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6999 if (DBG) log("Using locale from subId: " + subId + " locale: "
7000 + localeFromDefaultSim);
7001 return localeFromDefaultSim.toLanguageTag();
7002 } else {
7003 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004 }
7005 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007 // The SIM language preferences only store a language (e.g. fr = French), not an
7008 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7009 // the SIM and carrier preferences does not include a country we add the country
7010 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007011 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007013 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014 return mccLocale.toLanguageTag();
7015 }
7016
7017 if (DBG) log("No locale found - returning null");
7018 return null;
7019 } finally {
7020 Binder.restoreCallingIdentity(identity);
7021 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007022 }
7023
7024 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007025 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007026 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007027 }
7028
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 /**
7030 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7031 */
7032 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007033 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007034 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007035 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007036
Chenjie Yu1ba97252018-01-11 18:16:20 -08007037 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007038 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007039
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007040 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007041 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7042 * representing the state of the modem.
7043 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007044 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7045 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007046 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007047 */
7048 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007049 public void requestModemActivityInfo(ResultReceiver result) {
7050 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007051 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052
7053 final long identity = Binder.clearCallingIdentity();
7054 try {
sqian1a1be542020-03-05 11:37:28 -08007055 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007056 } finally {
7057 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007058 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007059 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007060
Siddharth Rayb8114062018-06-17 15:02:38 -07007061 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7062 // less than total activity duration.
7063 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7064 if (info == null) {
7065 return false;
7066 }
7067 int activityDurationMs =
7068 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7069 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007070 int[] txTimeMs = info.getTransmitTimeMillis();
7071 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7072 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007073 }
7074 return (info.isValid()
7075 && (info.getSleepTimeMillis() <= activityDurationMs)
7076 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007077 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007078 && (totalTxTimeMs <= activityDurationMs));
7079 }
7080
Jack Yu85bd38a2015-11-09 11:34:32 -08007081 /**
7082 * {@hide}
7083 * Returns the service state information on specified subscription.
7084 */
7085 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007086 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7087 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007089 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007090 return null;
7091 }
7092
Hall Liuf19c44f2018-11-27 14:38:17 -08007093 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7094 LocationAccessPolicy.checkLocationPermission(mApp,
7095 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7096 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007097 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007098 .setCallingPid(Binder.getCallingPid())
7099 .setCallingUid(Binder.getCallingUid())
7100 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007101 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007102 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7103 .build());
7104
7105 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7106 LocationAccessPolicy.checkLocationPermission(mApp,
7107 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7108 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007109 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007110 .setCallingPid(Binder.getCallingPid())
7111 .setCallingUid(Binder.getCallingUid())
7112 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007113 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007114 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7115 .build());
7116 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7117 boolean hasFinePermission =
7118 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7119 boolean hasCoarsePermission =
7120 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7121
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 final long identity = Binder.clearCallingIdentity();
7123 try {
7124 final Phone phone = getPhone(subId);
7125 if (phone == null) {
7126 return null;
7127 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007128
Hall Liuf19c44f2018-11-27 14:38:17 -08007129 ServiceState ss = phone.getServiceState();
7130
7131 // Scrub out the location info in ServiceState depending on what level of access
7132 // the caller has.
7133 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007134 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7135 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136 } finally {
7137 Binder.restoreCallingIdentity(identity);
7138 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007139 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007140
7141 /**
7142 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7143 *
7144 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7145 * voicemail ringtone.
7146 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7147 * PhoneAccount.
7148 */
7149 @Override
7150 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151 final long identity = Binder.clearCallingIdentity();
7152 try {
7153 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7154 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007155 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007156 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007158 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7159 } finally {
7160 Binder.restoreCallingIdentity(identity);
7161 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007162 }
7163
7164 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007165 * Sets the per-account voicemail ringtone.
7166 *
7167 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7168 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7169 *
7170 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7171 * voicemail ringtone.
7172 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7173 * PhoneAccount.
7174 */
7175 @Override
7176 public void setVoicemailRingtoneUri(String callingPackage,
7177 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007178 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007179 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007180 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7181 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7183 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7184 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007185 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007186
7187 final long identity = Binder.clearCallingIdentity();
7188 try {
7189 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7190 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007191 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007192 }
7193 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7194 } finally {
7195 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007196 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007197 }
7198
7199 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007200 * Returns whether vibration is set for voicemail notification in Phone settings.
7201 *
7202 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7203 * voicemail vibration setting.
7204 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7205 */
7206 @Override
7207 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007208 final long identity = Binder.clearCallingIdentity();
7209 try {
7210 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7211 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007212 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007213 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007215 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7216 } finally {
7217 Binder.restoreCallingIdentity(identity);
7218 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007219 }
7220
Youhan Wange64578a2016-05-02 15:32:42 -07007221 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007222 * Sets the per-account voicemail vibration.
7223 *
7224 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7225 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7226 *
7227 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7228 * voicemail vibration setting.
7229 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7230 * specific PhoneAccount.
7231 */
7232 @Override
7233 public void setVoicemailVibrationEnabled(String callingPackage,
7234 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007235 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007236 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007237 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7238 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7240 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7241 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007242 }
7243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007244 final long identity = Binder.clearCallingIdentity();
7245 try {
7246 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7247 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007248 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007249 }
7250 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7251 } finally {
7252 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007253 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007254 }
7255
7256 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007257 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7258 *
7259 * @throws SecurityException if the caller does not have the required permission
7260 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007261 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007262 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007263 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007264 }
7265
7266 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007267 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7268 * permission.
7269 *
7270 * @throws SecurityException if the caller does not have the required permission
7271 */
7272 private void enforceSendSmsPermission() {
7273 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7274 }
7275
7276 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007277 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007278 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007279 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007280 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007281 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282 final long identity = Binder.clearCallingIdentity();
7283 try {
7284 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007285 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007286 if (componentName == null) {
7287 throw new SecurityException(
7288 "Caller not current active visual voicemail package[null]");
7289 }
7290 String vvmPackage = componentName.getPackageName();
7291 if (!callingPackage.equals(vvmPackage)) {
7292 throw new SecurityException("Caller not current active visual voicemail package["
7293 + vvmPackage + "]");
7294 }
7295 } finally {
7296 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007297 }
7298 }
7299
7300 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007301 * Return the application ID for the app type.
7302 *
7303 * @param subId the subscription ID that this request applies to.
7304 * @param appType the uicc app type.
7305 * @return Application ID for specificied app type, or null if no uicc.
7306 */
7307 @Override
7308 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007309 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007310 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007311
7312 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007313 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007314 if (phone == null) {
7315 return null;
7316 }
7317 String aid = null;
7318 try {
7319 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7320 .getApplicationByType(appType).getAid();
7321 } catch (Exception e) {
7322 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7323 }
7324 return aid;
7325 } finally {
7326 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007327 }
Youhan Wange64578a2016-05-02 15:32:42 -07007328 }
7329
Youhan Wang4001d252016-05-11 10:29:41 -07007330 /**
7331 * Return the Electronic Serial Number.
7332 *
7333 * @param subId the subscription ID that this request applies to.
7334 * @return ESN or null if error.
7335 */
7336 @Override
7337 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007338 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007339 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007340
7341 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007342 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007343 if (phone == null) {
7344 return null;
7345 }
7346 String esn = null;
7347 try {
7348 esn = phone.getEsn();
7349 } catch (Exception e) {
7350 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7351 }
7352 return esn;
7353 } finally {
7354 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007355 }
Youhan Wang4001d252016-05-11 10:29:41 -07007356 }
7357
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007358 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007359 * Return the Preferred Roaming List Version.
7360 *
7361 * @param subId the subscription ID that this request applies to.
7362 * @return PRLVersion or null if error.
7363 */
7364 @Override
7365 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007366 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007367 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007368
7369 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007370 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007371 if (phone == null) {
7372 return null;
7373 }
7374 String cdmaPrlVersion = null;
7375 try {
7376 cdmaPrlVersion = phone.getCdmaPrlVersion();
7377 } catch (Exception e) {
7378 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7379 }
7380 return cdmaPrlVersion;
7381 } finally {
7382 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007383 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007384 }
7385
7386 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007387 * Get snapshot of Telephony histograms
7388 * @return List of Telephony histograms
7389 * @hide
7390 */
7391 @Override
7392 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7394 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007395
7396 final long identity = Binder.clearCallingIdentity();
7397 try {
7398 return RIL.getTelephonyRILTimingHistograms();
7399 } finally {
7400 Binder.restoreCallingIdentity(identity);
7401 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007402 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007403
7404 /**
7405 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007406 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7407 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007408 * Require system privileges. In the future we may add this to carrier APIs.
7409 *
Michele Berionne482f8202018-11-27 18:57:59 -08007410 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007411 */
7412 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007413 @TelephonyManager.SetCarrierRestrictionResult
7414 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007415 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007416 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007417
Michele Berionne482f8202018-11-27 18:57:59 -08007418 if (carrierRestrictionRules == null) {
7419 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007420 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007422 final long identity = Binder.clearCallingIdentity();
7423 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007424 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007425 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 } finally {
7427 Binder.restoreCallingIdentity(identity);
7428 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007429 }
7430
7431 /**
7432 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007433 * Get the allowed carrier list and the excluded carrier list, including the priority between
7434 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007435 * Require system privileges. In the future we may add this to carrier APIs.
7436 *
Michele Berionne482f8202018-11-27 18:57:59 -08007437 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007438 */
7439 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007440 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007441 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007442 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443
7444 final long identity = Binder.clearCallingIdentity();
7445 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007446 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7447 if (response instanceof CarrierRestrictionRules) {
7448 return (CarrierRestrictionRules) response;
7449 }
7450 // Response is an Exception of some kind,
7451 // which is signalled to the user as a NULL retval
7452 return null;
7453 } catch (Exception e) {
7454 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7455 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 } finally {
7457 Binder.restoreCallingIdentity(identity);
7458 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007459 }
7460
fionaxu59545b42016-05-25 15:53:37 -07007461 /**
fionaxu59545b42016-05-25 15:53:37 -07007462 * Action set from carrier signalling broadcast receivers to enable/disable radio
7463 * @param subId the subscription ID that this action applies to.
7464 * @param enabled control enable or disable radio.
7465 * {@hide}
7466 */
7467 @Override
7468 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7469 enforceModifyPermission();
7470 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007471
7472 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007473 if (phone == null) {
7474 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7475 return;
7476 }
7477 try {
7478 phone.carrierActionSetRadioEnabled(enabled);
7479 } catch (Exception e) {
7480 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 } finally {
7482 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007483 }
7484 }
7485
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007486 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007487 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7488 * network status based on which carrier apps could apply actions accordingly,
7489 * enable/disable default url handler for example.
7490 *
7491 * @param subId the subscription ID that this action applies to.
7492 * @param report control start/stop reporting the default network status.
7493 * {@hide}
7494 */
7495 @Override
7496 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7497 enforceModifyPermission();
7498 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499
7500 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007501 if (phone == null) {
7502 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7503 return;
7504 }
7505 try {
7506 phone.carrierActionReportDefaultNetworkStatus(report);
7507 } catch (Exception e) {
7508 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 } finally {
7510 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007511 }
7512 }
7513
7514 /**
fionaxud9622282017-07-17 17:51:30 -07007515 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7516 * @param subId the subscription ID that this action applies to.
7517 * {@hide}
7518 */
7519 @Override
7520 public void carrierActionResetAll(int subId) {
7521 enforceModifyPermission();
7522 final Phone phone = getPhone(subId);
7523 if (phone == null) {
7524 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7525 return;
7526 }
7527 try {
7528 phone.carrierActionResetAll();
7529 } catch (Exception e) {
7530 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7531 }
7532 }
7533
7534 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007535 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7536 * bug report is being generated.
7537 */
7538 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007539 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007540 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7541 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007542 writer.println("Permission Denial: can't dump Phone from pid="
7543 + Binder.getCallingPid()
7544 + ", uid=" + Binder.getCallingUid()
7545 + "without permission "
7546 + android.Manifest.permission.DUMP);
7547 return;
7548 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007549 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007550 }
Jack Yueb89b242016-06-22 13:27:47 -07007551
Brad Ebingerdac2f002018-04-03 15:17:52 -07007552 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007553 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7554 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7555 @NonNull String[] args) {
7556 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7557 this, in.getFileDescriptor(), out.getFileDescriptor(),
7558 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007559 }
7560
Jack Yueb89b242016-06-22 13:27:47 -07007561 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007562 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007563 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007564 * @param reason the reason the data enable change is taking place
7565 * @param enabled True if enabling the data, otherwise disabling.
7566 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007567 */
7568 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007569 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007570 boolean enabled) {
7571 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7572 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7573 try {
7574 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007575 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007576 } catch (SecurityException se) {
7577 enforceModifyPermission();
7578 }
7579 } else {
7580 enforceModifyPermission();
7581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007582
7583 final long identity = Binder.clearCallingIdentity();
7584 try {
7585 Phone phone = getPhone(subId);
7586 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007587 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7588 phone.carrierActionSetMeteredApnsEnabled(enabled);
7589 } else {
7590 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7591 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007592 }
7593 } finally {
7594 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007595 }
7596 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007597
7598 /**
7599 * Get Client request stats
7600 * @return List of Client Request Stats
7601 * @hide
7602 */
7603 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007604 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7605 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007606 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007607 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007608 return null;
7609 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007610 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007612 final long identity = Binder.clearCallingIdentity();
7613 try {
7614 if (phone != null) {
7615 return phone.getClientRequestStats();
7616 }
7617
7618 return null;
7619 } finally {
7620 Binder.restoreCallingIdentity(identity);
7621 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007622 }
7623
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007624 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007625 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007626 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007627 }
Jack Yueb4124c2017-02-16 15:32:43 -08007628
7629 /**
Grace Chen70990072017-03-24 17:21:30 -07007630 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007631 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007632 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007633 * @param state State of SIM (power down, power up, pass through)
7634 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7635 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7636 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007637 *
7638 **/
7639 @Override
Grace Chen70990072017-03-24 17:21:30 -07007640 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007641 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007642 Phone phone = PhoneFactory.getPhone(slotIndex);
7643
vagdeviaf9a5b92018-08-15 16:01:53 -07007644 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007646 final long identity = Binder.clearCallingIdentity();
7647 try {
7648 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007649 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007650 }
7651 } finally {
7652 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007653 }
7654 }
Shuo Qiandd210312017-04-12 22:11:33 +00007655
Tyler Gunn65d45c22017-06-05 11:22:26 -07007656 private boolean isUssdApiAllowed(int subId) {
7657 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007658 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007659 if (configManager == null) {
7660 return false;
7661 }
7662 PersistableBundle pb = configManager.getConfigForSubId(subId);
7663 if (pb == null) {
7664 return false;
7665 }
7666 return pb.getBoolean(
7667 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7668 }
7669
Shuo Qiandd210312017-04-12 22:11:33 +00007670 /**
7671 * Check if phone is in emergency callback mode
7672 * @return true if phone is in emergency callback mode
7673 * @param subId sub id
7674 */
goneil9c5f4872017-12-05 14:07:56 -08007675 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007676 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007677 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007678 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679
7680 final long identity = Binder.clearCallingIdentity();
7681 try {
7682 if (phone != null) {
7683 return phone.isInEcm();
7684 } else {
7685 return false;
7686 }
7687 } finally {
7688 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007689 }
7690 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007691
7692 /**
7693 * Get the current signal strength information for the given subscription.
7694 * Because this information is not updated when the device is in a low power state
7695 * it should not be relied-upon to be current.
7696 * @param subId Subscription index
7697 * @return the most recent cached signal strength info from the modem
7698 */
7699 @Override
7700 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 final long identity = Binder.clearCallingIdentity();
7702 try {
7703 Phone p = getPhone(subId);
7704 if (p == null) {
7705 return null;
7706 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708 return p.getSignalStrength();
7709 } finally {
7710 Binder.restoreCallingIdentity(identity);
7711 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007712 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007713
Pengquan Meng77b7f132018-08-22 14:49:57 -07007714 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007715 * Get the current modem radio state for the given slot.
7716 * @param slotIndex slot index.
7717 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007718 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007719 * @return the current radio power state from the modem
7720 */
7721 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007722 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007723 Phone phone = PhoneFactory.getPhone(slotIndex);
7724 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7726 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007727 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7728 }
7729
7730 final long identity = Binder.clearCallingIdentity();
7731 try {
7732 return phone.getRadioPowerState();
7733 } finally {
7734 Binder.restoreCallingIdentity(identity);
7735 }
7736 }
7737 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7738 }
7739
7740 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007741 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7742 *
7743 * <p>Requires one of the following permissions:
7744 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7745 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7746 * privileges.
7747 *
7748 * @param subId subscription id
7749 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7750 * {@code false}.
7751 */
7752 @Override
7753 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007754 try {
7755 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7756 null);
7757 } catch (Exception e) {
7758 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7759 mApp, subId, "isDataRoamingEnabled");
7760 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007761
Pengquan Menga1bb6272018-09-06 09:59:22 -07007762 boolean isEnabled = false;
7763 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007764 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007765 Phone phone = getPhone(subId);
7766 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007767 } finally {
7768 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007769 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007770 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007771 }
7772
7773
7774 /**
7775 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7776 *
7777 * <p> Requires permission:
7778 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7779 * privileges.
7780 *
7781 * @param subId subscription id
7782 * @param isEnabled {@code true} means enable, {@code false} means disable.
7783 */
7784 @Override
7785 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7787 mApp, subId, "setDataRoamingEnabled");
7788
Pengquan Menga1bb6272018-09-06 09:59:22 -07007789 final long identity = Binder.clearCallingIdentity();
7790 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007791 Phone phone = getPhone(subId);
7792 if (phone != null) {
7793 phone.setDataRoamingEnabled(isEnabled);
7794 }
7795 } finally {
7796 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007797 }
7798 }
7799
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007800 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007801 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007802 TelephonyPermissions
7803 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007804 mApp, subId, "isManualNetworkSelectionAllowed");
7805
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007806 boolean isAllowed = true;
7807 final long identity = Binder.clearCallingIdentity();
7808 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007809 Phone phone = getPhone(subId);
7810 if (phone != null) {
7811 isAllowed = phone.isCspPlmnEnabled();
7812 }
7813 } finally {
7814 Binder.restoreCallingIdentity(identity);
7815 }
7816 return isAllowed;
7817 }
7818
7819 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007820 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007821 // Verify that tha callingPackage belongs to the calling UID
7822 mApp.getSystemService(AppOpsManager.class)
7823 .checkPackage(Binder.getCallingUid(), callingPackage);
7824
Jordan Liu1e142fc2019-04-22 15:10:43 -07007825 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007826 try {
7827 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007828 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007829 } catch (SecurityException e) {
7830 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7831 // has carrier privileges on an active UICC
7832 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7833 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007834 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007835 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007836 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007837
7838 final long identity = Binder.clearCallingIdentity();
7839 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007840 UiccController uiccController = UiccController.getInstance();
7841 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007842 if (hasReadPermission) {
7843 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007844 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007845
7846 // Remove private info if the caller doesn't have access
7847 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7848 for (UiccCardInfo cardInfo : cardInfos) {
7849 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7850 // is available
7851 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7852 if (card == null || card.getUiccProfile() == null) {
7853 // assume no access if the card or profile is unavailable
7854 filteredInfos.add(cardInfo.getUnprivileged());
7855 continue;
7856 }
7857 UiccProfile profile = card.getUiccProfile();
7858 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7859 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7860 filteredInfos.add(cardInfo);
7861 } else {
7862 filteredInfos.add(cardInfo.getUnprivileged());
7863 }
7864 }
7865 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007866 } finally {
7867 Binder.restoreCallingIdentity(identity);
7868 }
7869 }
7870
7871 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007872 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007873 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007874
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007875 final long identity = Binder.clearCallingIdentity();
7876 try {
7877 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7878 if (slots == null) {
7879 Rlog.i(LOG_TAG, "slots is null.");
7880 return null;
7881 }
7882
7883 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7884 for (int i = 0; i < slots.length; i++) {
7885 UiccSlot slot = slots[i];
7886 if (slot == null) {
7887 continue;
7888 }
7889
Jordan Liu7be7e652019-05-06 18:55:02 +00007890 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891 UiccCard card = slot.getUiccCard();
7892 if (card != null) {
7893 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007894 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007895 cardId = slot.getEid();
7896 if (TextUtils.isEmpty(cardId)) {
7897 cardId = slot.getIccId();
7898 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007899 }
7900
Jordan Liu857451f2019-05-09 16:35:35 -07007901 if (cardId != null) {
7902 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7903 // if cardId is an EID, it's all digits so this is fine
7904 cardId = IccUtils.stripTrailingFs(cardId);
7905 }
7906
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007907 int cardState = 0;
7908 switch (slot.getCardState()) {
7909 case CARDSTATE_ABSENT:
7910 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7911 break;
7912 case CARDSTATE_PRESENT:
7913 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7914 break;
7915 case CARDSTATE_ERROR:
7916 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7917 break;
7918 case CARDSTATE_RESTRICTED:
7919 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7920 break;
7921 default:
7922 break;
7923
7924 }
7925
7926 infos[i] = new UiccSlotInfo(
7927 slot.isActive(),
7928 slot.isEuicc(),
7929 cardId,
7930 cardState,
7931 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007932 slot.isExtendedApduSupported(),
7933 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007934 }
7935 return infos;
7936 } finally {
7937 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007938 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007939 }
7940
7941 @Override
7942 public boolean switchSlots(int[] physicalSlots) {
7943 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007944
7945 final long identity = Binder.clearCallingIdentity();
7946 try {
7947 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7948 } finally {
7949 Binder.restoreCallingIdentity(identity);
7950 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007951 }
Jack Yu4c988042018-02-27 15:30:01 -08007952
7953 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007954 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007955 final long identity = Binder.clearCallingIdentity();
7956 try {
7957 return UiccController.getInstance().getCardIdForDefaultEuicc();
7958 } finally {
7959 Binder.restoreCallingIdentity(identity);
7960 }
7961 }
7962
Pengquan Meng85728fb2018-03-12 16:31:21 -07007963 /**
goneil47ffb6e2018-04-06 15:40:58 -07007964 * A test API to reload the UICC profile.
7965 *
7966 * <p>Requires that the calling app has permission
7967 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7968 * @hide
7969 */
7970 @Override
7971 public void refreshUiccProfile(int subId) {
7972 enforceModifyPermission();
7973
7974 final long identity = Binder.clearCallingIdentity();
7975 try {
7976 Phone phone = getPhone(subId);
7977 if (phone == null) {
7978 return;
7979 }
7980 UiccCard uiccCard = phone.getUiccCard();
7981 if (uiccCard == null) {
7982 return;
7983 }
7984 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7985 if (uiccProfile == null) {
7986 return;
7987 }
7988 uiccProfile.refresh();
7989 } finally {
7990 Binder.restoreCallingIdentity(identity);
7991 }
7992 }
7993
7994 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007995 * Returns false if the mobile data is disabled by default, otherwise return true.
7996 */
7997 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007998 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007999 }
8000
8001 /**
8002 * Returns true if the data roaming is enabled by default, i.e the system property
8003 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8004 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8005 */
8006 private boolean getDefaultDataRoamingEnabled(int subId) {
8007 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008008 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008009 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008010 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8011 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8012 return isDataRoamingEnabled;
8013 }
8014
8015 /**
8016 * Returns the default network type for the given {@code subId}, if the default network type is
8017 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8018 */
8019 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008020 List<Integer> list = TelephonyProperties.default_network();
8021 int phoneId = mSubscriptionController.getPhoneId(subId);
8022 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8023 return list.get(phoneId);
8024 }
8025 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008026 }
fionaxua13278b2018-03-21 00:08:13 -07008027
8028 @Override
8029 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008030 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008031 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008032
8033 final long identity = Binder.clearCallingIdentity();
8034 try {
8035 final Phone phone = getPhone(subId);
8036 if (phone == null) {
8037 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8038 return;
8039 }
chen xueaba88a2019-03-15 13:15:10 -07008040 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8041 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008042 if (carrierPrivilegeRules == null) {
8043 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8044 } else {
8045 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047 } finally {
8048 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008049 }
fionaxua13278b2018-03-21 00:08:13 -07008050 }
8051
8052 @Override
8053 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008054 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055
8056 final long identity = Binder.clearCallingIdentity();
8057 try {
8058 final Phone phone = getPhone(subId);
8059 if (phone == null) {
8060 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8061 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8062 }
8063 return phone.getCarrierIdListVersion();
8064 } finally {
8065 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008066 }
fionaxua13278b2018-03-21 00:08:13 -07008067 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008068
8069 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008070 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8071 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008073 mApp, subId, callingPackage, callingFeatureId,
8074 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008075 return -1;
8076 }
8077
8078 final long identity = Binder.clearCallingIdentity();
8079 try {
8080 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8081 } finally {
8082 Binder.restoreCallingIdentity(identity);
8083 }
8084 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008085
8086 @Override
8087 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008088 TelephonyPermissions
8089 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008090 mApp, subId, "getCdmaRoamingMode");
8091
8092 final long identity = Binder.clearCallingIdentity();
8093 try {
8094 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8095 } finally {
8096 Binder.restoreCallingIdentity(identity);
8097 }
8098 }
8099
8100 @Override
8101 public boolean setCdmaRoamingMode(int subId, int mode) {
8102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8103 mApp, subId, "setCdmaRoamingMode");
8104
8105 final long identity = Binder.clearCallingIdentity();
8106 try {
8107 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8108 } finally {
8109 Binder.restoreCallingIdentity(identity);
8110 }
8111 }
8112
8113 @Override
8114 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8116 mApp, subId, "setCdmaSubscriptionMode");
8117
8118 final long identity = Binder.clearCallingIdentity();
8119 try {
8120 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8121 } finally {
8122 Binder.restoreCallingIdentity(identity);
8123 }
8124 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008125
sqianc5eccab2018-10-19 18:46:41 -07008126 @Override
sqian8c685422019-02-22 15:55:18 -08008127 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008128 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008129 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008130 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8131 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008132 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8133 }
8134 final long identity = Binder.clearCallingIdentity();
8135 try {
sqian854d44b2018-12-12 16:48:18 -08008136 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8137 for (Phone phone: PhoneFactory.getPhones()) {
8138 if (phone.getEmergencyNumberTracker() != null
8139 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8140 emergencyNumberListInternal.put(
8141 phone.getSubId(),
8142 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8143 }
sqian11b7a0e2018-12-05 18:48:28 -08008144 }
sqian854d44b2018-12-12 16:48:18 -08008145 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008146 } finally {
8147 Binder.restoreCallingIdentity(identity);
8148 }
sqianc5eccab2018-10-19 18:46:41 -07008149 }
8150
8151 @Override
sqian8c685422019-02-22 15:55:18 -08008152 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008153 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008154 if (!exactMatch) {
8155 TelephonyPermissions
8156 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008157 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008158 }
8159 final long identity = Binder.clearCallingIdentity();
8160 try {
sqian854d44b2018-12-12 16:48:18 -08008161 for (Phone phone: PhoneFactory.getPhones()) {
8162 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008163 && phone.getEmergencyNumberTracker()
8164 .isEmergencyNumber(number, exactMatch)) {
8165 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008166 }
sqian11b7a0e2018-12-05 18:48:28 -08008167 }
8168 return false;
8169 } finally {
8170 Binder.restoreCallingIdentity(identity);
8171 }
8172 }
8173
sqianf4ca7ed2019-01-15 18:32:07 -08008174 /**
8175 * Update emergency number list for test mode.
8176 */
8177 @Override
8178 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8179 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8180 "updateEmergencyNumberListTestMode");
8181
8182 final long identity = Binder.clearCallingIdentity();
8183 try {
8184 for (Phone phone: PhoneFactory.getPhones()) {
8185 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8186 if (tracker != null) {
8187 tracker.executeEmergencyNumberTestModeCommand(action, num);
8188 }
8189 }
8190 } finally {
8191 Binder.restoreCallingIdentity(identity);
8192 }
8193 }
8194
8195 /**
8196 * Get the full emergency number list for test mode.
8197 */
8198 @Override
8199 public List<String> getEmergencyNumberListTestMode() {
8200 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8201 "getEmergencyNumberListTestMode");
8202
8203 final long identity = Binder.clearCallingIdentity();
8204 try {
8205 Set<String> emergencyNumbers = new HashSet<>();
8206 for (Phone phone: PhoneFactory.getPhones()) {
8207 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8208 if (tracker != null) {
8209 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8210 emergencyNumbers.add(num.getNumber());
8211 }
8212 }
8213 }
8214 return new ArrayList<>(emergencyNumbers);
8215 } finally {
8216 Binder.restoreCallingIdentity(identity);
8217 }
8218 }
8219
chen xud6b45bd2018-10-30 22:27:10 -07008220 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008221 public int getEmergencyNumberDbVersion(int subId) {
8222 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8223
8224 final long identity = Binder.clearCallingIdentity();
8225 try {
8226 final Phone phone = getPhone(subId);
8227 if (phone == null) {
8228 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8229 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8230 }
8231 return phone.getEmergencyNumberDbVersion();
8232 } finally {
8233 Binder.restoreCallingIdentity(identity);
8234 }
8235 }
8236
8237 @Override
8238 public void notifyOtaEmergencyNumberDbInstalled() {
8239 enforceModifyPermission();
8240
8241 final long identity = Binder.clearCallingIdentity();
8242 try {
8243 for (Phone phone: PhoneFactory.getPhones()) {
8244 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8245 if (tracker != null) {
8246 tracker.updateOtaEmergencyNumberDatabase();
8247 }
8248 }
8249 } finally {
8250 Binder.restoreCallingIdentity(identity);
8251 }
8252 }
8253
8254 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008255 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008256 enforceActiveEmergencySessionPermission();
8257
8258 final long identity = Binder.clearCallingIdentity();
8259 try {
8260 for (Phone phone: PhoneFactory.getPhones()) {
8261 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8262 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008263 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8264 }
8265 }
8266 } finally {
8267 Binder.restoreCallingIdentity(identity);
8268 }
8269 }
8270
8271 @Override
8272 public void resetOtaEmergencyNumberDbFilePath() {
8273 enforceActiveEmergencySessionPermission();
8274
8275 final long identity = Binder.clearCallingIdentity();
8276 try {
8277 for (Phone phone: PhoneFactory.getPhones()) {
8278 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8279 if (tracker != null) {
8280 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008281 }
8282 }
8283 } finally {
8284 Binder.restoreCallingIdentity(identity);
8285 }
8286 }
8287
8288 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008289 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8290 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8291 Phone phone = getPhone(subId);
8292 if (phone == null) {
8293 return null;
8294 }
8295 final long identity = Binder.clearCallingIdentity();
8296 try {
8297 UiccProfile profile = UiccController.getInstance()
8298 .getUiccProfileForPhone(phone.getPhoneId());
8299 if (profile != null) {
8300 return profile.getCertsFromCarrierPrivilegeAccessRules();
8301 }
8302 } finally {
8303 Binder.restoreCallingIdentity(identity);
8304 }
8305 return null;
8306 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008307
8308 /**
8309 * Enable or disable a modem stack.
8310 */
8311 @Override
8312 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8313 enforceModifyPermission();
8314
8315 final long identity = Binder.clearCallingIdentity();
8316 try {
8317 Phone phone = PhoneFactory.getPhone(slotIndex);
8318 if (phone == null) {
8319 return false;
8320 } else {
8321 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8322 }
8323 } finally {
8324 Binder.restoreCallingIdentity(identity);
8325 }
8326 }
Michelecea4cf22018-12-21 15:00:11 -08008327
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008328 /**
8329 * Whether a modem stack is enabled or not.
8330 */
8331 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008332 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8333 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008334 Phone phone = PhoneFactory.getPhone(slotIndex);
8335 if (phone == null) return false;
8336
8337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008338 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8339 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008340 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8341 }
8342
8343 final long identity = Binder.clearCallingIdentity();
8344 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008345 try {
8346 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8347 } catch (NoSuchElementException ex) {
8348 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8349 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008350 } finally {
8351 Binder.restoreCallingIdentity(identity);
8352 }
8353 }
8354
Michelecea4cf22018-12-21 15:00:11 -08008355 @Override
Michele0ea7d782019-03-19 14:58:42 -07008356 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008357 enforceModifyPermission();
8358
8359 final long identity = Binder.clearCallingIdentity();
8360 try {
8361 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008362 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008363 .commit();
8364 } finally {
8365 Binder.restoreCallingIdentity(identity);
8366 }
8367 }
8368
8369 @Override
Michele0ea7d782019-03-19 14:58:42 -07008370 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008371 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008373 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8374 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008375 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008376 }
Michelecea4cf22018-12-21 15:00:11 -08008377
8378 final long identity = Binder.clearCallingIdentity();
8379 try {
Michele0ea7d782019-03-19 14:58:42 -07008380 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008381 } finally {
8382 Binder.restoreCallingIdentity(identity);
8383 }
8384 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008385
Michele0ea7d782019-03-19 14:58:42 -07008386 @TelephonyManager.IsMultiSimSupportedResult
8387 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008388 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8389 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8390 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008391 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8392 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008393 }
8394 // Check if the hardware supports multisim functionality. If usage of multisim is not
8395 // supported by the modem, indicate that it is restricted.
8396 PhoneCapability staticCapability =
8397 mPhoneConfigurationManager.getStaticPhoneCapability();
8398 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008399 loge("isMultiSimSupportedInternal: no static configuration available");
8400 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008401 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008402 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008403 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8404 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008405 }
8406 // Check if support of multiple SIMs is restricted by carrier
8407 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008408 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008409 }
8410
Michele0ea7d782019-03-19 14:58:42 -07008411 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008412 }
8413
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008414 /**
8415 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008416 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8417 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8418 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008419 * @param numOfSims number of active sims we want to switch to
8420 */
8421 @Override
8422 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008423 if (numOfSims == 1) {
8424 enforceModifyPermission();
8425 } else {
8426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8427 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8428 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008429 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008430
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008431 try {
Michele30b57b22019-03-01 12:01:14 -08008432 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008433 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008434 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8435 return;
8436 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008437 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8438 } finally {
8439 Binder.restoreCallingIdentity(identity);
8440 }
8441 }
8442
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008443 @Override
8444 public boolean isApplicationOnUicc(int subId, int appType) {
8445 enforceReadPrivilegedPermission("isApplicationOnUicc");
8446 Phone phone = getPhone(subId);
8447 if (phone == null) {
8448 return false;
8449 }
8450 final long identity = Binder.clearCallingIdentity();
8451 try {
8452 UiccCard uiccCard = phone.getUiccCard();
8453 if (uiccCard == null) {
8454 return false;
8455 }
8456 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8457 if (uiccProfile == null) {
8458 return false;
8459 }
8460 if (TelephonyManager.APPTYPE_SIM <= appType
8461 && appType <= TelephonyManager.APPTYPE_ISIM) {
8462 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8463 }
8464 return false;
8465 } finally {
8466 Binder.restoreCallingIdentity(identity);
8467 }
8468 }
8469
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008470 /**
chen xub4baa772019-04-03 10:23:41 -07008471 * Get whether making changes to modem configurations will trigger reboot.
8472 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008473 */
8474 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008475 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8476 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008478 mApp, subId, callingPackage, callingFeatureId,
8479 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008480 return false;
8481 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008482 final long identity = Binder.clearCallingIdentity();
8483 try {
8484 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8485 } finally {
8486 Binder.restoreCallingIdentity(identity);
8487 }
8488 }
8489
Nathan Harold29f5f052019-02-15 13:41:57 -08008490 private void updateModemStateMetrics() {
8491 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8492 // TODO: check the state for each modem if the api is ready.
8493 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8494 }
8495
Pengquan Meng3889a572019-01-23 11:16:29 -08008496 @Override
8497 public int[] getSlotsMapping() {
8498 enforceReadPrivilegedPermission("getSlotsMapping");
8499
8500 final long identity = Binder.clearCallingIdentity();
8501 try {
8502 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8503 // All logical slots should have a mapping to a physical slot.
8504 int[] logicalSlotsMapping = new int[phoneCount];
8505 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8506 for (int i = 0; i < slotInfos.length; i++) {
8507 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8508 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8509 }
8510 }
8511 return logicalSlotsMapping;
8512 } finally {
8513 Binder.restoreCallingIdentity(identity);
8514 }
8515 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008516
8517 /**
8518 * Get the IRadio HAL Version
8519 */
8520 @Override
8521 public int getRadioHalVersion() {
8522 Phone phone = getDefaultPhone();
8523 if (phone == null) return -1;
8524 HalVersion hv = phone.getHalVersion();
8525 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8526 return hv.major * 100 + hv.minor;
8527 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008528
8529 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008530 * Get the current calling package name.
8531 * @return the current calling package name
8532 */
8533 @Override
8534 public String getCurrentPackageName() {
8535 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8536 }
8537
8538 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008539 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8540 * corresponding network requests on a subId.
8541 *
8542 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008543 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008544 * 2) APN is un-metered for this subscription, or
8545 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008546 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008547 *
8548 * @return whether data is allowed for a apn type.
8549 *
8550 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008551 */
8552 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008553 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008554 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8555 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008556
8557 // Now that all security checks passes, perform the operation as ourselves.
8558 final long identity = Binder.clearCallingIdentity();
8559 try {
8560 Phone phone = getPhone(subId);
8561 if (phone == null) return false;
8562
Jack Yu41407ee2019-05-13 16:54:09 -07008563 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008564 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8565 } finally {
8566 Binder.restoreCallingIdentity(identity);
8567 }
8568 }
8569
8570 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008571 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008572 enforceReadPrivilegedPermission("isApnMetered");
8573
8574 // Now that all security checks passes, perform the operation as ourselves.
8575 final long identity = Binder.clearCallingIdentity();
8576 try {
8577 Phone phone = getPhone(subId);
8578 if (phone == null) return true; // By default return true.
8579
Jack Yu41407ee2019-05-13 16:54:09 -07008580 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008581 } finally {
8582 Binder.restoreCallingIdentity(identity);
8583 }
8584 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008585
8586 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008587 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8588 int subscriptionId, IBooleanConsumer resultCallback) {
8589 enforceModifyPermission();
8590 long token = Binder.clearCallingIdentity();
8591 try {
8592 Phone phone = getPhone(subscriptionId);
8593 if (phone == null) {
8594 try {
8595 if (resultCallback != null) {
8596 resultCallback.accept(false);
8597 }
8598 } catch (RemoteException e) {
8599 // ignore
8600 }
8601 return;
8602 }
8603 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8604 Pair.create(specifiers, (x) -> {
8605 try {
8606 if (resultCallback != null) {
8607 resultCallback.accept(x);
8608 }
8609 } catch (RemoteException e) {
8610 // ignore
8611 }
8612 });
8613 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8614 } finally {
8615 Binder.restoreCallingIdentity(token);
8616 }
8617 }
8618
8619 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008620 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008621 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008622 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8623 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8624 if (iccRecords == null) {
8625 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8626 return false;
8627 }
8628 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8629 }
8630
8631 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008632 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8633 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008634 if (callingPackage == null) {
8635 callingPackage = getCurrentPackageName();
8636 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008637 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8638 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008639 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8640 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008641 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8642 }
8643 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8644 Intent intent = new Intent();
8645 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8646 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8647 // Bring up choose default SMS subscription dialog right now
8648 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8649 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8650 mApp.startActivity(intent);
8651 }
chen xud5ca2d52019-05-28 15:20:57 -07008652
8653 @Override
8654 public String getMmsUAProfUrl(int subId) {
8655 //TODO investigate if this API should require proper permission check in R b/133791609
8656 final long identity = Binder.clearCallingIdentity();
8657 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008658 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8659 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8660 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8661 return carrierUAProfUrl;
8662 }
chen xud5ca2d52019-05-28 15:20:57 -07008663 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8664 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8665 } finally {
8666 Binder.restoreCallingIdentity(identity);
8667 }
8668 }
8669
8670 @Override
8671 public String getMmsUserAgent(int subId) {
8672 //TODO investigate if this API should require proper permission check in R b/133791609
8673 final long identity = Binder.clearCallingIdentity();
8674 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008675 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8676 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8677 if (!TextUtils.isEmpty(carrierUserAgent)) {
8678 return carrierUserAgent;
8679 }
chen xud5ca2d52019-05-28 15:20:57 -07008680 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8681 .getString(com.android.internal.R.string.config_mms_user_agent);
8682 } finally {
8683 Binder.restoreCallingIdentity(identity);
8684 }
8685 }
Jack Yub07d4972019-05-28 16:12:25 -07008686
8687 @Override
Hall Liuc041a552020-09-25 10:42:19 -07008688 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8689 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
8690
8691 final long identity = Binder.clearCallingIdentity();
8692 try {
8693 Phone phone = getPhone(subscriptionId);
8694 if (phone == null) return false;
8695
8696 switch (policy) {
8697 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8698 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8699 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8700 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8701 default:
8702 throw new IllegalArgumentException(policy + " is not a valid policy");
8703 }
8704 } finally {
8705 Binder.restoreCallingIdentity(identity);
8706 }
8707 }
8708
8709 @Override
8710 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8711 boolean enabled) {
8712 enforceModifyPermission();
8713
8714 final long identity = Binder.clearCallingIdentity();
8715 try {
8716 Phone phone = getPhone(subscriptionId);
8717 if (phone == null) return;
8718
8719 switch (policy) {
8720 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8721 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8722 break;
8723 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8724 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8725 break;
8726 default:
8727 throw new IllegalArgumentException(policy + " is not a valid policy");
8728 }
8729 } finally {
8730 Binder.restoreCallingIdentity(identity);
8731 }
8732 }
8733
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008734 /**
Hall Liub48cf452020-09-25 11:13:49 -07008735 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008736 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8737 * otherwise.
8738 */
8739 @Override
8740 public void setCepEnabled(boolean isCepEnabled) {
8741 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8742
8743 final long identity = Binder.clearCallingIdentity();
8744 try {
8745 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8746 for (Phone phone : PhoneFactory.getPhones()) {
8747 Phone defaultPhone = phone.getImsPhone();
8748 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8749 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8750 ImsPhoneCallTracker imsPhoneCallTracker =
8751 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8752 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8753 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8754 + imsPhone.getMsisdn());
8755 }
8756 }
8757 } finally {
8758 Binder.restoreCallingIdentity(identity);
8759 }
8760 }
allenwtsu46dcc572020-01-08 18:24:03 +08008761
8762 /**
8763 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8764 *
8765 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8766 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8767 * before being read.
8768 */
8769 @Override
8770 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8771 isCompressed) {
8772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8773 mApp, subId, "notifyRcsAutoConfigurationReceived");
8774 try {
8775 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8776 if (configBinder == null) {
8777 Rlog.e(LOG_TAG, "null result for getImsConfig");
8778 } else {
8779 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8780 }
8781 } catch (RemoteException e) {
8782 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8783 }
8784 }
zoey chenf95ca592019-12-30 16:11:23 +08008785
8786 @Override
8787 public boolean isIccLockEnabled(int subId) {
8788 enforceReadPrivilegedPermission("isIccLockEnabled");
8789
8790 // Now that all security checks passes, perform the operation as ourselves.
8791 final long identity = Binder.clearCallingIdentity();
8792 try {
8793 Phone phone = getPhone(subId);
8794 if (phone != null && phone.getIccCard() != null) {
8795 return phone.getIccCard().getIccLockEnabled();
8796 } else {
8797 return false;
8798 }
8799 } finally {
8800 Binder.restoreCallingIdentity(identity);
8801 }
8802 }
8803
8804 /**
zoey chene02881a2019-12-30 16:11:23 +08008805 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08008806 *
zoey chene02881a2019-12-30 16:11:23 +08008807 * @return an integer representing the status of IccLock enabled or disabled in the following
8808 * three cases:
8809 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8810 * successfully.
8811 * - Positive number and zero for remaining password attempts.
8812 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008813 *
8814 */
8815 @Override
8816 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8817 enforceModifyPermission();
8818
8819 Phone phone = getPhone(subId);
8820 if (phone == null) {
8821 return 0;
8822 }
8823 // Now that all security checks passes, perform the operation as ourselves.
8824 final long identity = Binder.clearCallingIdentity();
8825 try {
8826 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8827 new Pair<Boolean, String>(enabled, password), phone, null);
8828 return attemptsRemaining;
8829
8830 } catch (Exception e) {
8831 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8832 } finally {
8833 Binder.restoreCallingIdentity(identity);
8834 }
8835 return 0;
8836 }
8837
8838 /**
8839 * Change the ICC password used in ICC pin lock.
8840 *
zoey chene02881a2019-12-30 16:11:23 +08008841 * @return an integer representing the status of IccLock changed in the following three cases:
8842 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8843 * - Positive number and zero for remaining password attempts.
8844 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008845 *
8846 */
8847 @Override
8848 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8849 enforceModifyPermission();
8850
8851 Phone phone = getPhone(subId);
8852 if (phone == null) {
8853 return 0;
8854 }
8855 // Now that all security checks passes, perform the operation as ourselves.
8856 final long identity = Binder.clearCallingIdentity();
8857 try {
8858 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8859 new Pair<String, String>(oldPassword, newPassword), phone, null);
8860 return attemptsRemaining;
8861
8862 } catch (Exception e) {
8863 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8864 } finally {
8865 Binder.restoreCallingIdentity(identity);
8866 }
8867 return 0;
8868 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008869
Peter Wangdafb9ac2020-01-15 14:13:38 -08008870 /**
8871 * Request for receiving user activity notification
8872 */
8873 @Override
8874 public void requestUserActivityNotification() {
8875 if (!mNotifyUserActivity.get()
8876 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8877 mNotifyUserActivity.set(true);
8878 }
8879 }
8880
8881 /**
8882 * Called when userActivity is signalled in the power manager.
8883 * This is safe to call from any thread, with any window manager locks held or not.
8884 */
8885 @Override
8886 public void userActivity() {
8887 // ***************************************
8888 // * Inherited from PhoneWindowManager *
8889 // ***************************************
8890 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8891 // WITH ITS LOCKS HELD.
8892 //
8893 // This code must be VERY careful about the locks
8894 // it acquires.
8895 // In fact, the current code acquires way too many,
8896 // and probably has lurking deadlocks.
8897
8898 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8899 throw new SecurityException("Only the OS may call notifyUserActivity()");
8900 }
8901
8902 if (mNotifyUserActivity.getAndSet(false)) {
8903 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8904 USER_ACTIVITY_NOTIFICATION_DELAY);
8905 }
8906 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008907
Malcolm Chen884180b2020-04-13 11:59:40 -07008908 @Override
8909 public boolean canConnectTo5GInDsdsMode() {
8910 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8911 }
Jack Yud10cdd42020-09-28 20:28:01 -07008912
8913 @Override
8914 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
8915 String callingFeatureId) {
8916 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
8917 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
8918 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8919 }
8920
8921 Phone phone = getPhone(subId);
8922 if (phone == null) {
8923 throw new RuntimeException("phone is not available");
8924 }
8925 // Now that all security checks passes, perform the operation as ourselves.
8926 final long identity = Binder.clearCallingIdentity();
8927 try {
8928 return phone.getEquivalentHomePlmns();
8929 } finally {
8930 Binder.restoreCallingIdentity(identity);
8931 }
8932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008933}